Example usage for org.apache.lucene.search.uhighlight UnifiedHighlighter highlightFields

List of usage examples for org.apache.lucene.search.uhighlight UnifiedHighlighter highlightFields

Introduction

In this page you can find the example usage for org.apache.lucene.search.uhighlight UnifiedHighlighter highlightFields.

Prototype

public Map<String, String[]> highlightFields(String[] fieldsIn, Query query, int[] docidsIn,
        int[] maxPassagesIn) throws IOException 

Source Link

Document

Highlights the top-N passages from multiple fields, for the provided int[] docids.

Usage

From source file:org.apache.solr.highlight.UnifiedSolrHighlighter.java

License:Apache License

@Override
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields)
        throws IOException {
    final SolrParams params = req.getParams();

    // if highlighting isn't enabled, then why call doHighlighting?
    if (!isHighlightingEnabled(params))
        return null;

    int[] docIDs = toDocIDs(docs);

    // fetch the unique keys
    String[] keys = getUniqueKeys(req.getSearcher(), docIDs);

    // query-time parameters
    String[] fieldNames = getHighlightFields(query, req, defaultFields);

    int maxPassages[] = new int[fieldNames.length];
    for (int i = 0; i < fieldNames.length; i++) {
        maxPassages[i] = params.getFieldInt(fieldNames[i], HighlightParams.SNIPPETS, 1);
    }/*from w  ww . ja v  a  2 s . co  m*/

    UnifiedHighlighter highlighter = getHighlighter(req);
    Map<String, String[]> snippets = highlighter.highlightFields(fieldNames, query, docIDs, maxPassages);
    return encodeSnippets(keys, fieldNames, snippets);
}