本文整理汇总了Java中org.apache.lucene.search.IndexSearcher.searchAfter方法的典型用法代码示例。如果您正苦于以下问题:Java IndexSearcher.searchAfter方法的具体用法?Java IndexSearcher.searchAfter怎么用?Java IndexSearcher.searchAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.searchAfter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopDocs
import org.apache.lucene.search.IndexSearcher; //导入方法依赖的package包/类
/**
* Executes the given {@link Query} but returns lucene's {@link TopDocs}.
* @param query the query to execute
* @param options the additional options to execute the query.
* @return {@link TopDocs} or null if an error occurred.
*/
public TopDocs getTopDocs(final Query query, final SearchOptions options) {
TopDocs topDocs = null;
final Index index = IndexManager.getInstance().getIndex();
final IndexReader reader = index.getIndexReader();
final IndexSearcher searcher = new IndexSearcher(reader);
// stopwatch to check performance of search
final StopWatch stopWatch = new StopWatch();
try {
int maxResults = options.getMaxResults();
if(maxResults <= 0) {
maxResults = reader.numDocs();
}
stopWatch.start();
if(options.getSort() == null) {
if(options.getAfterScoreDoc() == null) {
topDocs = searcher.search(query, maxResults);
}
else {
topDocs = searcher.searchAfter(options.getAfterScoreDoc(), query, maxResults);
}
}
else {
if(options.getAfterScoreDoc() == null) {
topDocs = searcher.search(query, maxResults, options.getSort());
}
else {
topDocs = searcher.searchAfter(options.getAfterScoreDoc(), query, maxResults, options.getSort());
}
}
stopWatch.stop();
LOGGER.info("Query execution used {}ms {}.", stopWatch.getTime(), query);
}
catch (final IOException e) {
LOGGER.error("Can't execute search because of an IOException.", e);
}
return topDocs;
}