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

The following examples show how to use org.apache.lucene.facet.FacetsConfig#setHierarchical() . 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: IndexAndTaxonomyReplicationClientTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  publishIndexDir = newDirectory();
  publishTaxoDir = newDirectory();
  handlerIndexDir = newMockDirectory();
  handlerTaxoDir = newMockDirectory();
  clientWorkDir = createTempDir("replicationClientTest");
  sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir);
  replicator = new LocalReplicator();
  callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
  handler = new IndexAndTaxonomyReplicationHandler(handlerIndexDir, handlerTaxoDir, callback);
  client = new ReplicationClient(replicator, handler, sourceDirFactory);
  
  IndexWriterConfig conf = newIndexWriterConfig(null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  publishIndexWriter = new IndexWriter(publishIndexDir, conf);
  publishTaxoWriter = new SnapshotDirectoryTaxonomyWriter(publishTaxoDir);
  config = new FacetsConfig();
  config.setHierarchical("A", true);
}
 
Example 2
Source File: TestTaxonomyFacetAssociations.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testNoHierarchy() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  FacetsConfig config = new FacetsConfig();
  config.setHierarchical("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 3
Source File: RandomFacetSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(FacetsConfig config) {
  for(int i=0;i<maxDims;i++) {
    config.setHierarchical(Integer.toString(i), true);
    config.setMultiValued(Integer.toString(i), true);
  }
}
 
Example 4
Source File: IndexAndTaxonomyReplicationClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public IndexAndTaxonomyReadyCallback(Directory indexDir, Directory taxoDir) throws IOException {
  this.indexDir = indexDir;
  this.taxoDir = taxoDir;
  config = new FacetsConfig();
  config.setHierarchical("A", true);
  if (DirectoryReader.indexExists(indexDir)) {
    indexReader = DirectoryReader.open(indexDir);
    lastIndexGeneration = indexReader.getIndexCommit().getGeneration();
    taxoReader = new DirectoryTaxonomyReader(taxoDir);
  }
}
 
Example 5
Source File: TestTaxonomyFacetCounts.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testMultiValuedHierarchy() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  FacetsConfig config = new FacetsConfig();
  config.setHierarchical("a", true);
  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", "x"));
  doc.add(new FacetField("a", "path", "y"));
  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);

  expectThrows(IllegalArgumentException.class, () -> {
    facets.getSpecificValue("a");
  });

  FacetResult result = facets.getTopChildren(10, "a");
  assertEquals(1, result.labelValues.length);
  assertEquals(1, result.labelValues[0].value.intValue());

  writer.close();
  IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir);
}
 
Example 6
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 7
Source File: TestTaxonomyFacetSumValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testRollupValues() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();

  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
  FacetsConfig config = new FacetsConfig();
  config.setHierarchical("a", true);
  //config.setRequireDimCount("a", true);
  
  for (int i = 0; i < 4; i++) {
    Document doc = new Document();
    doc.add(new NumericDocValuesField("price", (i+1)));
    doc.add(new FacetField("a", Integer.toString(i % 2), "1"));
    iw.addDocument(config.build(taxoWriter, doc));
  }
  
  DirectoryReader r = DirectoryReader.open(iw);
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);

  FacetsCollector sfc = new FacetsCollector();
  newSearcher(r).search(new MatchAllDocsQuery(), sfc);
  Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, sfc, DoubleValuesSource.fromLongField("price"));
  
  assertEquals("dim=a path=[] value=10.0 childCount=2\n  1 (6.0)\n  0 (4.0)\n", facets.getTopChildren(10, "a").toString());

  iw.close();
  IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
 
Example 8
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);
}