本文整理汇总了Java中org.apache.lucene.search.TopScoreDocCollector.getTotalHits方法的典型用法代码示例。如果您正苦于以下问题:Java TopScoreDocCollector.getTotalHits方法的具体用法?Java TopScoreDocCollector.getTotalHits怎么用?Java TopScoreDocCollector.getTotalHits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TopScoreDocCollector
的用法示例。
在下文中一共展示了TopScoreDocCollector.getTotalHits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHit
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
/**
* Get Hit by Lucene id. Used for tests only
* @param hitId
* @return hit
* @throws IOException
*/
protected Hit getHit(String hitId) throws IOException {
Term term = new Term("id", hitId);
Query query = new TermQuery(term);
TopScoreDocCollector collector = TopScoreDocCollector.create(1, true);
if (hitsSearcher == null) openReader();
hitsSearcher.search(query, collector);
if (collector.getTotalHits() > 0) {
ScoreDoc[] docs = collector.topDocs().scoreDocs;
Document doc = hitsSearcher.doc(docs[0].doc);
Hit hit = new Hit(doc.get("result"));
return hit;
} else {
return null;
}
}
示例2: doPagingSearch
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
/**
* This demonstrates a typical paging search scenario, where the search engine presents pages of size n to the user. The user can
* then go to the next page if interested in the next hits.
*
* When the query is executed for the first time, then only enough results are collected to fill 5 result pages. If the user wants
* to page beyond this limit, then the query is executed another time and all hits are collected.
*
*/
public static ScoreDoc[] doPagingSearch(Searcher searcher, Query query, int noOfPages) throws IOException {
// Collect enough docs to show 5 pages
TopScoreDocCollector collector = TopScoreDocCollector.create(noOfPages, true);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
int numTotalHits = collector.getTotalHits();
// System.out.println("Confidence Score : : "+hits.length);
System.out.println(numTotalHits + " total matching documents");
return hits;
}