本文整理汇总了Java中org.apache.lucene.facet.search.FacetsAccumulator类的典型用法代码示例。如果您正苦于以下问题:Java FacetsAccumulator类的具体用法?Java FacetsAccumulator怎么用?Java FacetsAccumulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FacetsAccumulator类属于org.apache.lucene.facet.search包,在下文中一共展示了FacetsAccumulator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sumAssociations
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的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);
CategoryPath tags = new CategoryPath("tags");
CategoryPath genre = new CategoryPath("genre");
FacetSearchParams fsp = new FacetSearchParams(
new AssociationIntSumFacetRequest(tags, 10),
new AssociationFloatSumFacetRequest(genre, 10));
// every category has a different type of association, so use chain their
// respective aggregators.
final Map<CategoryPath,FacetsAggregator> aggregators = new HashMap<CategoryPath,FacetsAggregator>();
aggregators.put(tags, new SumIntAssociationFacetsAggregator());
aggregators.put(genre, new SumFloatAssociationFacetsAggregator());
FacetsAccumulator fa = new FacetsAccumulator(fsp, indexReader, taxoReader) {
@Override
public FacetsAggregator getAggregator() {
return new MultiAssociationsFacetsAggregator(aggregators);
}
};
FacetsCollector fc = FacetsCollector.create(fa);
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query, and use MultiCollector to
// wrap collecting the "normal" hits and also facets:
searcher.search(new MatchAllDocsQuery(), fc);
// Retrieve results
List<FacetResult> facetResults = fc.getFacetResults();
indexReader.close();
taxoReader.close();
return facetResults;
}
示例2: testIntSumAssociation
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的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();
}
示例3: testFloatSumAssociation
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的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();
}
示例4: testDifferentAggregatorsSameCategoryList
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的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();
}
示例5: wrap
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的package包/类
/** Wraps the given {@link FacetsAccumulator accumulators}. */
public static FacetsAccumulator wrap(FacetsAccumulator... accumulators) {
if (accumulators.length == 0) {
return accumulators[0];
} else {
return new MultiFacetsAccumulator(accumulators);
}
}
示例6: requiresDocScores
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的package包/类
@Override
public boolean requiresDocScores() {
for (FacetsAccumulator fa : accumulators) {
if (fa.requiresDocScores()) {
return true;
}
}
return false;
}
示例7: accumulate
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的package包/类
@Override
public List<FacetResult> accumulate(List<MatchingDocs> matchingDocs) throws IOException {
List<FacetResult> merged = new ArrayList<FacetResult>();
for (FacetsAccumulator fa : accumulators) {
merged.addAll(fa.accumulate(matchingDocs));
}
return merged;
}
示例8: MultiFacetsAccumulator
import org.apache.lucene.facet.search.FacetsAccumulator; //导入依赖的package包/类
private MultiFacetsAccumulator(FacetsAccumulator... accumulators) {
super((FacetSearchParams) null);
this.accumulators = accumulators;
}