Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxonomy counts are incorrect due to ordinal sorting (#14008) #14010

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Other
Bug Fixes
---------------------

* GITHUB#14008: Counts provided by taxonomy facets in addition to another aggregation are now returned together with
their corresponding ordinals. (Paul King)

======================= Lucene 10.0.0 =======================

Expand Down Expand Up @@ -422,6 +424,14 @@ Build

* GITHUB#13698: Upgrade to gradle 8.10 (Dawid Weiss)

======================== Lucene 9.12.1 =======================

Bug Fixes
---------------------

* GITHUB#14008: Counts provided by taxonomy facets in addition to another aggregation are now returned together with
their corresponding ordinals. (Paul King)

======================== Lucene 9.12.0 =======================

Security Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,15 @@ private FacetResult createFacetResult(

LabelAndValue[] labelValues = new LabelAndValue[q.size()];
int[] ordinals = new int[labelValues.length];
int[] counts = new int[labelValues.length];
Number[] values = new Number[labelValues.length];

for (int i = labelValues.length - 1; i >= 0; i--) {
TopOrdAndNumberQueue.OrdAndValue ordAndValue = q.pop();
assert ordAndValue != null;
ordinals[i] = ordAndValue.ord;
values[i] = ordAndValue.getValue();
counts[i] = getCount(ordinals[i]);
}

FacetLabel[] bulkPath = taxoReader.getBulkPath(ordinals);
Expand All @@ -329,8 +331,7 @@ private FacetResult createFacetResult(
int childComponentIdx = path.length + 1;
for (int i = 0; i < labelValues.length; i++) {
labelValues[i] =
new LabelAndValue(
bulkPath[i].components[childComponentIdx], values[i], getCount(ordinals[i]));
new LabelAndValue(bulkPath[i].components[childComponentIdx], values[i], counts[i]);
}

return new FacetResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,49 @@ public void testNonPositiveAggregations() throws IOException {
IOUtils.close(taxoReader, reader, taxoDir, dir);
}

public void testAggregationCounts() throws IOException {
Directory taxoDir = newDirectory();

TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

FacetsConfig config = new FacetsConfig();
config.setIndexFieldName("a", "$int_facets");

RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document d;

d = new Document();
d.add(new IntAssociationFacetField(1, "a", "1"));
writer.addDocument(config.build(taxoWriter, d));

d = new Document();
d.add(new IntAssociationFacetField(5, "a", "2"));
writer.addDocument(config.build(taxoWriter, d));

d = new Document();
d.add(new IntAssociationFacetField(1, "a", "1"));
writer.addDocument(config.build(taxoWriter, d));

IndexReader reader = writer.getReader();
IOUtils.close(taxoWriter, writer);

IndexSearcher searcher = newSearcher(reader);
Query q = new MatchAllDocsQuery();
FacetsCollector fc = searcher.search(q, new FacetsCollectorManager());

TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
IntTaxonomyFacets intFacets =
new TaxonomyFacetIntAssociations(
"$int_facets", taxoReader, config, fc, AssociationAggregationFunction.SUM);

FacetResult result = intFacets.getTopChildren(10, "a");
assertEquals("dim=a path=[] value=7 childCount=2\n 2 (5)\n 1 (2)\n", result.toString());
assertEquals(1, result.labelValues[0].count);
assertEquals(2, result.labelValues[1].count);

IOUtils.close(taxoReader, reader, taxoDir);
}

private void validateInts(
String dim,
Map<String, Integer> expected,
Expand Down