本文整理汇总了Java中org.apache.lucene.search.Sort.rewrite方法的典型用法代码示例。如果您正苦于以下问题:Java Sort.rewrite方法的具体用法?Java Sort.rewrite怎么用?Java Sort.rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.Sort
的用法示例。
在下文中一共展示了Sort.rewrite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
/**
* Finds the top {@code count} hits for {@code query} and sorting the hits
* by {@code sort}.
*
* @param query
* the {@link Query} to search for
* @param sort
* the {@link Sort} to be applied
* @param count
* the max number of results to be collected
* @param fields
* the names of the fields to be loaded
* @return the found documents
*/
public List<Document> search(Query query, Sort sort, Integer count, Set<String> fields) {
try {
indexWriter.commit();
IndexReader reader = DirectoryReader.open(directory);
IndexSearcher searcher = new IndexSearcher(reader);
sort = sort.rewrite(searcher);
TopDocs topDocs = searcher.search(query, count, sort);
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
List<Document> documents = new LinkedList<>();
for (ScoreDoc scoreDoc : scoreDocs) {
Document document = searcher.doc(scoreDoc.doc, fields);
documents.add(document);
}
searcher.getIndexReader().close();
return documents;
} catch (IOException e) {
throw new FhirIndexException(e, "Error while searching");
}
}
示例2: ReRankCollector
import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
public ReRankCollector(int reRankDocs,
int length,
Query reRankQuery,
double reRankWeight,
SolrIndexSearcher.QueryCommand cmd,
IndexSearcher searcher,
Map<BytesRef, Integer> boostedPriority) throws IOException {
super(null);
this.reRankQuery = reRankQuery;
this.reRankDocs = reRankDocs;
this.length = length;
this.boostedPriority = boostedPriority;
Sort sort = cmd.getSort();
if(sort == null) {
this.mainCollector = TopScoreDocCollector.create(Math.max(this.reRankDocs, length),true);
} else {
sort = sort.rewrite(searcher);
this.mainCollector = TopFieldCollector.create(sort, Math.max(this.reRankDocs, length), false, true, true, true);
}
this.searcher = searcher;
this.reRankWeight = reRankWeight;
}
示例3: weightSort
import org.apache.lucene.search.Sort; //导入方法依赖的package包/类
/** Returns a weighted sort according to this searcher */
public Sort weightSort(Sort sort) throws IOException {
return (sort != null) ? sort.rewrite(this) : null;
}