本文整理汇总了Java中org.apache.lucene.facet.taxonomy.TaxonomyWriter.commit方法的典型用法代码示例。如果您正苦于以下问题:Java TaxonomyWriter.commit方法的具体用法?Java TaxonomyWriter.commit怎么用?Java TaxonomyWriter.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.facet.taxonomy.TaxonomyWriter
的用法示例。
在下文中一共展示了TaxonomyWriter.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doLogic
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Override
public int doLogic() throws Exception {
TaxonomyWriter taxonomyWriter = getRunData().getTaxonomyWriter();
if (taxonomyWriter != null) {
taxonomyWriter.commit();
} else {
throw new IllegalStateException("TaxonomyWriter is not currently open");
}
return 1;
}
示例2: testDefault
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testDefault() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
FacetsConfig config = getConfig();
seedIndex(tw, iw, config);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector sfc = performSearch(tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(getTaxonomyFacetCounts(tr, config, sfc));
assertOrdinalsExist("$facets", ir);
IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
示例3: testCustom
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testCustom() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
FacetsConfig config = getConfig();
config.setIndexFieldName("Author", "$author");
seedIndex(tw, iw, config);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector sfc = performSearch(tr, ir, searcher);
Map<String,Facets> facetsMap = new HashMap<>();
facetsMap.put("Author", getTaxonomyFacetCounts(tr, config, sfc, "$author"));
Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));
// Obtain facets results and hand-test them
assertCorrectResults(facets);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$author", ir);
IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
示例4: testDifferentFieldsAndText
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testDifferentFieldsAndText() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
FacetsConfig config = getConfig();
config.setIndexFieldName("Band", "$bands");
config.setIndexFieldName("Composer", "$composers");
seedIndex(tw, iw, config);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector sfc = performSearch(tr, ir, searcher);
Map<String,Facets> facetsMap = new HashMap<>();
facetsMap.put("Band", getTaxonomyFacetCounts(tr, config, sfc, "$bands"));
facetsMap.put("Composer", getTaxonomyFacetCounts(tr, config, sfc, "$composers"));
Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));
// Obtain facets results and hand-test them
assertCorrectResults(facets);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$bands", ir);
assertOrdinalsExist("$composers", ir);
IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
示例5: initIndex
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
/** Prepare index (in RAM/Disk) with some documents and some facets. */
protected final void initIndex(boolean forceDisk, FacetIndexingParams fip) throws Exception {
int partitionSize = fip.getPartitionSize();
if (VERBOSE) {
System.out.println("Partition Size: " + partitionSize + " forceDisk: "+forceDisk);
}
SearchTaxoDirPair pair = dirsPerPartitionSize.get(Integer.valueOf(partitionSize));
if (pair == null) {
pair = new SearchTaxoDirPair();
if (forceDisk) {
pair.searchDir = newFSDirectory(new File(TEST_DIR, "index"));
pair.taxoDir = newFSDirectory(new File(TEST_DIR, "taxo"));
} else {
pair.searchDir = newDirectory();
pair.taxoDir = newDirectory();
}
RandomIndexWriter iw = new RandomIndexWriter(random(), pair.searchDir, getIndexWriterConfig(getAnalyzer()));
TaxonomyWriter taxo = new DirectoryTaxonomyWriter(pair.taxoDir, OpenMode.CREATE);
populateIndex(iw, taxo, fip);
// commit changes (taxonomy prior to search index for consistency)
taxo.commit();
iw.commit();
taxo.close();
iw.close();
dirsPerPartitionSize.put(Integer.valueOf(partitionSize), pair);
}
// prepare for searching
taxoReader = new DirectoryTaxonomyReader(pair.taxoDir);
indexReader = DirectoryReader.open(pair.searchDir);
searcher = newSearcher(indexReader);
}
示例6: testDefault
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testDefault() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(Collections.<CategoryPath, CategoryListParams>emptyMap());
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
assertOrdinalsExist("$facets", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例7: testCustom
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testCustom() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(
Collections.singletonMap(new CategoryPath("Author"), new CategoryListParams("$author")));
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$author", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例8: testTwoCustomsSameField
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testTwoCustomsSameField() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$music", ir);
assertOrdinalsExist("$music", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例9: testDifferentFieldsAndText
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testDifferentFieldsAndText() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$bands"));
paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$composers"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$bands", ir);
assertOrdinalsExist("$composers", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例10: testSomeSameSomeDifferent
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testSomeSameSomeDifferent() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
paramsMap.put(new CategoryPath("Author"), new CategoryListParams("$literature"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
assertOrdinalsExist("$music", ir);
assertOrdinalsExist("$literature", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例11: testTwoCustomsSameField
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testTwoCustomsSameField() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
FacetsConfig config = getConfig();
config.setIndexFieldName("Band", "$music");
config.setIndexFieldName("Composer", "$music");
seedIndex(tw, iw, config);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector sfc = performSearch(tr, ir, searcher);
Map<String,Facets> facetsMap = new HashMap<>();
Facets facets2 = getTaxonomyFacetCounts(tr, config, sfc, "$music");
facetsMap.put("Band", facets2);
facetsMap.put("Composer", facets2);
Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));
// Obtain facets results and hand-test them
assertCorrectResults(facets);
assertOrdinalsExist("$facets", ir);
assertOrdinalsExist("$music", ir);
assertOrdinalsExist("$music", ir);
IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
示例12: testSomeSameSomeDifferent
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testSomeSameSomeDifferent() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// create and open an index writer
RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
FacetsConfig config = getConfig();
config.setIndexFieldName("Band", "$music");
config.setIndexFieldName("Composer", "$music");
config.setIndexFieldName("Author", "$literature");
seedIndex(tw, iw, config);
IndexReader ir = iw.getReader();
tw.commit();
// prepare index reader and taxonomy.
TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
FacetsCollector sfc = performSearch(tr, ir, searcher);
Map<String,Facets> facetsMap = new HashMap<>();
Facets facets2 = getTaxonomyFacetCounts(tr, config, sfc, "$music");
facetsMap.put("Band", facets2);
facetsMap.put("Composer", facets2);
facetsMap.put("Author", getTaxonomyFacetCounts(tr, config, sfc, "$literature"));
Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));
// Obtain facets results and hand-test them
assertCorrectResults(facets);
assertOrdinalsExist("$music", ir);
assertOrdinalsExist("$literature", ir);
IOUtils.close(tr, ir, iw, tw);
IOUtils.close(indexDir, taxoDir);
}
示例13: testGenerationalConsistency
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
/**
* Simple test to make sure the TotalFacetCountsManager updates the
* TotalFacetCounts array only when it is supposed to, and whether it
* is recomputed or read from disk.
*/
@Test
public void testGenerationalConsistency() throws Exception {
// Create temporary RAMDirectories
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// Create our index/taxonomy writers
IndexWriter indexWriter = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
// Add a facet to the index
addFacets(iParams, indexWriter, taxoWriter, "a", "b");
// Commit Changes
indexWriter.commit();
taxoWriter.commit();
// Open readers
DirectoryReader indexReader = DirectoryReader.open(indexDir);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// As this is the first time we have invoked the TotalFacetCountsManager,
// we should expect to compute and not read from disk.
TotalFacetCounts totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
int prevGen = assertRecomputed(totalCounts, 0, "after first attempt to get it!");
// Repeating same operation should pull from the cache - not recomputed.
assertTrue("Should be obtained from cache at 2nd attempt",totalCounts ==
TFC.getTotalCounts(indexReader, taxoReader, iParams));
// Repeat the same operation as above. but clear first - now should recompute again
initCache();
totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 3rd attempt to get it!");
//store to file
File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
initCache();
TFC.store(outputFile, indexReader, taxoReader, iParams);
totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 4th attempt to get it!");
//clear and load
initCache();
TFC.load(outputFile, indexReader, taxoReader, iParams);
totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
prevGen = assertReadFromDisc(totalCounts, prevGen, "after 5th attempt to get it!");
// Add a new facet to the index, commit and refresh readers
addFacets(iParams, indexWriter, taxoWriter, "c", "d");
IOUtils.close(indexWriter, taxoWriter);
TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(taxoReader);
assertNotNull(newTaxoReader);
assertTrue("should have received more cagtegories in updated taxonomy", newTaxoReader.getSize() > taxoReader.getSize());
taxoReader.close();
taxoReader = newTaxoReader;
DirectoryReader r2 = DirectoryReader.openIfChanged(indexReader);
assertNotNull(r2);
indexReader.close();
indexReader = r2;
// now use the new reader - should recompute
totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after updating the index - 7th attempt!");
// try again - should not recompute
assertTrue("Should be obtained from cache at 8th attempt",totalCounts ==
TFC.getTotalCounts(indexReader, taxoReader, iParams));
IOUtils.close(indexReader, taxoReader);
outputFile.delete();
IOUtils.close(indexDir, taxoDir);
}
示例14: testGrowingTaxonomy
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
/**
* This test is to address a bug in a previous version. If a TFC cache is
* written to disk, and then the taxonomy grows (but the index does not change),
* and then the TFC cache is re-read from disk, there will be an exception
* thrown, as the integers are read off of the disk according to taxonomy
* size, which has changed.
*/
@Test
public void testGrowingTaxonomy() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
// Create our index/taxonomy writers
IndexWriter indexWriter = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
FacetIndexingParams iParams = new FacetIndexingParams() {
@Override
public int getPartitionSize() {
return 2;
}
};
// Add a facet to the index
addFacets(iParams, indexWriter, taxoWriter, "a", "b");
// Commit Changes
indexWriter.commit();
taxoWriter.commit();
DirectoryReader indexReader = DirectoryReader.open(indexDir);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Create TFC and write cache to disk
File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
TFC.store(outputFile, indexReader, taxoReader, iParams);
// Make the taxonomy grow without touching the index
for (int i = 0; i < 10; i++) {
taxoWriter.addCategory(new CategoryPath("foo", Integer.toString(i)));
}
taxoWriter.commit();
TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(taxoReader);
assertNotNull(newTaxoReader);
taxoReader.close();
taxoReader = newTaxoReader;
initCache();
// With the bug, this next call should result in an exception
TFC.load(outputFile, indexReader, taxoReader, iParams);
TotalFacetCounts totalCounts = TFC.getTotalCounts(indexReader, taxoReader, iParams);
assertReadFromDisc(totalCounts, 0, "after reading from disk.");
outputFile.delete();
IOUtils.close(indexWriter, taxoWriter, indexReader, taxoReader);
IOUtils.close(indexDir, taxoDir);
}
示例15: testMultipleIndices
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
/**
* Simple test to make sure the TotalFacetCountsManager updates the
* TotalFacetCounts array only when it is supposed to, and whether it
* is recomputed or read from disk, but this time with TWO different
* TotalFacetCounts
*/
@Test
public void testMultipleIndices() throws IOException {
Directory indexDir1 = newDirectory(), indexDir2 = newDirectory();
Directory taxoDir1 = newDirectory(), taxoDir2 = newDirectory();
// Create our index/taxonomy writers
IndexWriter indexWriter1 = new IndexWriter(indexDir1, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
IndexWriter indexWriter2 = new IndexWriter(indexDir2, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
TaxonomyWriter taxoWriter1 = new DirectoryTaxonomyWriter(taxoDir1);
TaxonomyWriter taxoWriter2 = new DirectoryTaxonomyWriter(taxoDir2);
FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
// Add a facet to the index
addFacets(iParams, indexWriter1, taxoWriter1, "a", "b");
addFacets(iParams, indexWriter1, taxoWriter1, "d", "e");
// Commit Changes
indexWriter1.commit();
indexWriter2.commit();
taxoWriter1.commit();
taxoWriter2.commit();
// Open two readers
DirectoryReader indexReader1 = DirectoryReader.open(indexDir1);
DirectoryReader indexReader2 = DirectoryReader.open(indexDir2);
TaxonomyReader taxoReader1 = new DirectoryTaxonomyReader(taxoDir1);
TaxonomyReader taxoReader2 = new DirectoryTaxonomyReader(taxoDir2);
// As this is the first time we have invoked the TotalFacetCountsManager, we
// should expect to compute.
TotalFacetCounts totalCounts0 = TFC.getTotalCounts(indexReader1, taxoReader1, iParams);
int prevGen = -1;
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 1");
assertTrue("attempt 1b for same input [0] shout find it in cache",
totalCounts0 == TFC.getTotalCounts(indexReader1, taxoReader1, iParams));
// 2nd Reader - As this is the first time we have invoked the
// TotalFacetCountsManager, we should expect a state of NEW to be returned.
TotalFacetCounts totalCounts1 = TFC.getTotalCounts(indexReader2, taxoReader2, iParams);
prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 2");
assertTrue("attempt 2b for same input [1] shout find it in cache",
totalCounts1 == TFC.getTotalCounts(indexReader2, taxoReader2, iParams));
// Right now cache size is one, so first TFC is gone and should be recomputed
totalCounts0 = TFC.getTotalCounts(indexReader1, taxoReader1, iParams);
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 3");
// Similarly will recompute the second result
totalCounts1 = TFC.getTotalCounts(indexReader2, taxoReader2, iParams);
prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 4");
// Now we set the cache size to two, meaning both should exist in the
// cache simultaneously
TFC.setCacheSize(2);
// Re-compute totalCounts0 (was evicted from the cache when the cache was smaller)
totalCounts0 = TFC.getTotalCounts(indexReader1, taxoReader1, iParams);
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 5");
// now both are in the larger cache and should not be recomputed
totalCounts1 = TFC.getTotalCounts(indexReader2, taxoReader2, iParams);
assertTrue("with cache of size 2 res no. 0 should come from cache",
totalCounts0 == TFC.getTotalCounts(indexReader1, taxoReader1, iParams));
assertTrue("with cache of size 2 res no. 1 should come from cache",
totalCounts1 == TFC.getTotalCounts(indexReader2, taxoReader2, iParams));
IOUtils.close(indexWriter1, indexWriter2, taxoWriter1, taxoWriter2);
IOUtils.close(indexReader1, indexReader2, taxoReader1, taxoReader2);
IOUtils.close(indexDir1, indexDir2, taxoDir1, taxoDir2);
}