You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/03/29 14:03:40 UTC

[GitHub] [lucene] mikemccand commented on a change in pull request #718: LUCENE-10444: Support alternate aggregation functions in association facets

mikemccand commented on a change in pull request #718:
URL: https://github.com/apache/lucene/pull/718#discussion_r837510411



##########
File path: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
##########
@@ -49,22 +57,24 @@ void rollup() throws IOException {
       if (ft.hierarchical && ft.multiValued == false) {
         int dimRootOrd = taxoReader.getOrdinal(new FacetLabel(dim));
         assert dimRootOrd > 0;
-        values[dimRootOrd] += rollup(children[dimRootOrd]);
+        float newValue =
+            aggregationFunction.aggregate(values[dimRootOrd], rollup(children[dimRootOrd]));

Review comment:
       Are we assuming here that using `0` always as an initial value is OK for any aggregation function?  What if we wanted `MIN` aggregator?

##########
File path: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
##########
@@ -173,17 +185,17 @@ public FacetResult getTopChildren(int topN, String dim, String... path) throws I
 
     if (sparseValues != null) {
       for (IntIntCursor c : sparseValues) {
-        int count = c.value;
+        int value = c.value;
         int ord = c.key;
-        if (parents[ord] == dimOrd && count > 0) {
-          totValue += count;
+        if (parents[ord] == dimOrd && value > 0) {
+          aggregatedValue = aggregationFunction.aggregate(aggregatedValue, value);
           childCount++;
-          if (count > bottomValue) {
+          if (value > bottomValue) {

Review comment:
       Ahh, OK, so then disregard my comment above -- we should not try to tackle `min` here!

##########
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:
       Hmm, instead of `index++` shouldn't we do `index = doc`?

##########
File path: lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
##########
@@ -76,6 +93,49 @@ public static void beforeClass() throws Exception {
       writer.addDocument(config.build(taxoWriter, doc));
     }
 
+    // Also index random content for more random testing:

Review comment:
       Yay, thanks!




-- 
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-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org