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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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