LUCENE-4913: ordinal was 0 when all children are returned

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1465372 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-04-07 12:18:22 +00:00
parent a22e571189
commit 9b52638a84
5 changed files with 56 additions and 5 deletions

View File

@ -229,6 +229,9 @@ Bug Fixes
flag. It affects SpatialRecursivePrefixTreeStrategy on non-point indexed
shapes, as of Lucene 4.2. (David Smiley)
* LUCENE-4913: FacetResultNode.ordinal was always 0 when all children
are returned. (Mike McCandless)
Documentation
* LUCENE-4841: Added example SimpleSortedSetFacetsExample to show how

View File

@ -66,9 +66,8 @@ public final class FloatFacetResultsHandler extends DepthOneFacetResultsHandler
while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
float value = values[ordinal];
if (value > 0) {
FacetResultNode node = new FacetResultNode();
FacetResultNode node = new FacetResultNode(ordinal, value);
node.label = taxonomyReader.getPath(ordinal);
node.value = value;
nodes.add(node);
}
ordinal = siblings[ordinal];

View File

@ -65,9 +65,8 @@ public final class IntFacetResultsHandler extends DepthOneFacetResultsHandler {
while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
int value = values[ordinal];
if (value > 0) {
FacetResultNode node = new FacetResultNode();
FacetResultNode node = new FacetResultNode(ordinal, value);
node.label = taxonomyReader.getPath(ordinal);
node.value = value;
nodes.add(node);
}
ordinal = siblings[ordinal];

View File

@ -203,7 +203,7 @@ public class TestDemoFacets extends FacetTestCase {
FacetSearchParams fsp = new FacetSearchParams(fip,
new CountFacetRequest(new CategoryPath("a", '/'), 10));
// Aggregatses the facet counts:
// Aggregate the facet counts:
FacetsCollector c = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
// MatchAllDocsQuery is for "browsing" (counts facets
@ -215,6 +215,11 @@ public class TestDemoFacets extends FacetTestCase {
assertEquals(1, results.size());
assertEquals(1, (int) results.get(0).getFacetResultNode().value);
// LUCENE-4913:
for(FacetResultNode childNode : results.get(0).getFacetResultNode().subResults) {
assertTrue(childNode.ordinal != 0);
}
searcher.getIndexReader().close();
taxoReader.close();
dir.close();

View File

@ -304,4 +304,49 @@ public class TestFacetsCollector extends FacetTestCase {
IOUtils.close(taxo, taxoDir, r, indexDir);
}
@Test
public void testParentOrdinal() throws Exception {
// LUCENE-4913: root ordinal was always 0 when all children were requested
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
Document doc = new Document();
facetFields.addFields(doc, Arrays.asList(new CategoryPath("a/1", '/')));
iw.addDocument(doc);
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// assert IntFacetResultHandler
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("a"), 10));
FacetsAccumulator fa = random().nextBoolean() ? new FacetsAccumulator(fsp, r, taxo) : new StandardFacetsAccumulator(fsp, r, taxo);
FacetsCollector fc = FacetsCollector.create(fa);
new IndexSearcher(r).search(new MatchAllDocsQuery(), fc);
assertTrue("invalid ordinal for child node: 0", 0 != fc.getFacetResults().get(0).getFacetResultNode().subResults.get(0).ordinal);
// assert IntFacetResultHandler
fsp = new FacetSearchParams(new SumScoreFacetRequest(new CategoryPath("a"), 10));
if (random().nextBoolean()) {
fa = new FacetsAccumulator(fsp, r, taxo) {
@Override
public FacetsAggregator getAggregator() {
return new SumScoreFacetsAggregator();
}
};
} else {
fa = new StandardFacetsAccumulator(fsp, r, taxo);
}
fc = FacetsCollector.create(fa);
new IndexSearcher(r).search(new MatchAllDocsQuery(), fc);
assertTrue("invalid ordinal for child node: 0", 0 != fc.getFacetResults().get(0).getFacetResultNode().subResults.get(0).ordinal);
IOUtils.close(taxo, taxoDir, r, indexDir);
}
}