當前位置: 首頁>>代碼示例>>Java>>正文


Java TopScoreDocCollector.getTotalHits方法代碼示例

本文整理匯總了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;
	}
}
 
開發者ID:searsia,項目名稱:searsiaserver,代碼行數:22,代碼來源:SearchResultIndex.java

示例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;
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:20,代碼來源:SearchFiles.java


注:本文中的org.apache.lucene.search.TopScoreDocCollector.getTotalHits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。