sonatype-lift[bot] commented on a change in pull request #418: URL: https://github.com/apache/lucene/pull/418#discussion_r760988572
########## File path: lucene/core/src/java/org/apache/lucene/search/ImpactsMergingUtils.java ########## @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.lucene.index.Impact; +import org.apache.lucene.index.Impacts; +import org.apache.lucene.index.ImpactsEnum; +import org.apache.lucene.util.PriorityQueue; +import org.apache.lucene.util.SmallFloat; + +/** + * Utils for merging impacts for SynonymQuery, CombinedFieldsQuery etc + * + * @lucene.internal + */ +public final class ImpactsMergingUtils { + /** Cache of decoded norms. */ + private static final float[] LENGTH_TABLE = new float[256]; + + static { + for (int i = 0; i < 256; i++) { + LENGTH_TABLE[i] = SmallFloat.byte4ToInt((byte) i); + } + } + + /** + * Return the minimum level whose impacts are valid up to {@code docIdUpTo}, or {@code -1} if + * there is no such level. + */ + private static int getLevel(Impacts impacts, int docIdUpTo) { + for (int level = 0, numLevels = impacts.numLevels(); level < numLevels; ++level) { + if (impacts.getDocIdUpTo(level) >= docIdUpTo) { + return level; + } + } + return -1; + } + + private static class SubIterator { + final Iterator<Impact> iterator; + int previousFreq; + Impact current; + + SubIterator(Iterator<Impact> iterator) { + this.iterator = iterator; + this.current = iterator.next(); + } + + void next() { + previousFreq = current.freq; + if (iterator.hasNext() == false) { + current = null; + } else { + current = iterator.next(); + } + } + } + + private static double normToLength(long norm) { + return LENGTH_TABLE[Byte.toUnsignedInt((byte) norm)]; + } + + /** + * Merge impacts from multiple impactsEnum (terms matches) within the same field. The high level + * logic is to combine freqs that have the same norm from impacts. + */ + public static List<Impact> mergeImpactsPerField( Review comment: *MixedMutabilityReturnType:* This method returns both mutable and immutable collections or maps from different paths. This may be confusing for users of the method. [(details)](https://errorprone.info/bugpattern/MixedMutabilityReturnType) (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org