本文整理汇总了Java中org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryTaxonomyReader.close方法的具体用法?Java DirectoryTaxonomyReader.close怎么用?Java DirectoryTaxonomyReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader
的用法示例。
在下文中一共展示了DirectoryTaxonomyReader.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyResults
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
private void verifyResults(Directory dir, Directory taxDir, FacetIndexingParams fip) throws IOException {
DirectoryReader reader1 = DirectoryReader.open(dir);
DirectoryTaxonomyReader taxReader = new DirectoryTaxonomyReader(taxDir);
IndexSearcher searcher = newSearcher(reader1);
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS));
FacetsCollector collector = FacetsCollector.create(fsp, reader1, taxReader);
searcher.search(new MatchAllDocsQuery(), collector);
FacetResult result = collector.getFacetResults().get(0);
FacetResultNode node = result.getFacetResultNode();
for (FacetResultNode facet: node.subResults) {
int weight = (int)facet.value;
int label = Integer.parseInt(facet.label.components[1]);
//System.out.println(label + ": " + weight);
if (VERBOSE) {
System.out.println(label + ": " + weight);
}
assertEquals(NUM_DOCS ,weight);
}
reader1.close();
taxReader.close();
}
示例2: testIntSumAssociation
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testIntSumAssociation() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new SumIntAssociationFacetRequest(aint, 10),
new SumIntAssociationFacetRequest(bint, 10));
Query q = new MatchAllDocsQuery();
FacetsCollector fc = FacetsCollector.create(fsp, reader, taxo);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertNotNull("No results!",res);
assertEquals("Wrong number of results!",2, res.size());
assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
taxo.close();
}
示例3: testFloatSumAssociation
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testFloatSumAssociation() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new SumFloatAssociationFacetRequest(afloat, 10),
new SumFloatAssociationFacetRequest(bfloat, 10));
Query q = new MatchAllDocsQuery();
FacetsCollector fc = FacetsCollector.create(fsp, reader, taxo);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertNotNull("No results!",res);
assertEquals("Wrong number of results!", 2, res.size());
assertEquals("Wrong count for category 'a'!",50f, (float) res.get(0).getFacetResultNode().value, 0.00001);
assertEquals("Wrong count for category 'b'!",10f, (float) res.get(1).getFacetResultNode().value, 0.00001);
taxo.close();
}
示例4: commit
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
public void commit(Search s, SpimeDB db) {
try {
DirectoryTaxonomyReader taxoReader = db.readTaxonomy();
Facets facets = new FastTaxonomyFacetCounts(taxoReader, db.facetConfig(), this);
s.setFacets(facets.getTopChildren(limit, NObject.TAG));
taxoReader.close();
} catch (IOException e) {
throw new RuntimeException(e);
} //finally {
}
示例5: call
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Override
public Boolean call() throws Exception {
if (indexReader == null) {
indexReader = DirectoryReader.open(indexDir);
lastIndexGeneration = indexReader.getIndexCommit().getGeneration();
taxoReader = new DirectoryTaxonomyReader(taxoDir);
} else {
// verify search index
DirectoryReader newReader = DirectoryReader.openIfChanged(indexReader);
assertNotNull("should not have reached here if no changes were made to the index", newReader);
long newGeneration = newReader.getIndexCommit().getGeneration();
assertTrue("expected newer generation; current=" + lastIndexGeneration + " new=" + newGeneration, newGeneration > lastIndexGeneration);
indexReader.close();
indexReader = newReader;
lastIndexGeneration = newGeneration;
TestUtil.checkIndex(indexDir);
// verify taxonomy index
DirectoryTaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(taxoReader);
if (newTaxoReader != null) {
taxoReader.close();
taxoReader = newTaxoReader;
}
TestUtil.checkIndex(taxoDir);
// verify faceted search
int id = Integer.parseInt(indexReader.getIndexCommit().getUserData().get(VERSION_ID), 16);
IndexSearcher searcher = new IndexSearcher(indexReader);
FacetsCollector fc = new FacetsCollector();
searcher.search(new MatchAllDocsQuery(), fc);
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
assertEquals(1, facets.getSpecificValue("A", Integer.toString(id, 16)).intValue());
DrillDownQuery drillDown = new DrillDownQuery(config);
drillDown.add("A", Integer.toString(id, 16));
TopDocs docs = searcher.search(drillDown, 10);
assertEquals(1, docs.totalHits);
}
return null;
}
示例6: testIntSumAssociation
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testIntSumAssociation() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new AssociationIntSumFacetRequest(aint, 10),
new AssociationIntSumFacetRequest(bint, 10));
Query q = new MatchAllDocsQuery();
FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
@Override
public FacetsAggregator getAggregator() {
return new SumIntAssociationFacetsAggregator();
}
};
FacetsCollector fc = FacetsCollector.create(fa);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertNotNull("No results!",res);
assertEquals("Wrong number of results!",2, res.size());
assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
taxo.close();
}
示例7: testFloatSumAssociation
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testFloatSumAssociation() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new AssociationFloatSumFacetRequest(afloat, 10),
new AssociationFloatSumFacetRequest(bfloat, 10));
Query q = new MatchAllDocsQuery();
FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
@Override
public FacetsAggregator getAggregator() {
return new SumFloatAssociationFacetsAggregator();
}
};
FacetsCollector fc = FacetsCollector.create(fa);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertNotNull("No results!",res);
assertEquals("Wrong number of results!", 2, res.size());
assertEquals("Wrong count for category 'a'!",50f, (float) res.get(0).getFacetResultNode().value, 0.00001);
assertEquals("Wrong count for category 'b'!",10f, (float) res.get(1).getFacetResultNode().value, 0.00001);
taxo.close();
}
示例8: testDifferentAggregatorsSameCategoryList
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testDifferentAggregatorsSameCategoryList() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new AssociationIntSumFacetRequest(aint, 10),
new AssociationIntSumFacetRequest(bint, 10),
new AssociationFloatSumFacetRequest(afloat, 10),
new AssociationFloatSumFacetRequest(bfloat, 10));
Query q = new MatchAllDocsQuery();
final SumIntAssociationFacetsAggregator sumInt = new SumIntAssociationFacetsAggregator();
final SumFloatAssociationFacetsAggregator sumFloat = new SumFloatAssociationFacetsAggregator();
final Map<CategoryPath,FacetsAggregator> aggregators = new HashMap<CategoryPath,FacetsAggregator>();
aggregators.put(aint, sumInt);
aggregators.put(bint, sumInt);
aggregators.put(afloat, sumFloat);
aggregators.put(bfloat, sumFloat);
FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
@Override
public FacetsAggregator getAggregator() {
return new MultiAssociationsFacetsAggregator(aggregators);
}
};
FacetsCollector fc = FacetsCollector.create(fa);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertEquals("Wrong number of results!", 4, res.size());
assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
assertEquals("Wrong count for category 'a'!",50f, (float) res.get(2).getFacetResultNode().value, 0.00001);
assertEquals("Wrong count for category 'b'!",10f, (float) res.get(3).getFacetResultNode().value, 0.00001);
taxo.close();
}
示例9: call
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Override
public Boolean call() throws Exception {
if (indexReader == null) {
indexReader = DirectoryReader.open(indexDir);
lastIndexGeneration = indexReader.getIndexCommit().getGeneration();
taxoReader = new DirectoryTaxonomyReader(taxoDir);
} else {
// verify search index
DirectoryReader newReader = DirectoryReader.openIfChanged(indexReader);
assertNotNull("should not have reached here if no changes were made to the index", newReader);
long newGeneration = newReader.getIndexCommit().getGeneration();
assertTrue("expected newer generation; current=" + lastIndexGeneration + " new=" + newGeneration, newGeneration > lastIndexGeneration);
indexReader.close();
indexReader = newReader;
lastIndexGeneration = newGeneration;
_TestUtil.checkIndex(indexDir);
// verify taxonomy index
DirectoryTaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(taxoReader);
if (newTaxoReader != null) {
taxoReader.close();
taxoReader = newTaxoReader;
}
_TestUtil.checkIndex(taxoDir);
// verify faceted search
int id = Integer.parseInt(indexReader.getIndexCommit().getUserData().get(VERSION_ID), 16);
CategoryPath cp = new CategoryPath("A", Integer.toString(id, 16));
IndexSearcher searcher = new IndexSearcher(indexReader);
FacetsCollector fc = FacetsCollector.create(new FacetSearchParams(new CountFacetRequest(cp, 10)), indexReader, taxoReader);
searcher.search(new MatchAllDocsQuery(), fc);
assertEquals(1, (int) fc.getFacetResults().get(0).getFacetResultNode().value);
DrillDownQuery drillDown = new DrillDownQuery(FacetIndexingParams.DEFAULT);
drillDown.add(cp);
TopDocs docs = searcher.search(drillDown, 10);
assertEquals(1, docs.totalHits);
}
return null;
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:41,代码来源:IndexAndTaxonomyReplicationClientTest.java
示例10: testDifferentAggregatorsSameCategoryList
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
@Test
public void testDifferentAggregatorsSameCategoryList() throws Exception {
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(
new SumIntAssociationFacetRequest(aint, 10),
new SumIntAssociationFacetRequest(bint, 10),
new SumFloatAssociationFacetRequest(afloat, 10),
new SumFloatAssociationFacetRequest(bfloat, 10));
Query q = new MatchAllDocsQuery();
FacetsCollector fc = FacetsCollector.create(fsp, reader, taxo);
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, fc);
List<FacetResult> res = fc.getFacetResults();
assertEquals("Wrong number of results!", 4, res.size());
assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
assertEquals("Wrong count for category 'a'!",50f, (float) res.get(2).getFacetResultNode().value, 0.00001);
assertEquals("Wrong count for category 'b'!",10f, (float) res.get(3).getFacetResultNode().value, 0.00001);
taxo.close();
}
示例11: testMemoryCacheSynchronization
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; //导入方法依赖的package包/类
/**
* Test that a new TFC is only calculated and placed in memory (by two
* threads who want it at the same time) only once.
*/
@Test
public void testMemoryCacheSynchronization() throws Exception {
SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null);
SlowRAMDirectory taxoDir = new SlowRAMDirectory(-1, null);
// Write index using 'normal' directories
IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
// Add documents and facets
for (int i = 0; i < 1000; i++) {
addFacets(iParams, w, tw, "facet", Integer.toString(i));
}
w.close();
tw.close();
indexDir.setSleepMillis(1);
taxoDir.setSleepMillis(1);
IndexReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// Create and start threads. Thread1 should lock the cache and calculate
// the TFC array. The second thread should block until the first is
// done, then successfully retrieve from the cache without recalculating
// or reading from disk.
TFCThread tfcCalc1 = new TFCThread(r, tr, iParams);
TFCThread tfcCalc2 = new TFCThread(r, tr, iParams);
tfcCalc1.start();
// Give thread 1 a head start to ensure correct sequencing for testing
Thread.sleep(5);
tfcCalc2.start();
tfcCalc1.join();
tfcCalc2.join();
// Since this test ends up with references to the same TFC object, we
// can only test the times to make sure that they are the same.
assertRecomputed(tfcCalc1.tfc, 0, "thread 1 should recompute");
assertRecomputed(tfcCalc2.tfc, 0, "thread 2 should recompute");
assertTrue("Both results should be the same (as their inputs are the same objects)",
tfcCalc1.tfc == tfcCalc2.tfc);
r.close();
tr.close();
}