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


Java SolrIndexSearcher.doc方法代码示例

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


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

示例1: for

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的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: getUniqueKeys

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
/** Retrieves the unique keys for the topdocs to key the results */
protected String[] getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs) throws IOException {
  IndexSchema schema = searcher.getSchema();
  SchemaField keyField = schema.getUniqueKeyField();
  if (keyField != null) {
    Set<String> selector = Collections.singleton(keyField.getName());
    String uniqueKeys[] = new String[docIDs.length];
    for (int i = 0; i < docIDs.length; i++) {
      int docid = docIDs[i];
      Document doc = searcher.doc(docid, selector);
      String id = schema.printableUniqueKey(doc);
      uniqueKeys[i] = id;
    }
    return uniqueKeys;
  } else {
    return new String[docIDs.length];
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:PostingsSolrHighlighter.java

示例3: process

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的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

示例4: getInputDocument

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public static SolrInputDocument getInputDocument(SolrCore core, BytesRef idBytes) throws IOException {
  SolrInputDocument sid = null;
  RefCounted<SolrIndexSearcher> searcherHolder = null;
  try {
    SolrIndexSearcher searcher = null;
    sid = getInputDocumentFromTlog(core, idBytes);
    if (sid == DELETED) {
      return null;
    }

    if (sid == null) {
      // didn't find it in the update log, so it should be in the newest searcher opened
      if (searcher == null) {
        searcherHolder = core.getRealtimeSearcher();
        searcher = searcherHolder.get();
      }

      // SolrCore.verbose("RealTimeGet using searcher ", searcher);
      SchemaField idField = core.getLatestSchema().getUniqueKeyField();

      int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes));
      if (docid < 0) return null;
      Document luceneDocument = searcher.doc(docid);
      sid = toSolrInputDocument(luceneDocument, core.getLatestSchema());
    }
  } finally {
    if (searcherHolder != null) {
      searcherHolder.decref();
    }
  }

  return sid;
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:RealTimeGetComponent.java

示例5: optimizePreFetchDocs

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的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

示例6: write

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
/**
 * Here the writer creates its output.
 * 
 * @param writer the character stream writer.
 * @param request the current {@link SolrQueryRequest}
 * @param response the output response.
 * @throws IOException in case of I/O failure.
 */
@SuppressWarnings("rawtypes")
@Override
public void write(
		final Writer writer, 
		final SolrQueryRequest request, 
		final SolrQueryResponse response) throws IOException {
	
	// 1. Get a reference to values that compound the current response
	final NamedList elements = response.getValues();
	
	// 2. Use a StringBuilder to build the output 
	final StringBuilder builder = new StringBuilder("{")
		.append("query:'")
		.append(request.getParams().get(CommonParams.Q))
		.append("',");
	
	// 3. Get a reference to the object which hold the query result
	final Object value = elements.getVal(1);		
	if (value instanceof ResultContext) {
		final ResultContext context = (ResultContext) value;
	
		// The ordered list (actually the page subset) of matched documents
		final DocList ids = context.getDocList();
		if (ids != null) {
			final SolrIndexSearcher searcher = request.getSearcher();
			final DocIterator iterator = ids.iterator();
			builder.append("suggestions:[");
			
			// 4. Iterate over documents
			for (int i = 0; i < ids.size(); i++) {
				// 5. For each document we need to get the corresponding "label" attribute
				final Document document = searcher.doc(iterator.nextDoc(), FIELDS);
				if (i > 0)  { builder.append(","); }
				
				// 6. Append the label value to writer output
				builder
					.append("'")
					.append(((String) document.get("label")).replaceAll("'", "\\\\'").replaceAll("\"", "\\\\\""))
					.append("'");
			}
			builder.append("]").append("}");
		}
	}
	
	// 7. and finally write out the built character stream by means of output writer.
	writer.write(builder.toString());
}
 
开发者ID:agazzarini,项目名称:as-full-text-search-server,代码行数:56,代码来源:CustomResponseWriter.java

示例7: doHighlighting

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
/**
 * Generates a list of Highlighted query fragments for each item in a list
 * of documents, or returns null if highlighting is disabled.
 *
 * @param docs query results
 * @param query the query
 * @param req the current request
 * @param defaultFields default list of fields to summarize
 *
 * @return NamedList containing a NamedList for each document, which in 
 * turns contains sets (field, summary) pairs.
 */
@Override
@SuppressWarnings("unchecked")
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
  SolrParams params = req.getParams(); 
  if (!isHighlightingEnabled(params))
      return null;
   
  SolrIndexSearcher searcher = req.getSearcher();
  IndexSchema schema = searcher.getSchema();
  NamedList fragments = new SimpleOrderedMap();
  String[] fieldNames = getHighlightFields(query, req, defaultFields);
  Set<String> fset = new HashSet<>();
   
  {
    // pre-fetch documents using the Searcher's doc cache
    for(String f : fieldNames) { fset.add(f); }
    // fetch unique key if one exists.
    SchemaField keyField = schema.getUniqueKeyField();
    if(null != keyField)
      fset.add(keyField.getName());  
  }

  // get FastVectorHighlighter instance out of the processing loop
  FastVectorHighlighter fvh = new FastVectorHighlighter(
      // FVH cannot process hl.usePhraseHighlighter parameter per-field basis
      params.getBool( HighlightParams.USE_PHRASE_HIGHLIGHTER, true ),
      // FVH cannot process hl.requireFieldMatch parameter per-field basis
      params.getBool( HighlightParams.FIELD_MATCH, false ) );
  fvh.setPhraseLimit(params.getInt(HighlightParams.PHRASE_LIMIT, SolrHighlighter.DEFAULT_PHRASE_LIMIT));
  FieldQuery fieldQuery = fvh.getFieldQuery( query, searcher.getIndexReader() );

  // Highlight each document
  DocIterator iterator = docs.iterator();
  for (int i = 0; i < docs.size(); i++) {
    int docId = iterator.nextDoc();
    Document doc = searcher.doc(docId, fset);
    NamedList docSummaries = new SimpleOrderedMap();
    for (String fieldName : fieldNames) {
      fieldName = fieldName.trim();
      if( useFastVectorHighlighter( params, schema, fieldName ) )
        doHighlightingByFastVectorHighlighter( fvh, fieldQuery, req, docSummaries, docId, doc, fieldName );
      else
        doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
    }
    String printId = schema.printableUniqueKey(doc);
    fragments.add(printId == null ? null : printId, docSummaries);
  }
  return fragments;
}
 
开发者ID:europeana,项目名称:search,代码行数:62,代码来源:DefaultSolrHighlighter.java


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