Java Code Examples for org.apache.lucene.search.highlight.WeightedSpanTermExtractor

The following examples show how to use org.apache.lucene.search.highlight.WeightedSpanTermExtractor. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: DefaultSolrHighlighter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a {@link org.apache.lucene.search.highlight.QueryScorer} suitable for this Query and field.
 *
 * @param query       The current query
 * @param tokenStream document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter).
 *                    If it's used, call reset() first.
 * @param fieldName   The name of the field
 * @param request     The SolrQueryRequest
 */
protected QueryScorer getSpanQueryScorer(Query query, String fieldName, TokenStream tokenStream, SolrQueryRequest request) {
  QueryScorer scorer = new QueryScorer(query,
          request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false) ? fieldName : null) {
    @Override
    protected WeightedSpanTermExtractor newTermExtractor(String defaultField) {
      return new CustomSpanTermExtractor(defaultField);
    }
  };
  scorer.setExpandMultiTermQuery(request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM, true));

  boolean defaultPayloads = true;//overwritten below
  try {
    // It'd be nice to know if payloads are on the tokenStream but the presence of the attribute isn't a good
    // indicator.
    final Terms terms = request.getSearcher().getSlowAtomicReader().terms(fieldName);
    if (terms != null) {
      defaultPayloads = terms.hasPayloads();
    }
  } catch (IOException e) {
    log.error("Couldn't check for existence of payloads", e);
  }
  scorer.setUsePayloads(request.getParams().getFieldBool(fieldName, HighlightParams.PAYLOADS, defaultPayloads));
  return scorer;
}
 
Example 2
Source Project: Elasticsearch   Source File: CustomQueryScorer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected WeightedSpanTermExtractor newTermExtractor(String defaultField) {
    return defaultField == null ? new CustomWeightedSpanTermExtractor()
            : new CustomWeightedSpanTermExtractor(defaultField);
}
 
Example 3
Source Project: lucene-solr   Source File: HighlightCustomQueryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected WeightedSpanTermExtractor newTermExtractor(String defaultField) {
  return defaultField == null ? new MyWeightedSpanTermExtractor()
      : new MyWeightedSpanTermExtractor(defaultField);
}