Java Code Examples for org.apache.lucene.facet.FacetsConfig#setRequireDimCount()

The following examples show how to use org.apache.lucene.facet.FacetsConfig#setRequireDimCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTaxonomyFacetAssociations.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testRequireDimCount() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  FacetsConfig config = new FacetsConfig();
  config.setRequireDimCount("a", true);
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);

  Document doc = new Document();
  doc.add(new IntAssociationFacetField(14, "a", "x"));
  expectThrows(IllegalArgumentException.class, () -> {
    writer.addDocument(config.build(taxoWriter, doc));
  });

  writer.close();
  IOUtils.close(taxoWriter, dir, taxoDir);
}
 
Example 2
Source File: TestTaxonomyFacetCounts2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static FacetsConfig getConfig() {
  FacetsConfig config = new FacetsConfig();
  config.setMultiValued("A", true);
  config.setMultiValued("B", true);
  config.setRequireDimCount("B", true);
  config.setHierarchical("D", true);
  return config;
}
 
Example 3
Source File: TestTaxonomyFacetCounts.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testRequireDimCount() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);

  FacetsConfig config = new FacetsConfig();
  config.setRequireDimCount("dim", true);

  config.setMultiValued("dim2", true);
  config.setRequireDimCount("dim2", true);

  config.setMultiValued("dim3", true);
  config.setHierarchical("dim3", true);
  config.setRequireDimCount("dim3", true);

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  doc.add(new FacetField("dim", "a"));
  doc.add(new FacetField("dim2", "a"));
  doc.add(new FacetField("dim2", "b"));
  doc.add(new FacetField("dim3", "a", "b"));
  doc.add(new FacetField("dim3", "a", "c"));
  writer.addDocument(config.build(taxoWriter, doc));

  // 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(1, facets.getTopChildren(10, "dim").value);
  assertEquals(1, facets.getTopChildren(10, "dim2").value);
  assertEquals(1, facets.getTopChildren(10, "dim3").value);
  expectThrows(IllegalArgumentException.class, () -> {
    facets.getSpecificValue("dim");
  });
  assertEquals(1, facets.getSpecificValue("dim2"));
  assertEquals(1, facets.getSpecificValue("dim3"));
  writer.close();
  IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir);
}