当前位置: 首页>>代码示例>>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;未经允许,请勿转载。