本文整理汇总了Java中org.apache.lucene.facet.search.CountFacetRequest类的典型用法代码示例。如果您正苦于以下问题:Java CountFacetRequest类的具体用法?Java CountFacetRequest怎么用?Java CountFacetRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CountFacetRequest类属于org.apache.lucene.facet.search包,在下文中一共展示了CountFacetRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drillDown
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** User drills down on 'Publish date/2010'. */
private List<FacetResult> drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Now user drills down on Publish Date/2010:
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("Author"), 10));
DrillDownQuery q = new DrillDownQuery(fsp.indexingParams, new MatchAllDocsQuery());
q.add(new CategoryPath("Publish Date/2010", '/'));
FacetsCollector fc = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
searcher.search(q, fc);
// Retrieve results
List<FacetResult> facetResults = fc.getFacetResults();
indexReader.close();
taxoReader.close();
return facetResults;
}
示例2: findFacets
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** compute facets with certain facet requests and docs */
private List<FacetResult> findFacets(boolean withComplement) throws IOException {
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("root","a"), 10));
StandardFacetsAccumulator sfa = new StandardFacetsAccumulator(fsp, indexReader, taxoReader);
sfa.setComplementThreshold(withComplement ? StandardFacetsAccumulator.FORCE_COMPLEMENT : StandardFacetsAccumulator.DISABLE_COMPLEMENT);
FacetsCollector fc = FacetsCollector.create(sfa);
searcher.search(new MatchAllDocsQuery(), fc);
List<FacetResult> res = fc.getFacetResults();
// Results are ready, printing them...
int i = 0;
for (FacetResult facetResult : res) {
if (VERBOSE) {
System.out.println("Res "+(i++)+": "+facetResult);
}
}
assertEquals(withComplement, sfa.isUsingComplements());
return res;
}
示例3: verifyDrillDown
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
private void verifyDrillDown(Map<String,Integer> expectedCounts, FacetIndexingParams fip, DirectoryReader indexReader,
TaxonomyReader taxoReader, IndexSearcher searcher) throws IOException {
// verify drill-down
for (String dim : expectedCounts.keySet()) {
CategoryPath drillDownCP = new CategoryPath(dim);
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(drillDownCP, 10));
DrillDownQuery drillDown = new DrillDownQuery(fip, new MatchAllDocsQuery());
drillDown.add(drillDownCP);
TotalHitCountCollector total = new TotalHitCountCollector();
FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
searcher.search(drillDown, MultiCollector.wrap(fc, total));
assertTrue("no results for drill-down query " + drillDown, total.getTotalHits() > 0);
List<FacetResult> facetResults = fc.getFacetResults();
assertEquals(1, facetResults.size());
FacetResultNode rootNode = facetResults.get(0).getFacetResultNode();
assertEquals("wrong count for " + dim, expectedCounts.get(dim).intValue(), (int) rootNode.value);
}
}
示例4: verifyResults
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的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();
}
示例5: getDummyFacetsCollector
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
public FacetsCollector getDummyFacetsCollector(
final DirectoryReader indexReader,
final TaxonomyReader taxonomyReader) {
final List<FacetRequest> facets = new ArrayList<FacetRequest>();
final CategoryPath facetPath = new CategoryPath("Author", '/');
final CountFacetRequest facetRequest =
new CountFacetRequest(facetPath, 10);
facets.add(facetRequest);
final FacetSearchParams facetSearchParams =
new FacetSearchParams(facets);
final FacetsCollector facetsCollector =
FacetsCollector.create(
facetSearchParams,
indexReader,
taxonomyReader);
return facetsCollector;
}
示例6: getDummyFacetsCollector
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
private FacetsCollector getDummyFacetsCollector(
final DirectoryReader indexReader,
final TaxonomyReader taxonomyReader) {
final List<FacetRequest> facets = new ArrayList<FacetRequest>();
final CategoryPath facetPath = new CategoryPath("Author", '/');
final CountFacetRequest facetRequest =
new CountFacetRequest(facetPath, 10);
facets.add(facetRequest);
final FacetSearchParams facetSearchParams =
new FacetSearchParams(facets);
final FacetsCollector facetsCollector =
FacetsCollector.create(
facetSearchParams,
indexReader,
taxonomyReader);
return facetsCollector;
}
示例7: drillDown
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** User drills down on 'Publish Date/2010'. */
private List<FacetResult> drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Now user drills down on Publish Date/2010:
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("Author"), 10));
// Passing no baseQuery means we drill down on all
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(fsp.indexingParams);
q.add(new CategoryPath("Publish Date/2010", '/'));
FacetsCollector fc = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
searcher.search(q, fc);
// Retrieve results
List<FacetResult> facetResults = fc.getFacetResults();
indexReader.close();
taxoReader.close();
return facetResults;
}
示例8: drillDown
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** User drills down on 'Publish Year/2010'. */
private List<FacetResult> drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(indexReader);
// Now user drills down on Publish Year/2010:
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("Author"), 10));
DrillDownQuery q = new DrillDownQuery(fsp.indexingParams, new MatchAllDocsQuery());
q.add(new CategoryPath("Publish Year/2010", '/'));
FacetsCollector fc = FacetsCollector.create(new SortedSetDocValuesAccumulator(state, fsp));
searcher.search(q, fc);
// Retrieve results
List<FacetResult> facetResults = fc.getFacetResults();
indexReader.close();
return facetResults;
}
示例9: createAggregator
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
protected Aggregator createAggregator(FacetRequest fr, FacetArrays facetArrays) {
if (fr instanceof CountFacetRequest) {
// we rely on that, if needed, result is cleared by arrays!
int[] a = facetArrays.getIntArray();
if (isUsingComplements) {
return new ComplementCountingAggregator(a);
} else {
return new CountingAggregator(a);
}
} else if (fr instanceof SumScoreFacetRequest) {
if (isUsingComplements) {
throw new IllegalArgumentException("complements are not supported by SumScoreFacetRequest");
} else {
return new ScoringAggregator(facetArrays.getFloatArray());
}
} else if (fr instanceof OverSampledFacetRequest) {
return createAggregator(((OverSampledFacetRequest) fr).orig, facetArrays);
} else {
throw new IllegalArgumentException("unknown Aggregator implementation for request " + fr.getClass());
}
}
示例10: findFacets
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** compute facets with certain facet requests and docs */
private List<FacetResult> findFacets(boolean withComplement) throws IOException {
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("root","a"), 10));
OldFacetsAccumulator sfa = new OldFacetsAccumulator(fsp, indexReader, taxoReader);
sfa.setComplementThreshold(withComplement ? OldFacetsAccumulator.FORCE_COMPLEMENT : OldFacetsAccumulator.DISABLE_COMPLEMENT);
FacetsCollector fc = FacetsCollector.create(sfa);
searcher.search(new MatchAllDocsQuery(), fc);
List<FacetResult> res = fc.getFacetResults();
// Results are ready, printing them...
int i = 0;
if (VERBOSE) {
for (FacetResult facetResult : res) {
System.out.println("Res "+(i++)+": "+facetResult);
}
}
assertEquals(withComplement, sfa.isUsingComplements());
return res;
}
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:23,代码来源:TestFacetsAccumulatorWithComplement.java
示例11: testNoFixing
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
public void testNoFixing() throws Exception {
SamplingParams sp = new SamplingParams();
sp.setMaxSampleSize(10);
sp.setMinSampleSize(5);
sp.setSampleRatio(0.01d);
sp.setSamplingThreshold(50);
sp.setOversampleFactor(5d);
assertNull("Fixer should be null as the test is for no-fixing",
sp.getSampleFixer());
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(
new CategoryPath("root", "a"), 1));
SamplingAccumulator accumulator = new SamplingAccumulator(
new RandomSampler(sp, random()), fsp, indexReader, taxoReader);
// Make sure no complements are in action
accumulator
.setComplementThreshold(OldFacetsAccumulator.DISABLE_COMPLEMENT);
FacetsCollector fc = FacetsCollector.create(accumulator);
searcher.search(new MatchAllDocsQuery(), fc);
FacetResultNode node = fc.getFacetResults().get(0).getFacetResultNode();
assertTrue(node.value < numDocsToIndex());
}
示例12: search
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Count both "Publish Date" and "Author" dimensions
FacetSearchParams fsp = new FacetSearchParams(indexingParams,
new CountFacetRequest(new CategoryPath("Publish Date"), 10),
new CountFacetRequest(new CategoryPath("Author"), 10));
// Aggregatses the facet counts
FacetsCollector fc = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
// 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;
}
示例13: search
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Count both "Publish Date" and "Author" dimensions
FacetSearchParams fsp = new FacetSearchParams(
new CountFacetRequest(new CategoryPath("Publish Date"), 10),
new CountFacetRequest(new CategoryPath("Author"), 10));
// Aggregatses the facet counts
FacetsCollector fc = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
// 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;
}
示例14: testHashAndEquals
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
@Test
public void testHashAndEquals() {
CountFacetRequest fr1 = new CountFacetRequest(new CategoryPath("a"), 8);
CountFacetRequest fr2 = new CountFacetRequest(new CategoryPath("a"), 8);
assertEquals("hashCode() should agree on both objects", fr1.hashCode(), fr2.hashCode());
assertTrue("equals() should return true", fr1.equals(fr2));
fr1.setDepth(10);
assertFalse("equals() should return false as fr1.depth != fr2.depth", fr1.equals(fr2));
}
示例15: Search
import org.apache.lucene.facet.search.CountFacetRequest; //导入依赖的package包/类
/**
* Initializes a new instance of Search with a query,
* a set of facets (in {@link String} form with integer counts), an
* analyzer and a custom sort.
* @param qquery The query to be executed during the search.
* @param ffacets The facets for which to search.
* @param aanalyzer The analyzer with which to parse the
* query.
* @param ssort The custom sort order.
* @throws ParseException A fatal exception occurred while
* parsing the String query.
*/
public Search(
final String qquery,
final Map<String, Integer> ffacets,
final Analyzer aanalyzer,
final Sort ssort)
throws ParseException {
QueryParser parser =
new SearchQueryParser(
Lucene.LUCENE_VERSION,
Lucene.DEFAULT_QUERY_FIELD,
aanalyzer
);
parser.setDateResolution(Resolution.HOUR);
query = parser.parse(qquery);
if (ffacets == null) {
facets = null;
} else {
facets = new ArrayList<FacetRequest>(ffacets.size());
for (Entry<String, Integer> facet : ffacets.entrySet()) {
final CategoryPath facetPath =
new CategoryPath(facet.getKey(), '/');
final CountFacetRequest facetRequest =
new CountFacetRequest(facetPath, facet.getValue());
facets.add(facetRequest);
}
}
sort = ssort;
}