From 042878117308f76629a27b0bcf83e25f074dc8b1 Mon Sep 17 00:00:00 2001 From: Gautam Worah Date: Sun, 9 May 2021 23:51:41 -0700 Subject: [PATCH] Test cases for LongValueFacetCounts and FastTaxonomyFacetCounts --- .../facet/TestLongValueFacetCounts.java | 23 ++++++++++++ .../taxonomy/TestTaxonomyFacetCounts.java | 36 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java index 5821052d12ea..6319d7036b24 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java @@ -573,6 +573,29 @@ public void testRandomMultiValued() throws Exception { dir.close(); } + public void testLongValues() throws Exception { + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + Document doc = new Document(); + doc.add(new SortedNumericDocValuesField("field", 3)); + doc.add(new SortedNumericDocValuesField("field", 3)); + w.addDocument(doc); + IndexReader r = w.getReader(); + w.close(); + FacetsCollector fc = new FacetsCollector(); + LongValueFacetCounts facetCounts = new LongValueFacetCounts("field", r); + + FacetResult fr = facetCounts.getAllChildrenSortByValue(); + for (LabelAndValue a : fr.labelValues) { + System.out.println("label is " + a.label); + System.out.println("value is " + a.value); + } + System.out.println("length of children is " + fr.childCount); + System.out.println("dim is " + fr.dim + "labelvalues " + fr.labelValues.toString() + " value is " + fr.value); + r.close(); + dir.close(); + } + private static void assertSame( String desc, List> expectedCounts, diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java index e5ac9cb94aab..9b3d051ae4f7 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java @@ -332,6 +332,42 @@ public void testMultiValuedHierarchy() throws Exception { IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir); } + public void testFastTaxonomyFacetCountsWithMultiValues() throws Exception { + Directory dir = newDirectory(); + Directory taxoDir = newDirectory(); + DirectoryTaxonomyWriter taxoWriter = + new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE); + FacetsConfig config = new FacetsConfig(); + config.setMultiValued("a", true); + RandomIndexWriter writer = new RandomIndexWriter(random(), dir); + + Document doc = new Document(); + doc.add(newTextField("field", "text", Field.Store.NO)); + doc.add(new FacetField("a", "path")); + doc.add(new FacetField("a", "path")); + doc.add(new FacetField("a", "path")); + + writer.addDocument(config.build(taxoWriter, doc)); + + Document doc2 = new Document(); + doc2.add(new FacetField("a", "path")); + writer.addDocument(config.build(taxoWriter, doc2)); + + // NRT open + IndexSearcher searcher = newSearcher(writer.getReader()); + + // NRT open + TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter); + + Facets facets = + getAllFacets(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, searcher, taxoReader, config); + + assertEquals(4, facets.getSpecificValue("a", "path")); + + writer.close(); + IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir); + } + public void testLabelWithDelimiter() throws Exception { Directory dir = newDirectory(); Directory taxoDir = newDirectory();