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