本文整理汇总了Java中org.apache.lucene.search.TotalHitCountCollector类的典型用法代码示例。如果您正苦于以下问题:Java TotalHitCountCollector类的具体用法?Java TotalHitCountCollector怎么用?Java TotalHitCountCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TotalHitCountCollector类属于org.apache.lucene.search包,在下文中一共展示了TotalHitCountCollector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: olderDocumentsExists
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
/**
* Searches the index, if older documents exists. Updates the solr query response.
*
* @param req - the solr query request information
* @param rsp - the solr query response information
* @return true if the hit count is greater zero, otherwise false
* @throws SyntaxError, IOException if bad things happen
*/
private boolean olderDocumentsExists(String queryString, SolrQueryRequest req, SolrQueryResponse rsp) throws SyntaxError, IOException {
String defType = req.getParams().get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);
QParser queryParser = QParser.getParser(queryString, defType, req);
Query query = queryParser.getQuery();
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
req.getSearcher().search(query, totalHitCountCollector);
rsp.add("query", String.format("%s:[* TO NOW-%s]", queryField, timeSeriesAge));
rsp.add("queryTechnical", queryString);
rsp.add("removedDocuments", totalHitCountCollector.getTotalHits());
return totalHitCountCollector.getTotalHits() != 0;
}
示例2: numDocs
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
/**
* Returns the number of documents that match both <code>a</code> and <code>b</code>.
* <p>
* This method is cache-aware and may check as well as modify the cache.
*
* @return the number of documents in the intersection between <code>a</code> and <code>b</code>.
* @throws IOException If there is a low-level I/O error.
*/
public int numDocs(Query a, DocSet b) throws IOException {
if (filterCache != null) {
// Negative query if absolute value different from original
Query absQ = QueryUtils.getAbs(a);
DocSet positiveA = getPositiveDocSet(absQ);
return a==absQ ? b.intersectionSize(positiveA) : b.andNotSize(positiveA);
} else {
// If there isn't a cache, then do a single filtered query
// NOTE: we cannot use FilteredQuery, because BitDocSet assumes it will never
// have deleted documents, but UninvertedField's doNegative has sets with deleted docs
TotalHitCountCollector collector = new TotalHitCountCollector();
BooleanQuery bq = new BooleanQuery();
bq.add(QueryUtils.makeQueryable(a), BooleanClause.Occur.MUST);
bq.add(new ConstantScoreQuery(b.getTopFilter()), BooleanClause.Occur.MUST);
super.search(bq, null, collector);
return collector.getTotalHits();
}
}
示例3: countIndexedNodes
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
@Override
public int countIndexedNodes( long nodeId, Object propertyValue )
{
Query nodeIdQuery = new TermQuery( documentLogic.newTermForChangeOrRemove( nodeId ) );
Query valueQuery = documentLogic.newSeekQuery( propertyValue );
BooleanQuery.Builder nodeIdAndValueQuery = new BooleanQuery.Builder().setDisableCoord( true );
nodeIdAndValueQuery.add( nodeIdQuery, BooleanClause.Occur.MUST );
nodeIdAndValueQuery.add( valueQuery, BooleanClause.Occur.MUST );
try
{
TotalHitCountCollector collector = new TotalHitCountCollector();
searcher.search( nodeIdAndValueQuery.build(), collector );
// A <label,propertyKeyId,nodeId> tuple should only match at most a single propertyValue
return collector.getTotalHits();
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}
示例4: verifyNotFacetsData
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private void verifyNotFacetsData(DirectoryReader indexReader, IndexSearcher searcher) throws IOException {
// verify that non facets data was not damaged
TotalHitCountCollector total = new TotalHitCountCollector();
searcher.search(new PrefixQuery(new Term("foo", "content")), total);
assertEquals("invalid number of results for content query", total.getTotalHits(), indexReader.maxDoc());
int numDocIDs = 0;
for (AtomicReaderContext context : indexReader.leaves()) {
Terms docIDs = context.reader().terms("docid");
assertNotNull(docIDs);
TermsEnum te = docIDs.iterator(null);
while (te.next() != null) {
++numDocIDs;
}
}
assertEquals("invalid number of docid terms", indexReader.maxDoc(), numDocIDs);
}
示例5: verifyDrillDown
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的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);
}
}
示例6: testLowLevelCancellableCollector
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
public void testLowLevelCancellableCollector() throws IOException {
TotalHitCountCollector collector = new TotalHitCountCollector();
AtomicBoolean cancelled = new AtomicBoolean();
CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, true, collector);
final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0));
leafCollector.collect(0);
cancelled.set(true);
expectThrows(TaskCancelledException.class, () -> leafCollector.collect(1));
}
示例7: testCancellableCollector
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
public void testCancellableCollector() throws IOException {
TotalHitCountCollector collector = new TotalHitCountCollector();
AtomicBoolean cancelled = new AtomicBoolean();
CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, false, collector);
final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0));
leafCollector.collect(0);
cancelled.set(true);
leafCollector.collect(1);
expectThrows(TaskCancelledException.class, () -> cancellableCollector.getLeafCollector(reader.leaves().get(1)));
}
示例8: testCollector
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
public void testCollector() throws IOException {
TotalHitCountCollector collector = new TotalHitCountCollector();
ProfileCollector profileCollector = new ProfileCollector(collector);
assertEquals(0, profileCollector.getTime());
final LeafCollector leafCollector = profileCollector.getLeafCollector(reader.leaves().get(0));
assertThat(profileCollector.getTime(), greaterThan(0L));
long time = profileCollector.getTime();
leafCollector.setScorer(null);
assertThat(profileCollector.getTime(), greaterThan(time));
time = profileCollector.getTime();
leafCollector.collect(0);
assertThat(profileCollector.getTime(), greaterThan(time));
}
示例9: count
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private int count(Query query) {
TotalHitCountCollector collector = new TotalHitCountCollector();
try {
searcher.search(query, collector);
} catch (IOException e) {
throw new RuntimeException(e);
}
return collector.getTotalHits();
}
示例10: createCounter
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private AdCategoryWithCounterVO createCounter(final IndexSearcher searcher, final Query query, final Filters baseFilters, final AdCategory adCategory, final AdCategoryWithCounterVO parent, final int level) throws IOException {
// Run with filters based on the current category
Filters filters = (Filters) baseFilters.clone();
filters.addTerms("category", adCategory.getId());
TotalHitCountCollector collector = new TotalHitCountCollector();
searcher.search(query, filters, collector);
int totalCount = collector.getTotalHits();
AdCategoryWithCounterVO counter = new AdCategoryWithCounterVO(adCategory.getId(), adCategory.getName(), level, totalCount, parent);
// Repeat recursively for each child
for (AdCategory childCategory : adCategory.getChildren()) {
AdCategoryWithCounterVO childCounter = createCounter(searcher, query, baseFilters, childCategory, counter, level + 1);
counter.addChild(childCounter);
}
return counter;
}
示例11: countDocsWithClass
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private int countDocsWithClass() throws IOException {
int docCount = MultiFields.getTerms(this.atomicReader, this.classFieldName).getDocCount();
if (docCount == -1) { // in case codec doesn't support getDocCount
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
BooleanQuery q = new BooleanQuery();
q.add(new BooleanClause(new WildcardQuery(new Term(classFieldName, String.valueOf(WildcardQuery.WILDCARD_STRING))), BooleanClause.Occur.MUST));
if (query != null) {
q.add(query, BooleanClause.Occur.MUST);
}
indexSearcher.search(q,
totalHitCountCollector);
docCount = totalHitCountCollector.getTotalHits();
}
return docCount;
}
示例12: getWordFreqForClass
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private int getWordFreqForClass(String word, BytesRef c) throws IOException {
BooleanQuery booleanQuery = new BooleanQuery();
BooleanQuery subQuery = new BooleanQuery();
for (String textFieldName : textFieldNames) {
subQuery.add(new BooleanClause(new TermQuery(new Term(textFieldName, word)), BooleanClause.Occur.SHOULD));
}
booleanQuery.add(new BooleanClause(subQuery, BooleanClause.Occur.MUST));
booleanQuery.add(new BooleanClause(new TermQuery(new Term(classFieldName, c)), BooleanClause.Occur.MUST));
if (query != null) {
booleanQuery.add(query, BooleanClause.Occur.MUST);
}
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
indexSearcher.search(booleanQuery, totalHitCountCollector);
return totalHitCountCollector.getTotalHits();
}
示例13: createFirstPassCollector
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Collector createFirstPassCollector() throws IOException {
// Ok we don't want groups, but do want a total count
if (actualGroupsToFind <= 0) {
fallBackCollector = new TotalHitCountCollector();
return fallBackCollector;
}
sort = sort == null ? Sort.RELEVANCE : sort;
firstPass = new TermFirstPassGroupingCollector(groupBy, sort, actualGroupsToFind);
return firstPass;
}
示例14: searchHits
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private int searchHits(final Query query,
final ClusterSegment... clusterSegments) {
final IndexSearcher index = indexManager.getIndexSearcher(clusterSegments);
try {
final TotalHitCountCollector collector = new TotalHitCountCollector();
index.search(query,
collector);
return collector.getTotalHits();
} catch (final Exception ex) {
throw new RuntimeException("Error during Query!",
ex);
} finally {
indexManager.release(index);
}
}
示例15: countDocsWithClass
import org.apache.lucene.search.TotalHitCountCollector; //导入依赖的package包/类
private int countDocsWithClass() throws IOException {
int docCount = MultiFields.getTerms(this.atomicReader, this.classFieldName).getDocCount();
if (docCount == -1) { // in case codec doesn't support getDocCount
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
indexSearcher.search(new WildcardQuery(new Term(classFieldName, String.valueOf(WildcardQuery.WILDCARD_STRING))),
totalHitCountCollector);
docCount = totalHitCountCollector.getTotalHits();
}
return docCount;
}