本文整理汇总了Java中org.apache.lucene.facet.taxonomy.TaxonomyWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java TaxonomyWriter.close方法的具体用法?Java TaxonomyWriter.close怎么用?Java TaxonomyWriter.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.facet.taxonomy.TaxonomyWriter
的用法示例。
在下文中一共展示了TaxonomyWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReallyNoNormsForDrillDown
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
public void testReallyNoNormsForDrillDown() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setSimilarity(new PerFieldSimilarityWrapper() {
final Similarity sim = new DefaultSimilarity();
@Override
public Similarity get(String name) {
assertEquals("field", name);
return sim;
}
});
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
FacetFields facetFields = new FacetFields(taxoWriter);
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
writer.addDocument(doc);
writer.close();
taxoWriter.close();
dir.close();
taxoDir.close();
}
示例2: beforeClass
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
dir = newDirectory();
taxoDir = newDirectory();
// preparations - index, taxonomy, content
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
// Cannot mix ints & floats in the same indexed field:
config = new FacetsConfig();
config.setIndexFieldName("int", "$facets.int");
config.setMultiValued("int", true);
config.setIndexFieldName("float", "$facets.float");
config.setMultiValued("float", true);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
// index documents, 50% have only 'b' and all have 'a'
for (int i = 0; i < 110; i++) {
Document doc = new Document();
// every 11th document is added empty, this used to cause the association
// aggregators to go into an infinite loop
if (i % 11 != 0) {
doc.add(new IntAssociationFacetField(2, "int", "a"));
doc.add(new FloatAssociationFacetField(0.5f, "float", "a"));
if (i % 2 == 0) { // 50
doc.add(new IntAssociationFacetField(3, "int", "b"));
doc.add(new FloatAssociationFacetField(0.2f, "float", "b"));
}
}
writer.addDocument(config.build(taxoWriter, doc));
}
taxoWriter.close();
reader = writer.getReader();
writer.close();
taxoReader = new DirectoryTaxonomyReader(taxoDir);
}
示例3: 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);
}
示例4: beforeClassAssociationsFacetRequestTest
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClassAssociationsFacetRequestTest() throws Exception {
dir = newDirectory();
taxoDir = newDirectory();
// preparations - index, taxonomy, content
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random(), MockTokenizer.KEYWORD, false)));
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
AssociationsFacetFields assocFacetFields = new AssociationsFacetFields(taxoWriter);
// index documents, 50% have only 'b' and all have 'a'
for (int i = 0; i < 100; i++) {
Document doc = new Document();
CategoryAssociationsContainer associations = new CategoryAssociationsContainer();
associations.setAssociation(aint, new CategoryIntAssociation(2));
associations.setAssociation(afloat, new CategoryFloatAssociation(0.5f));
if (i % 2 == 0) { // 50
associations.setAssociation(bint, new CategoryIntAssociation(3));
associations.setAssociation(bfloat, new CategoryFloatAssociation(0.2f));
}
assocFacetFields.addFields(doc, associations);
writer.addDocument(doc);
}
taxoWriter.close();
reader = writer.getReader();
writer.close();
}
示例5: testSumScoreAggregator
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testSumScoreAggregator() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
doc.add(new StringField("f", "v", Store.NO));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams sParams = new FacetSearchParams(new SumScoreFacetRequest(new CategoryPath("a"), 10));
FacetsAccumulator fa = new FacetsAccumulator(sParams, r, taxo) {
@Override
public FacetsAggregator getAggregator() {
return new SumScoreFacetsAggregator();
}
};
FacetsCollector fc = FacetsCollector.create(fa);
TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
new IndexSearcher(r).search(new MatchAllDocsQuery(), MultiCollector.wrap(fc, topDocs));
List<FacetResult> res = fc.getFacetResults();
double value = res.get(0).getFacetResultNode().value;
double expected = topDocs.topDocs().getMaxScore() * r.numDocs();
assertEquals(expected, value, 1E-10);
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例6: testMultiCountingLists
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testMultiCountingLists() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
doc.add(new StringField("f", "v", Store.NO));
List<CategoryPath> cats = new ArrayList<CategoryPath>();
cats.add(new CategoryPath("a"));
cats.add(new CategoryPath("b"));
facetFields.addFields(doc, cats);
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams sParams = new FacetSearchParams(fip,
new CountFacetRequest(new CategoryPath("a"), 10),
new CountFacetRequest(new CategoryPath("b"), 10));
FacetsCollector fc = FacetsCollector.create(sParams, r, taxo);
new IndexSearcher(r).search(new MatchAllDocsQuery(), fc);
for (FacetResult res : fc.getFacetResults()) {
assertEquals("unexpected count for " + res, r.maxDoc(), (int) res.getFacetResultNode().value);
}
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例7: beforeClassAssociationsFacetRequestTest
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClassAssociationsFacetRequestTest() throws Exception {
dir = newDirectory();
taxoDir = newDirectory();
// preparations - index, taxonomy, content
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random(), MockTokenizer.KEYWORD, false)));
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
AssociationsFacetFields assocFacetFields = new AssociationsFacetFields(taxoWriter);
// index documents, 50% have only 'b' and all have 'a'
for (int i = 0; i < 110; i++) {
Document doc = new Document();
CategoryAssociationsContainer associations = new CategoryAssociationsContainer();
// every 11th document is added empty, this used to cause the association
// aggregators to go into an infinite loop
if (i % 11 != 0) {
associations.setAssociation(aint, new CategoryIntAssociation(2));
associations.setAssociation(afloat, new CategoryFloatAssociation(0.5f));
if (i % 2 == 0) { // 50
associations.setAssociation(bint, new CategoryIntAssociation(3));
associations.setAssociation(bfloat, new CategoryFloatAssociation(0.2f));
}
}
assocFacetFields.addFields(doc, associations);
writer.addDocument(doc);
}
taxoWriter.close();
reader = writer.getReader();
writer.close();
}
示例8: testSumScoreAggregator
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testSumScoreAggregator() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
if (random().nextBoolean()) { // don't match all documents
doc.add(new StringField("f", "v", Store.NO));
}
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams fsp = new FacetSearchParams(new SumScoreFacetRequest(new CategoryPath("a"), 10));
FacetsCollector fc = FacetsCollector.create(fsp, r, taxo);
TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
ConstantScoreQuery csq = new ConstantScoreQuery(new MatchAllDocsQuery());
csq.setBoost(2.0f);
newSearcher(r).search(csq, MultiCollector.wrap(fc, topDocs));
List<FacetResult> res = fc.getFacetResults();
float value = (float) res.get(0).getFacetResultNode().value;
TopDocs td = topDocs.topDocs();
int expected = (int) (td.getMaxScore() * td.totalHits);
assertEquals(expected, (int) value);
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例9: testMultiCountingLists
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testMultiCountingLists() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
doc.add(new StringField("f", "v", Store.NO));
List<CategoryPath> cats = new ArrayList<CategoryPath>();
cats.add(new CategoryPath("a"));
cats.add(new CategoryPath("b"));
facetFields.addFields(doc, cats);
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams sParams = new FacetSearchParams(fip,
new CountFacetRequest(new CategoryPath("a"), 10),
new CountFacetRequest(new CategoryPath("b"), 10));
FacetsCollector fc = FacetsCollector.create(sParams, r, taxo);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
for (FacetResult res : fc.getFacetResults()) {
assertEquals("unexpected count for " + res, r.maxDoc(), (int) res.getFacetResultNode().value);
}
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例10: testCountRoot
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testCountRoot() throws Exception {
// LUCENE-4882: FacetsAccumulator threw NPE if a FacetRequest was defined on CP.EMPTY
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
facetFields.addFields(doc, Arrays.asList(new CategoryPath("a"), new CategoryPath("b")));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(CategoryPath.EMPTY, 10));
final TaxonomyFacetsAccumulator fa = random().nextBoolean() ? new TaxonomyFacetsAccumulator(fsp, r, taxo) : new OldFacetsAccumulator(fsp, r, taxo);
FacetsCollector fc = FacetsCollector.create(fa);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
FacetResult res = fc.getFacetResults().get(0);
for (FacetResultNode node : res.getFacetResultNode().subResults) {
assertEquals(r.numDocs(), (int) node.value);
}
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例11: testGetFacetResultsTwice
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testGetFacetResultsTwice() throws Exception {
// LUCENE-4893: counts were multiplied as many times as getFacetResults was called.
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
Document doc = new Document();
facetFields.addFields(doc, Arrays.asList(new CategoryPath("a/1", '/'), new CategoryPath("b/1", '/')));
iw.addDocument(doc);
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams fsp = new FacetSearchParams(
new CountFacetRequest(new CategoryPath("a"), 10),
new CountFacetRequest(new CategoryPath("b"), 10));
final TaxonomyFacetsAccumulator fa = random().nextBoolean() ? new TaxonomyFacetsAccumulator(fsp, r, taxo) : new OldFacetsAccumulator(fsp, r, taxo);
final FacetsCollector fc = FacetsCollector.create(fa);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
List<FacetResult> res1 = fc.getFacetResults();
List<FacetResult> res2 = fc.getFacetResults();
assertSame("calling getFacetResults twice should return the exact same result", res1, res2);
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例12: testReset
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testReset() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
Document doc = new Document();
facetFields.addFields(doc, Arrays.asList(new CategoryPath("a/1", '/'), new CategoryPath("b/1", '/')));
iw.addDocument(doc);
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
FacetSearchParams fsp = new FacetSearchParams(
new CountFacetRequest(new CategoryPath("a"), 10),
new CountFacetRequest(new CategoryPath("b"), 10));
final TaxonomyFacetsAccumulator fa = random().nextBoolean() ? new TaxonomyFacetsAccumulator(fsp, r, taxo) : new OldFacetsAccumulator(fsp, r, taxo);
final FacetsCollector fc = FacetsCollector.create(fa);
// this should populate the cached results, but doing search should clear the cache
fc.getFacetResults();
newSearcher(r).search(new MatchAllDocsQuery(), fc);
List<FacetResult> res1 = fc.getFacetResults();
// verify that we didn't get the cached result
assertEquals(2, res1.size());
for (FacetResult res : res1) {
assertEquals(1, res.getFacetResultNode().subResults.size());
assertEquals(1, (int) res.getFacetResultNode().subResults.get(0).value);
}
fc.reset();
List<FacetResult> res2 = fc.getFacetResults();
assertNotSame("reset() should clear the cached results", res1, res2);
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例13: testNumValidDescendants
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testNumValidDescendants() throws Exception {
// LUCENE-4885: FacetResult.numValidDescendants was not set properly by FacetsAccumulator
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
for (int i = 0; i < 10; i++) {
Document doc = new Document();
facetFields.addFields(doc, Arrays.asList(new CategoryPath("a", Integer.toString(i))));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
CountFacetRequest cfr = new CountFacetRequest(new CategoryPath("a"), 2);
cfr.setResultMode(random().nextBoolean() ? ResultMode.GLOBAL_FLAT : ResultMode.PER_NODE_IN_TREE);
FacetSearchParams fsp = new FacetSearchParams(cfr);
final TaxonomyFacetsAccumulator fa = random().nextBoolean() ? new TaxonomyFacetsAccumulator(fsp, r, taxo) : new OldFacetsAccumulator(fsp, r, taxo);
FacetsCollector fc = FacetsCollector.create(fa);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
FacetResult res = fc.getFacetResults().get(0);
assertEquals(10, res.getNumValidDescendants());
IOUtils.close(taxo, taxoDir, r, indexDir);
}
示例14: testNoScore
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testNoScore() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetFields facetFields = new FacetFields(taxonomyWriter);
for (int i = 0; i < 4; i++) {
Document doc = new Document();
doc.add(new NumericDocValuesField("price", (i+1)));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a", Integer.toString(i % 2))));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
ValueSource valueSource = new LongFieldSource("price");
FacetSearchParams fsp = new FacetSearchParams(new SumValueSourceFacetRequest(new CategoryPath("a"), 10, valueSource, false));
FacetsCollector fc = FacetsCollector.create(fsp, r, taxo);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
List<FacetResult> res = fc.getFacetResults();
assertEquals("a (0)\n 1 (6)\n 0 (4)\n", FacetTestUtils.toSimpleString(res.get(0)));
IOUtils.close(taxo, taxoDir, r, indexDir);
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:33,代码来源:TestSumValueSourceFacetRequest.java
示例15: testRollupValues
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入方法依赖的package包/类
@Test
public void testRollupValues() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
FacetIndexingParams fip = new FacetIndexingParams(new CategoryListParams() {
@Override
public OrdinalPolicy getOrdinalPolicy(String dimension) {
return OrdinalPolicy.NO_PARENTS;
}
});
FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
for (int i = 0; i < 4; i++) {
Document doc = new Document();
doc.add(new NumericDocValuesField("price", (i+1)));
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a", Integer.toString(i % 2), "1")));
iw.addDocument(doc);
}
taxonomyWriter.close();
iw.close();
DirectoryReader r = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
ValueSource valueSource = new LongFieldSource("price");
FacetSearchParams fsp = new FacetSearchParams(fip, new SumValueSourceFacetRequest(new CategoryPath("a"), 10, valueSource, false));
FacetsCollector fc = FacetsCollector.create(fsp, r, taxo);
newSearcher(r).search(new MatchAllDocsQuery(), fc);
List<FacetResult> res = fc.getFacetResults();
assertEquals("a (10)\n 1 (6)\n 0 (4)\n", FacetTestUtils.toSimpleString(res.get(0)));
IOUtils.close(taxo, taxoDir, r, indexDir);
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:38,代码来源:TestSumValueSourceFacetRequest.java