本文整理汇总了Java中org.apache.lucene.search.TopDocsCollector类的典型用法代码示例。如果您正苦于以下问题:Java TopDocsCollector类的具体用法?Java TopDocsCollector怎么用?Java TopDocsCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TopDocsCollector类属于org.apache.lucene.search包,在下文中一共展示了TopDocsCollector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTopDocsCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
/**
* Helper method for inspecting QueryCommand and creating the appropriate
* {@link TopDocsCollector}
*
* @param len the number of docs to return
* @param cmd The Command whose properties should determine the type of
* TopDocsCollector to use.
*/
private TopDocsCollector buildTopDocsCollector(int len, QueryCommand cmd) throws IOException {
Query q = cmd.getQuery();
if(q instanceof RankQuery) {
RankQuery rq = (RankQuery)q;
return rq.getTopDocsCollector(len, cmd, this);
}
if (null == cmd.getSort()) {
assert null == cmd.getCursorMark() : "have cursor but no sort";
return TopScoreDocCollector.create(len, true);
} else {
// we have a sort
final boolean needScores = (cmd.getFlags() & GET_SCORES) != 0;
final Sort weightedSort = weightSort(cmd.getSort());
final CursorMark cursor = cmd.getCursorMark();
// :TODO: make fillFields it's own QueryCommand flag? ...
// ... see comments in populateNextCursorMarkFromTopDocs for cache issues (SOLR-5595)
final boolean fillFields = (null != cursor);
final FieldDoc searchAfter = (null != cursor ? cursor.getSearchAfterFieldDoc() : null);
return TopFieldCollector.create(weightedSort, len, searchAfter,
fillFields, needScores, needScores, true);
}
}
示例2: buildTopDocsCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
/**
* Helper method for inspecting QueryCommand and creating the appropriate
* {@link TopDocsCollector}
*
* @param len the number of docs to return
* @param cmd The Command whose properties should determine the type of
* TopDocsCollector to use.
*/
private TopDocsCollector buildTopDocsCollector(int len, QueryCommand cmd) throws IOException {
if (null == cmd.getSort()) {
assert null == cmd.getCursorMark() : "have cursor but no sort";
return TopScoreDocCollector.create(len, true);
} else {
// we have a sort
final boolean needScores = (cmd.getFlags() & GET_SCORES) != 0;
final Sort weightedSort = weightSort(cmd.getSort());
final CursorMark cursor = cmd.getCursorMark();
// :TODO: make fillFields it's own QueryCommand flag? ...
// ... see comments in populateNextCursorMarkFromTopDocs for cache issues (SOLR-5595)
final boolean fillFields = (null != cursor);
final FieldDoc searchAfter = (null != cursor ? cursor.getSearchAfterFieldDoc() : null);
return TopFieldCollector.create(weightedSort, len, searchAfter,
fillFields, needScores, needScores, true);
}
}
示例3: query
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
private static void query(String indexDir, Query q) throws IOException, ParseException {
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexDir)));
IndexSearcher indexSearcher = new IndexSearcher(reader);
TopDocsCollector collector = TopScoreDocCollector.create(hitsPerPage, false);
indexSearcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
LOGGER.info("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document d = indexSearcher.doc(docId);
// LOGGER.info((i + 1) + ". " + d.get("title"));
}
// searcher can only be closed when there
// is no need to access the documents any more.
// indexSearcher.close();
}
示例4: query
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
private static void query(IndexSearcher indexSearcher, Query q) throws IOException, ParseException {
int hitsPerPage = 10;
TopDocsCollector collector = TopScoreDocCollector.create(hitsPerPage, false);
indexSearcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
LOGGER.info("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document d = indexSearcher.doc(docId);
LOGGER.info((i + 1) + ". " + d.get("title"));
}
}
示例5: topDocs
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
@Override
public TopDocs topDocs(SearchContext context, FetchSubPhase.HitContext hitContext) throws IOException {
Query rawParentFilter;
if (parentObjectMapper == null) {
rawParentFilter = Queries.newNonNestedFilter();
} else {
rawParentFilter = parentObjectMapper.nestedTypeFilter();
}
BitSetProducer parentFilter = context.bitsetFilterCache().getBitSetProducer(rawParentFilter);
Query childFilter = childObjectMapper.nestedTypeFilter();
Query q = Queries.filtered(query(), new NestedChildrenQuery(parentFilter, childFilter, hitContext));
if (size() == 0) {
return new TopDocs(context.searcher().count(q), Lucene.EMPTY_SCORE_DOCS, 0);
} else {
int topN = Math.min(from() + size(), context.searcher().getIndexReader().maxDoc());
TopDocsCollector topDocsCollector;
if (sort() != null) {
try {
topDocsCollector = TopFieldCollector.create(sort().sort, topN, true, trackScores(), trackScores());
} catch (IOException e) {
throw ExceptionsHelper.convertToElastic(e);
}
} else {
topDocsCollector = TopScoreDocCollector.create(topN);
}
try {
context.searcher().search(q, topDocsCollector);
} finally {
clearReleasables(Lifetime.COLLECTION);
}
return topDocsCollector.topDocs(from(), size());
}
}
示例6: EarlyTerminationCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
public EarlyTerminationCollector(TopDocsCollector collector, Sort sort, int numDocsToCollectPerSortedSegment) {
if (numDocsToCollectPerSortedSegment <= 0) {
throw new IllegalStateException(
"numDocsToCollectPerSortedSegment must always be > 0, got " + numDocsToCollectPerSortedSegment);
}
this.collector = collector;
this.sort = sort;
this.numDocsToCollectPerSortedSegment = numDocsToCollectPerSortedSegment;
}
示例7: LindenDocsCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
public LindenDocsCollector(Collector collector) {
if (!(collector instanceof TopDocsCollector) && !(collector instanceof EarlyTerminationCollector)) {
throw new RuntimeException("Unsupported collector class in LindenDocsCollector: " + collector.getClass().getName());
}
hitCollector = collector;
wrappedCollector = collector;
}
示例8: reduce
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
@Override
public TopDocs reduce(Collection<AccessibleTimeLimitingCollector> collectors) throws IOException {
TopDocs[] docs = collectors.stream()
.map(AccessibleTimeLimitingCollector::getWrappedCollector)
.map(TopDocsCollector::topDocs)
.collect(Collectors.toList())
.toArray(new TopDocs[collectors.size()]);
return TopDocs.merge(perPage, docs);
}
示例9: getTotalHits
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
public int getTotalHits() {
if (totalHits == null) {
try {
TopDocsCollector documentCollector = TopFieldCollector.create(
this.sort, 1, null, false, false, false, false);
searcher.search(this.q, documentCollector);
this.totalHits = documentCollector.getTotalHits();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
return this.totalHits;
}
示例10: queryDocuments
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
private TopDocs queryDocuments(int pageSize, FieldDoc memento) throws IOException {
TopDocsCollector documentCollector = TopFieldCollector.create(
this.sort, pageSize, memento, true, false, false, false);
searcher.search(this.q, documentCollector);
this.totalHits = documentCollector.getTotalHits();
return documentCollector.topDocs(0, pageSize);
}
示例11: newCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
TopDocsCollector newCollector(Sort sort, boolean needScores) throws IOException {
int groupDocsToCollect = getMax(groupOffset, docsPerGroup, maxDoc);
if (sort == null || sort == Sort.RELEVANCE) {
return TopScoreDocCollector.create(groupDocsToCollect, true);
} else {
return TopFieldCollector.create(searcher.weightSort(sort), groupDocsToCollect, false, needScores, needScores, true);
}
}
示例12: finish
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void finish() throws IOException {
TopDocsCollector topDocsCollector = (TopDocsCollector) collector.getDelegate();
TopDocs topDocs = topDocsCollector.topDocs();
GroupDocs<String> groupDocs = new GroupDocs<>(Float.NaN, topDocs.getMaxScore(), topDocs.totalHits, topDocs.scoreDocs, query.toString(), null);
if (main) {
mainResult = getDocList(groupDocs);
} else {
NamedList rsp = commonResponse();
addDocList(rsp, groupDocs);
}
}
示例13: getTopDocsCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
public TopDocsCollector getTopDocsCollector(int len, SolrIndexSearcher.QueryCommand cmd, IndexSearcher searcher) throws IOException {
if(this.boostedPriority == null) {
SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
if(info != null) {
Map context = info.getReq().getContext();
this.boostedPriority = (Map<BytesRef, Integer>)context.get(QueryElevationComponent.BOOSTED_PRIORITY);
}
}
return new ReRankCollector(reRankDocs, length, reRankQuery, reRankWeight, cmd, searcher, boostedPriority);
}
示例14: getTopDocsCollector
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
public TopDocsCollector getTopDocsCollector(int len, SolrIndexSearcher.QueryCommand cmd, IndexSearcher searcher) throws IOException {
if(this.boostedPriority == null) {
SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
if(info != null) {
Map context = info.getReq().getContext();
this.boostedPriority = (Map<BytesRef, Integer>)context.get(QueryElevationComponent.BOOSTED_PRIORITY);
}
}
return new ReRankCollector(reRankDocs, length, reRankQuery, reRankWeight, cmd, searcher, boostedPriority, scale);
}
示例15: sortDocSet
import org.apache.lucene.search.TopDocsCollector; //导入依赖的package包/类
protected DocList sortDocSet(DocSet set, Sort sort, int nDocs) throws IOException {
if (nDocs == 0) {
// SOLR-2923
return new DocSlice(0, 0, new int[0], null, 0, 0f);
}
// bit of a hack to tell if a set is sorted - do it better in the future.
boolean inOrder = set instanceof BitDocSet || set instanceof SortedIntDocSet;
TopDocsCollector topCollector = TopFieldCollector.create(weightSort(sort), nDocs, false, false, false, inOrder);
DocIterator iter = set.iterator();
int base=0;
int end=0;
int readerIndex = 0;
while (iter.hasNext()) {
int doc = iter.nextDoc();
while (doc>=end) {
AtomicReaderContext leaf = leafContexts.get(readerIndex++);
base = leaf.docBase;
end = base + leaf.reader().maxDoc();
topCollector.setNextReader(leaf);
// we should never need to set the scorer given the settings for the collector
}
topCollector.collect(doc-base);
}
TopDocs topDocs = topCollector.topDocs(0, nDocs);
int nDocsReturned = topDocs.scoreDocs.length;
int[] ids = new int[nDocsReturned];
for (int i=0; i<nDocsReturned; i++) {
ScoreDoc scoreDoc = topDocs.scoreDocs[i];
ids[i] = scoreDoc.doc;
}
return new DocSlice(0,nDocsReturned,ids,null,topDocs.totalHits,0.0f);
}