本文整理汇总了Java中org.apache.lucene.search.TopDocsCollector.topDocs方法的典型用法代码示例。如果您正苦于以下问题:Java TopDocsCollector.topDocs方法的具体用法?Java TopDocsCollector.topDocs怎么用?Java TopDocsCollector.topDocs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TopDocsCollector
的用法示例。
在下文中一共展示了TopDocsCollector.topDocs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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"));
}
}
示例3: 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());
}
}
示例4: 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);
}
示例5: 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);
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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<String>(Float.NaN, topDocs.getMaxScore(), topDocs.totalHits, topDocs.scoreDocs, query.toString(), null);
if (main) {
mainResult = getDocList(groupDocs);
} else {
NamedList rsp = commonResponse();
addDocList(rsp, groupDocs);
}
}
示例9: sortDocSet
import org.apache.lucene.search.TopDocsCollector; //导入方法依赖的package包/类
protected void sortDocSet(QueryResult qr, QueryCommand cmd) throws IOException {
DocSet set = qr.getDocListAndSet().docSet;
int nDocs = cmd.getSupersetMaxDoc();
if (nDocs == 0) {
// SOLR-2923
qr.getDocListAndSet().docList = new DocSlice(0, 0, new int[0], null, set.size(), 0f);
qr.setNextCursorMark(cmd.getCursorMark());
return;
}
// 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 = buildTopDocsCollector(nDocs, cmd);
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;
}
qr.getDocListAndSet().docList = new DocSlice(0,nDocsReturned,ids,null,topDocs.totalHits,0.0f);
populateNextCursorMarkFromTopDocs(qr, cmd, topDocs);
}
示例10: queryIndex
import org.apache.lucene.search.TopDocsCollector; //导入方法依赖的package包/类
private void queryIndex(Query query, String fieldname) throws CorruptIndexException, IOException {
LOGGER.info("-------------------------------------");
long start = java.util.Calendar.getInstance().getTimeInMillis();
int hitsPerPage = 100;
IndexReader reader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(reader);
TopDocsCollector collector = TopScoreDocCollector.create(hitsPerPage, false);
indexSearcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
long end = java.util.Calendar.getInstance().getTimeInMillis();
// float duration = (end - start) / 1000;
LOGGER.info("Found " + hits.length + " hits in " + (end - start) + " milliseconds");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document document = indexSearcher.doc(docId);
LOGGER.info((i + 1) + ". " + document.get(fieldname));
}
}