本文整理汇总了Java中org.apache.lucene.search.TotalHitCountCollector.getTotalHits方法的典型用法代码示例。如果您正苦于以下问题:Java TotalHitCountCollector.getTotalHits方法的具体用法?Java TotalHitCountCollector.getTotalHits怎么用?Java TotalHitCountCollector.getTotalHits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TotalHitCountCollector
的用法示例。
在下文中一共展示了TotalHitCountCollector.getTotalHits方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例5: 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;
}
示例6: 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;
}
示例7: 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();
}
示例8: 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);
}
}
示例9: 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;
}
示例10: getWordFreqForClass
import org.apache.lucene.search.TotalHitCountCollector; //导入方法依赖的package包/类
private int getWordFreqForClass(String word, BytesRef c) throws IOException {
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new BooleanClause(new TermQuery(new Term(textFieldName, word)), BooleanClause.Occur.MUST));
booleanQuery.add(new BooleanClause(new TermQuery(new Term(classFieldName, c)), BooleanClause.Occur.MUST));
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
indexSearcher.search(booleanQuery, totalHitCountCollector);
return totalHitCountCollector.getTotalHits();
}
示例11: getTotalDocs
import org.apache.lucene.search.TotalHitCountCollector; //导入方法依赖的package包/类
private static int getTotalDocs(NodeContext context) throws IOException {
TotalHitCountCollector collector = new TotalHitCountCollector();
context.req.getSearcher().search(new MatchAllDocsQuery(), collector);
return collector.getTotalHits();
}
示例12: simpleDocCount
import org.apache.lucene.search.TotalHitCountCollector; //导入方法依赖的package包/类
/**
* Simple utility method to get document counts for a given query.
* This uses TotalHitCounter.
*
* @param query query
* @param reader reader
* @return number of docs with a hit
* @throws java.io.IOException if there is an exception from teh searcher
*/
public int simpleDocCount(Query query, IndexReader reader) throws IOException {
IndexSearcher searcher = new IndexSearcher(reader);
TotalHitCountCollector collector = new TotalHitCountCollector();
searcher.search(query, collector);
return collector.getTotalHits();
}