Java Code Examples for org.apache.solr.schema.IndexSchema#printableUniqueKey()

The following examples show how to use org.apache.solr.schema.IndexSchema#printableUniqueKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrPluginUtils.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
    SolrReturnFields returnFields = new SolrReturnFields(keyField.getName(), null);
    String[] uniqueKeys = new String[docIDs.length];
    for (int i = 0; i < docIDs.length; i++) {
      int docid = docIDs[i];
      SolrDocument solrDoc = searcher.getDocFetcher().solrDoc(docid, returnFields);
      uniqueKeys[i] = schema.printableUniqueKey(solrDoc);
    }
    return uniqueKeys;
  } else {
    return new String[docIDs.length];
  }
}