当前位置: 首页>>代码示例>>Java>>正文


Java TopDocsCollector.collect方法代码示例

本文整理汇总了Java中org.apache.lucene.search.TopDocsCollector.collect方法的典型用法代码示例。如果您正苦于以下问题:Java TopDocsCollector.collect方法的具体用法?Java TopDocsCollector.collect怎么用?Java TopDocsCollector.collect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.TopDocsCollector的用法示例。


在下文中一共展示了TopDocsCollector.collect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:41,代码来源:SolrIndexSearcher.java

示例2: 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);
}
 
开发者ID:netboynb,项目名称:search-core,代码行数:41,代码来源:SolrIndexSearcher.java

示例3: 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);
}
 
开发者ID:europeana,项目名称:search,代码行数:47,代码来源:SolrIndexSearcher.java


注:本文中的org.apache.lucene.search.TopDocsCollector.collect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。