本文整理汇总了Java中org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader类的典型用法代码示例。如果您正苦于以下问题:Java DirectoryTaxonomyReader类的具体用法?Java DirectoryTaxonomyReader怎么用?Java DirectoryTaxonomyReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryTaxonomyReader类属于org.apache.lucene.facet.taxonomy.directory包,在下文中一共展示了DirectoryTaxonomyReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: facetsWithSearch
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User runs a query and counts facets. */
private List<FacetResult> facetsWithSearch() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
FacetsCollector fc = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query:
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
// Retrieve results
List<FacetResult> results = new ArrayList<FacetResult>();
// Count both "Publish Date" and "Author" dimensions
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
results.add(facets.getTopChildren(10, "Author"));
results.add(facets.getTopChildren(10, "Publish Date"));
indexReader.close();
taxoReader.close();
return results;
}
示例2: drillDown
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User drills down on 'Publish Date/2010', and we
* return facets for 'Author' */
private FacetResult drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Passing no baseQuery means we drill down on all
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(config);
// Now user drills down on Publish Date/2010:
q.add("Publish Date", "2010");
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, q, 10, fc);
// Retrieve results
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
FacetResult result = facets.getTopChildren(10, "Author");
indexReader.close();
taxoReader.close();
return result;
}
示例3: drillSideways
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User drills down on 'Publish Date/2010', and we
* return facets for both 'Publish Date' and 'Author',
* using DrillSideways. */
private List<FacetResult> drillSideways() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Passing no baseQuery means we drill down on all
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(config);
// Now user drills down on Publish Date/2010:
q.add("Publish Date", "2010");
DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
DrillSidewaysResult result = ds.search(q, 10);
// Retrieve results
List<FacetResult> facets = result.facets.getAllDims(10);
indexReader.close();
taxoReader.close();
return facets;
}
示例4: sumAssociations
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User runs a query and aggregates facets by summing their association values. */
private List<FacetResult> sumAssociations() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
FacetsCollector fc = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query:
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc);
Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
// Retrieve results
List<FacetResult> results = new ArrayList<FacetResult>();
results.add(tags.getTopChildren(10, "tags"));
results.add(genre.getTopChildren(10, "genre"));
indexReader.close();
taxoReader.close();
return results;
}
示例5: drillDown
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User drills down on 'tags/solr'. */
private FacetResult drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Passing no baseQuery means we drill down on all
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(config);
// Now user drills down on Publish Date/2010:
q.add("tags", "solr");
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, q, 10, fc);
// Retrieve results
Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
FacetResult result = facets.getTopChildren(10, "genre");
indexReader.close();
taxoReader.close();
return result;
}
示例6: facetsWithSearch
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User runs a query and counts facets. */
private List<FacetResult> facetsWithSearch() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
FacetsCollector fc = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query:
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
// Retrieve results
List<FacetResult> results = new ArrayList<>();
// Count both "Publish Date" and "Author" dimensions
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
results.add(facets.getTopChildren(10, "Author"));
results.add(facets.getTopChildren(10, "Publish Date"));
indexReader.close();
taxoReader.close();
return results;
}
示例7: sumAssociations
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** User runs a query and aggregates facets by summing their association values. */
private List<FacetResult> sumAssociations() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
FacetsCollector fc = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query:
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc);
Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
// Retrieve results
List<FacetResult> results = new ArrayList<>();
results.add(tags.getTopChildren(10, "tags"));
results.add(genre.getTopChildren(10, "genre"));
indexReader.close();
taxoReader.close();
return results;
}
示例8: main
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** Command-line tool. */
public static void main(String[] args) throws IOException {
boolean printTree = false;
String path = null;
for(int i=0;i<args.length;i++) {
if (args[i].equals("-printTree")) {
printTree = true;
} else {
path = args[i];
}
}
if (args.length != (printTree ? 2 : 1)) {
System.out.println("\nUsage: java -classpath ... org.apache.lucene.facet.util.PrintTaxonomyStats [-printTree] /path/to/taxononmy/index\n");
System.exit(1);
}
Directory dir = FSDirectory.open(new File(path));
TaxonomyReader r = new DirectoryTaxonomyReader(dir);
printStats(r, System.out, printTree);
r.close();
dir.close();
}
示例9: refreshIfNeeded
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
@Override
protected SearcherAndTaxonomy refreshIfNeeded(SearcherAndTaxonomy ref) throws IOException {
// Must re-open searcher first, otherwise we may get a
// new reader that references ords not yet known to the
// taxonomy reader:
final IndexReader r = ref.searcher.getIndexReader();
final IndexReader newReader = DirectoryReader.openIfChanged((DirectoryReader) r);
if (newReader == null) {
return null;
} else {
DirectoryTaxonomyReader tr = TaxonomyReader.openIfChanged(ref.taxonomyReader);
if (tr == null) {
ref.taxonomyReader.incRef();
tr = ref.taxonomyReader;
} else if (taxoWriter != null && taxoWriter.getTaxonomyEpoch() != taxoEpoch) {
IOUtils.close(newReader, tr);
throw new IllegalStateException("DirectoryTaxonomyWriter.replaceTaxonomy was called, which is not allowed when using SearcherTaxonomyManager");
}
return new SearcherAndTaxonomy(SearcherManager.getSearcher(searcherFactory, newReader), tr);
}
}
示例10: testEmptyIndex
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
public void testEmptyIndex() throws Exception {
// LUCENE-5045: make sure DrillSideways works with an empty index
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
IndexSearcher searcher = newSearcher(writer.getReader());
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
// Count "Author"
FacetsConfig config = new FacetsConfig();
DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
DrillDownQuery ddq = new DrillDownQuery(config);
ddq.add("Author", "Lisa");
DrillSidewaysResult r = ds.search(ddq, 10); // this used to fail on IllegalArgEx
assertEquals(0, r.hits.totalHits);
r = ds.search(ddq, null, null, 10, new Sort(new SortField("foo", SortField.Type.INT)), false, false); // this used to fail on IllegalArgEx
assertEquals(0, r.hits.totalHits);
IOUtils.close(writer, taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir);
}
示例11: testChildCount
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
public void testChildCount() throws Exception {
// LUCENE-4885: FacetResult.numValidDescendants was not set properly by FacetsAccumulator
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
FacetsConfig config = new FacetsConfig();
for (int i = 0; i < 10; i++) {
Document doc = new Document();
doc.add(new FacetField("a", Integer.toString(i)));
iw.addDocument(config.build(taxoWriter, doc));
}
DirectoryReader r = DirectoryReader.open(iw, true);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
FacetsCollector sfc = new FacetsCollector();
newSearcher(r).search(new MatchAllDocsQuery(), sfc);
Facets facets = getTaxonomyFacetCounts(taxoReader, config, sfc);
assertEquals(10, facets.getTopChildren(2, "a").childCount);
IOUtils.close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir);
}
示例12: testRootOnly
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
/** Test writing an empty index, and seeing that a reader finds in it
the root category, and only it. We check all the methods on that
root category return the expected results.
*/
@Test
public void testRootOnly() throws Exception {
Directory indexDir = newDirectory();
TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
// right after opening the index, it should already contain the
// root, so have size 1:
assertEquals(1, tw.getSize());
tw.close();
TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
assertEquals(1, tr.getSize());
assertEquals(0, tr.getPath(0).length);
assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParallelTaxonomyArrays().parents()[0]);
assertEquals(0, tr.getOrdinal(new FacetLabel()));
tr.close();
indexDir.close();
}
示例13: testNRT
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
@Test
public void testNRT() throws Exception {
Directory dir = newDirectory();
DirectoryTaxonomyWriter writer = new DirectoryTaxonomyWriter(dir);
TaxonomyReader reader = new DirectoryTaxonomyReader(writer);
FacetLabel cp = new FacetLabel("a");
writer.addCategory(cp);
TaxonomyReader newReader = TaxonomyReader.openIfChanged(reader);
assertNotNull("expected a new instance", newReader);
assertEquals(2, newReader.getSize());
assertNotSame(TaxonomyReader.INVALID_ORDINAL, newReader.getOrdinal(cp));
reader.close();
reader = newReader;
writer.close();
reader.close();
dir.close();
}
示例14: testNoScore
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
public void testNoScore() 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();
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)));
iw.addDocument(config.build(taxoWriter, doc));
}
DirectoryReader r = DirectoryReader.open(iw, true);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
FacetsCollector sfc = new FacetsCollector();
newSearcher(r).search(new MatchAllDocsQuery(), sfc);
Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, sfc, new LongFieldSource("price"));
assertEquals("dim=a path=[] value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n", facets.getTopChildren(10, "a").toString());
IOUtils.close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir);
}
示例15: testFaceting
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入依赖的package包/类
@Test
public void testFaceting() throws Exception {
DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxonomyDirectory);
FacetsConfig cfg = new FacetsConfig();
Document doc1 = new Document();
Document doc2 = new Document();
Document doc3 = new Document();
doc1.add(new FacetField("category", "c2"));
doc2.add(new FacetField("category", "c2"));
doc3.add(new FacetField("category", "c1"));
index(cfg.build(tw, doc1), cfg.build(tw, doc2), cfg.build(tw, doc3));
tw.close();
DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxonomyDirectory);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(openSearcher(), new MatchAllDocsQuery(), 10, fc);
Facets facets = new FastTaxonomyFacetCounts(tr, cfg, fc);
FacetResult category = facets.getTopChildren(10, "category");
assertEquals(2, category.childCount);
}