gsmiller commented on a change in pull request #718: URL: https://github.com/apache/lucene/pull/718#discussion_r838621313
########## File path: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetFloatAssociations.java ########## @@ -0,0 +1,187 @@ +/* + * 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.facet.taxonomy; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import org.apache.lucene.facet.FacetField; +import org.apache.lucene.facet.FacetsCollector; +import org.apache.lucene.facet.FacetsCollector.MatchingDocs; +import org.apache.lucene.facet.FacetsConfig; +import org.apache.lucene.index.BinaryDocValues; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.ConjunctionUtils; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.DoubleValues; +import org.apache.lucene.search.DoubleValuesSource; +import org.apache.lucene.util.BitUtil; +import org.apache.lucene.util.BytesRef; + +/** + * Aggregates float values associated with facet fields. Supports two different approaches: + * + * <ol> + * <li>Fields can be indexed with {@link FloatAssociationFacetField}, associating weights with + * facet values at indexing time. + * <li>Fields can be indexed with {@link FacetField} and a {@link DoubleValuesSource} can + * dynamically supply a weight from each doc. With this approach, the document's weight gets + * contributed to each facet value associated with the doc. + * </ol> + * + * Aggregation logic is supplied by the provided {@link FloatAssociationFacetField}. + * + * @lucene.experimental + */ +public class TaxonomyFacetFloatAssociations extends FloatTaxonomyFacets { + + /** Create {@code TaxonomyFacetFloatAssociations} against the default index field. */ + public TaxonomyFacetFloatAssociations( + TaxonomyReader taxoReader, + FacetsConfig config, + FacetsCollector fc, + AssociationAggregationFunction aggregationFunction) + throws IOException { + this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc, aggregationFunction); + } + + /** + * Create {@code TaxonomyFacetFloatAssociations} against the default index field. Sources values + * from the provided {@code valuesSource}. + */ + public TaxonomyFacetFloatAssociations( + TaxonomyReader taxoReader, + FacetsConfig config, + FacetsCollector fc, + AssociationAggregationFunction aggregationFunction, + DoubleValuesSource valuesSource) + throws IOException { + this( + FacetsConfig.DEFAULT_INDEX_FIELD_NAME, + taxoReader, + config, + fc, + aggregationFunction, + valuesSource); + } + + /** Create {@code TaxonomyFacetFloatAssociations} against the specified index field. */ + public TaxonomyFacetFloatAssociations( + String indexFieldName, + TaxonomyReader taxoReader, + FacetsConfig config, + FacetsCollector fc, + AssociationAggregationFunction aggregationFunction) + throws IOException { + super(indexFieldName, taxoReader, aggregationFunction, config); + aggregateValues(aggregationFunction, fc.getMatchingDocs()); + } + + /** + * Create {@code TaxonomyFacetFloatAssociations} against the specified index field. Sources values + * from the provided {@code valuesSource}. + */ + public TaxonomyFacetFloatAssociations( + String indexFieldName, + TaxonomyReader taxoReader, + FacetsConfig config, + FacetsCollector fc, + AssociationAggregationFunction aggregationFunction, + DoubleValuesSource valuesSource) + throws IOException { + super(indexFieldName, taxoReader, aggregationFunction, config); + aggregateValues(aggregationFunction, fc.getMatchingDocs(), fc.getKeepScores(), valuesSource); + } + + private static DoubleValues scores(MatchingDocs hits) { + return new DoubleValues() { + + int index = -1; + + @Override + public double doubleValue() throws IOException { + return hits.scores[index]; + } + + @Override + public boolean advanceExact(int doc) throws IOException { + index++; Review comment: Oh wow. Great catch! I lifted this from the current implementation but this is an uncaught bug. I just reproduced it with a test. I'm going to open a separate issue and fix this bug first, then merge the fix into this PR. Thanks Mike! -- 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