Rodrigo Vega created LUCENE-4461:
------------------------------------

             Summary: Multiple FacetRequest with the same path creates 
inconsistent results
                 Key: LUCENE-4461
                 URL: https://issues.apache.org/jira/browse/LUCENE-4461
             Project: Lucene - Core
          Issue Type: Bug
          Components: modules/facet
    Affects Versions: 3.6
            Reporter: Rodrigo Vega


Multiple FacetRequest are getting merged into one creating wrong results in 
this case:

FacetSearchParams facetSearchParams = new FacetSearchParams();
                facetSearchParams.addFacetRequest(new CountFacetRequest(new 
CategoryPath("author"), 10));
                facetSearchParams.addFacetRequest(new CountFacetRequest(new 
CategoryPath("author"), 10));

Problem can be fixed defining hashcode and equals in certain way that Lucene 
recognize we are talking about different requests.


A Very simple test case:
========================

public class LuceneFacetTest {

        @Test
        public void testDuplicateFacetRequest() throws Exception {
                IndexWriter writer = new IndexWriter(new RAMDirectory(), new 
IndexWriterConfig(Version.LUCENE_36, new StandardAnalyzer(Version.LUCENE_36)));
                Directory taxoDir = new RAMDirectory();
                TaxonomyWriter taxoWriter = new 
DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);

                Document doc = new Document();
                doc.add(new Field("title", "simple text title", Store.YES, 
org.apache.lucene.document.Field.Index.ANALYZED));
                List<CategoryPath> categories = new ArrayList<CategoryPath>();
                categories.add(new CategoryPath("author", "Mark Twain"));
                categories.add(new CategoryPath("year", "2010"));
                CategoryDocumentBuilder categoryDocBuilder = new 
CategoryDocumentBuilder(taxoWriter);
                categoryDocBuilder.setCategoryPaths(categories);
                categoryDocBuilder.build(doc);
                writer.addDocument(doc);
                writer.commit();
                taxoWriter.commit();

                IndexReader indexReader = IndexReader.open(writer, true);
                IndexSearcher searcher = new IndexSearcher(indexReader);
                TaxonomyReader taxoReader = new 
DirectoryTaxonomyReader(taxoDir);
                Query q = new TermQuery(new Term("title", "text"));

                TopScoreDocCollector tdc = TopScoreDocCollector.create(10, 
true);

                FacetSearchParams facetSearchParams = new FacetSearchParams();
                facetSearchParams.addFacetRequest(new CountFacetRequest(new 
CategoryPath("author"), 10));
                facetSearchParams.addFacetRequest(new CountFacetRequest(new 
CategoryPath("author"), 10));

                FacetsCollector facetsCollector = new 
FacetsCollector(facetSearchParams, indexReader, taxoReader);
                searcher.search(q, MultiCollector.wrap(tdc, facetsCollector));
                List<FacetResult> res = facetsCollector.getFacetResults();

                Assert.assertEquals("Only Mark Twain should be returned as 
result", 1, res.get(0).getNumValidDescendants());
                Assert.assertEquals("Only Mark Twain should be returned as 
result", 1, res.get(1).getNumValidDescendants());
        }
}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to