本文整理匯總了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;
}