HighlightingHelper(Query query, Analyzer analyzer) { this.analyzer = analyzer; Formatter formatter = new SimpleHTMLFormatter(); Encoder encoder = new MinimalHTMLEncoder(); scorer = new QueryScorer(query); highlighter = new Highlighter(formatter, encoder, scorer); fragmentLength = DEFAULT_FRAGMENT_LENGTH; Fragmenter fragmenter = new SimpleSpanFragmenter(scorer, fragmentLength); highlighter.setTextFragmenter(fragmenter); }
/** * Return a {@link org.apache.lucene.search.highlight.Formatter} appropriate for this field. If a formatter * has not been configured for this field, fall back to the configured * default or the solr default ({@link org.apache.lucene.search.highlight.SimpleHTMLFormatter}). * * @param fieldName The name of the field * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Formatter}. */ protected Formatter getFormatter(String fieldName, SolrParams params ) { String str = params.getFieldParam( fieldName, HighlightParams.FORMATTER ); SolrFormatter formatter = formatters.get( str ); if( formatter == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown formatter: "+str ); } return formatter.getFormatter( fieldName, params ); }
@Override public Formatter getFormatter(String fieldName, SolrParams params ) { numRequests++; params = SolrParams.wrapDefaults(params, defaults); return new SimpleHTMLFormatter( params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE, "<em>" ), params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>")); }
public void setFormatter(Formatter formatter) { this.formatter = formatter; }
public LumongoHighlighter(Formatter formatter, Scorer fragmentScorer, Lumongo.HighlightRequest highlightRequest) { super(formatter, fragmentScorer); this.highlightRequest = highlightRequest; }
/** * * * @param query * @param analyzer * @param fieldName * @param fulltext * @param startDelimiter * @param stopDelimiter * @return * * @throws IOException * @throws InvalidTokenOffsetsException */ public static String getHighlightedField(Query query, Analyzer analyzer, String fieldName, String fulltext, final String startDelimiter, final String stopDelimiter) throws IOException, InvalidTokenOffsetsException { Formatter formatter = new SimpleHTMLFormatter(startDelimiter, stopDelimiter); QueryScorer queryScorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(formatter, queryScorer); highlighter.setTextFragmenter(new SimpleSpanFragmenter(queryScorer, Integer.MAX_VALUE)); highlighter.setMaxDocCharsToAnalyze(Integer.MAX_VALUE); return highlighter.getBestFragment(analyzer, fieldName, fulltext); }
/** * Return a {@link org.apache.lucene.search.highlight.Formatter} appropriate for this field. If a formatter has not * been configured for this field, fall back to the configured default or the solr default ( * {@link org.apache.lucene.search.highlight.SimpleHTMLFormatter}). * * @param fieldName * The name of the field * @param params * The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Formatter}. */ protected Formatter getFormatter(String fieldName, SolrParams params) { String str = params.getFieldParam(fieldName, HighlightParams.FORMATTER); SolrFormatter formatter = formatters.get(str); if (formatter == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown formatter: " + str); } return formatter.getFormatter(fieldName, params); }
/** * Return a {@link org.apache.lucene.search.highlight.Formatter} appropriate for this field. * * @param fieldName The name of the field * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.highlight.Formatter} */ public Formatter getFormatter(String fieldName, SolrParams params );