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


Java DocIterator类代码示例

本文整理汇总了Java中org.apache.solr.search.DocIterator的典型用法代码示例。如果您正苦于以下问题:Java DocIterator类的具体用法?Java DocIterator怎么用?Java DocIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: for

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
 * Generates an NamedList of Explanations for each item in a list of docs.
 *
 * @param query The Query you want explanations in the context of
 * @param docs The Documents you want explained relative that query
 */
public static NamedList<Explanation> getExplanations
  (Query query,
   DocList docs,
   SolrIndexSearcher searcher,
   IndexSchema schema) throws IOException {

  NamedList<Explanation> explainList = new SimpleOrderedMap<>();
  DocIterator iterator = docs.iterator();
  for (int i=0; i<docs.size(); i++) {
    int id = iterator.nextDoc();

    Document doc = searcher.doc(id);
    String strid = schema.printableUniqueKey(doc);

    explainList.add(strid, searcher.explain(query, id) );
  }
  return explainList;
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SolrPluginUtils.java

示例2: printDocIDs

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@SuppressWarnings("unused")
private void printDocIDs(DocSet fromSet) throws IOException {
	// Only used in debugging.
	System.out.println("---------------------------");
	DocIterator iter = fromSet.iterator();
	while (iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
		Integer docId = iter.next();
		Document d = fromSearcher.doc(docId);
		String id = d.getValues("id")[0];
		// TODO :log message  (this is too verbose?)
		if (debug) {
			System.out.println("INTERNAL ID : " + docId + " DOC : " + id);
		}
	}
	System.out.println("---------------------------");
}
 
开发者ID:kwatters,项目名称:solrgraph,代码行数:17,代码来源:GraphQuery.java

示例3: AbstractSolrCachingScorer

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
AbstractSolrCachingScorer(Weight weight, DocSet in, AtomicReaderContext context, Bits acceptDocs, SolrIndexSearcher searcher)
{
    super(weight);
    this.context = context;
    this.acceptDocs = acceptDocs;
    
    if (in instanceof BitDocSet)
    {
        matches = (BitDocSet) in;
    }
    else
    {
        this.matches = new BitDocSet(new FixedBitSet(searcher.maxDoc()));
        for (DocIterator it = in.iterator(); it.hasNext(); /* */)
        {
            matches.addUnique(it.nextDoc());
        }
    }
    bitSet = matches.getBits();
    
    doc = getBase() - 1;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:23,代码来源:AbstractSolrCachingScorer.java

示例4: AbstractSolrCachingScorer

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
AbstractSolrCachingScorer(Similarity similarity, DocSet in, SolrIndexReader solrIndexReader)
{
    super(similarity);
    if (in instanceof BitDocSet)
    {
        matches = (BitDocSet) in;
    }
    else
    {
        this.matches = new BitDocSet(new OpenBitSet(solrIndexReader.maxDoc()));
        for (DocIterator it = in.iterator(); it.hasNext(); /* */)
        {
            matches.addUnique(it.nextDoc());
        }
    }
    openBitSet = matches.getBits();
    this.solrIndexReader = solrIndexReader;
    doc = solrIndexReader.getBase() - 1;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:20,代码来源:AbstractSolrCachingScorer.java

示例5: testUngrouped

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  ResultContext response = (ResultContext)results.get("response");
  DocList docs = response.getDocList();
  assertEquals(2, docs.size());
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:17,代码来源:TestXJoinSearchComponent.java

示例6: testGroupedSimple

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testGroupedSimple() {
  ModifiableSolrParams params = new ModifiableSolrParams();    
  params.add("group", "true");
  params.add("group.field", "colour");
  params.add("group.format", "simple");
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  NamedList grouped = (NamedList)results.get("grouped");
  NamedList colours = (NamedList)grouped.get("colour");
  assertEquals(2, colours.get("matches"));
  DocList docs = (DocList)colours.get("doclist");
  assertEquals(docs.size(), 2);
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:22,代码来源:TestXJoinSearchComponent.java

示例7: testMultiValued

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
public void testMultiValued() throws Exception {
  Query q = parse(COMPONENT_NAME_4);
  DocSet docs = searcher.getDocSet(q);

  assertEquals(4, docs.size());
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(0, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(2, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());    
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:18,代码来源:TestXJoinQParserPlugin.java

示例8: testUngrouped

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  NamedList results = test(params, "xjoin");
  testXJoinResults(results, "xjoin");
  ResultContext response = (ResultContext)results.get("response");
  DocList docs = response.docs;
  assertEquals(2, docs.size());
  DocIterator it = docs.iterator();
  assertTrue(it.hasNext());
  assertEquals(1, it.nextDoc());
  assertTrue(it.hasNext());
  assertEquals(3, it.nextDoc());
  assertFalse(it.hasNext());
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:17,代码来源:TestXJoinSearchComponent.java

示例9: findParentIdsForNodes

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
private Map<String, Set<String>> findParentIdsForNodes(SolrIndexSearcher searcher, Collection<String> nodeIds) throws IOException {
	Map<String, Set<String>> parentIds = new HashMap<>();
	
	LOGGER.debug("Looking up parents for {} nodes", nodeIds.size());
	Query filter = buildFilterQuery(getNodeField(), nodeIds);
	LOGGER.trace("Filter query: {}", filter);
	
	DocSet docs = searcher.getDocSet(filter);
	
	for (DocIterator it = docs.iterator(); it.hasNext(); ) {
		Document doc = searcher.doc(it.nextDoc(), docFields);
		String nodeId = doc.get(getNodeField());
		
		Set<String> parentIdValues = new HashSet<>(Arrays.asList(doc.getValues(parentField)));
		parentIds.put(nodeId, parentIdValues);
		
		// Record the label, if required
		if (isLabelRequired(nodeId)) {
			recordLabel(nodeId, doc.getValues(getLabelField()));
		}
	}
	
	return parentIds;
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:25,代码来源:ParentNodeFacetTreeBuilder.java

示例10: for

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
 * Generates an NamedList of Explanations for each item in a list of docs.
 *
 * @param query The Query you want explanations in the context of
 * @param docs The Documents you want explained relative that query
 */
public static NamedList<Explanation> getExplanations
  (Query query,
   DocList docs,
   SolrIndexSearcher searcher,
   IndexSchema schema) throws IOException {

  NamedList<Explanation> explainList = new SimpleOrderedMap<Explanation>();
  DocIterator iterator = docs.iterator();
  for (int i=0; i<docs.size(); i++) {
    int id = iterator.nextDoc();

    Document doc = searcher.doc(id);
    String strid = schema.printableUniqueKey(doc);

    explainList.add(strid, searcher.explain(query, id) );
  }
  return explainList;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:25,代码来源:SolrPluginUtils.java

示例11: process

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
 * Here we define the component core logic.
 * For each document belonging to search results, we call an external service
 * for gathering a corresponding up-to-date price.
 * 
 * @param rb The {@link org.apache.solr.handler.component.ResponseBuilder}
 * @throws IOException If there is a low-level I/O error.
 */
@Override
public void process(final ResponseBuilder builder) throws IOException {
	// Sanity check: if the component hasn't been properly initialised 
	// then it must immediately return.
	// A more ideal approach could retry the initialisation (in the prepare method).
	if (!hasBeenCorrectlyInitialised) {
		return;
	}
	
	// Get a SolrIndexSearcher reference 
	final SolrIndexSearcher searcher = builder.req.getSearcher();

	// This NamediLis will hold the component contribution (i.e. the component result).
	final NamedList<Double> contribution = new SimpleOrderedMap<Double>();
	for (final DocIterator it = builder.getResults().docList.iterator(); it.hasNext();) {

		// This is NOT the Solr ID of our records, but instead the Lucene internal document id
		// which is different
		int docId = it.nextDoc();
		final Document luceneDocument = searcher.doc(docId);
		
		// This is the Solr document Id 
		String id = luceneDocument.get("id");

		// Get the price of the item
		final Double itemPrice = getPrice(id);

		// Add the price of the item to the component contribution
		contribution.add(id, itemPrice);
	}

	// Add the component contribution to the response builder
	builder.rsp.add("prices", contribution);			
}
 
开发者ID:agazzarini,项目名称:as-full-text-search-server,代码行数:43,代码来源:CustomSearchComponent.java

示例12: transform

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
@Override
public void transform(SolrDocument doc, int docid) {

  FieldType idFt = idField.getType();
  Object parentIdField = doc.getFirstValue(idField.getName());
  
  String parentIdExt = parentIdField instanceof IndexableField
    ? idFt.toExternal((IndexableField)parentIdField)
    : parentIdField.toString();

  try {
    Query parentQuery = idFt.getFieldQuery(null, idField, parentIdExt);
    Query query = new ToChildBlockJoinQuery(parentQuery, parentsFilter, false);
    DocList children = context.searcher.getDocList(query, childFilterQuery, new Sort(), 0, limit);
    if(children.matches() > 0) {
      DocIterator i = children.iterator();
      while(i.hasNext()) {
        Integer childDocNum = i.next();
        Document childDoc = context.searcher.doc(childDocNum);
        SolrDocument solrChildDoc = ResponseWriterUtil.toSolrDocument(childDoc, schema);

        // TODO: future enhancement...
        // support an fl local param in the transformer, which is used to build
        // a private ReturnFields instance that we use to prune unwanted field 
        // names from solrChildDoc
        doc.addChildDocument(solrChildDoc);
      }
    }
    
  } catch (IOException e) {
    doc.put(name, "Could not fetch child Documents");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:ChildDocTransformerFactory.java

示例13: processIds

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
protected void processIds(ResponseBuilder rb, DocList dl, IndexSchema schema,
    SolrIndexSearcher searcher) throws IOException {
  
  StringBuilder sb = new StringBuilder();

  Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
  for(DocIterator iter = dl.iterator(); iter.hasNext();) {

    sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
      .append(',');
  }
  if (sb.length() > 0) {
    rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
  }  
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:ResponseLogComponent.java

示例14: processScores

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
protected void processScores(ResponseBuilder rb, DocList dl, IndexSchema schema,
    SolrIndexSearcher searcher) throws IOException {
  
  StringBuilder sb = new StringBuilder();
  Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
  for(DocIterator iter = dl.iterator(); iter.hasNext();) {
    sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
      .append(':')
      .append(iter.score())
      .append(',');
  }
  if (sb.length() > 0) {
    rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
  }  
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:ResponseLogComponent.java

示例15: optimizePreFetchDocs

import org.apache.solr.search.DocIterator; //导入依赖的package包/类
/**
 * Pre-fetch documents into the index searcher's document cache.
 *
 * This is an entirely optional step which you might want to perform for
 * the following reasons:
 *
 * <ul>
 *     <li>Locates the document-retrieval costs in one spot, which helps
 *     detailed performance measurement</li>
 *
 *     <li>Determines a priori what fields will be needed to be fetched by
 *     various subtasks, like response writing and highlighting.  This
 *     minimizes the chance that many needed fields will be loaded lazily.
 *     (it is more efficient to load all the field we require normally).</li>
 * </ul>
 *
 * If lazy field loading is disabled, this method does nothing.
 */
public static void optimizePreFetchDocs(ResponseBuilder rb,
                                        DocList docs,
                                        Query query,
                                        SolrQueryRequest req,
                                        SolrQueryResponse res) throws IOException {
  SolrIndexSearcher searcher = req.getSearcher();
  if(!searcher.enableLazyFieldLoading) {
    // nothing to do
    return;
  }

  ReturnFields returnFields = res.getReturnFields();
  if(returnFields.getLuceneFieldNames() != null) {
    Set<String> fieldFilter = returnFields.getLuceneFieldNames();

    if (rb.doHighlights) {
      // copy return fields list
      fieldFilter = new HashSet<>(fieldFilter);
      // add highlight fields

      SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore());
      for (String field: highlighter.getHighlightFields(query, req, null))
        fieldFilter.add(field);

      // fetch unique key if one exists.
      SchemaField keyField = searcher.getSchema().getUniqueKeyField();
      if(null != keyField)
        fieldFilter.add(keyField.getName());
    }

    // get documents
    DocIterator iter = docs.iterator();
    for (int i=0; i<docs.size(); i++) {
      searcher.doc(iter.nextDoc(), fieldFilter);
    }

  }

}
 
开发者ID:europeana,项目名称:search,代码行数:58,代码来源:SolrPluginUtils.java


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