Skip to content

Commit

Permalink
Test cases for LongValueFacetCounts and FastTaxonomyFacetCounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam Worah committed May 10, 2021
1 parent 6ebf959 commit 0428781
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map.Entry<Long, Integer>> expectedCounts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0428781

Please sign in to comment.