Java Code Examples for org.apache.lucene.search.highlight.QueryScorer#setExpandMultiTermQuery()
The following examples show how to use
org.apache.lucene.search.highlight.QueryScorer#setExpandMultiTermQuery() .
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: DefaultSolrHighlighter.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 File: LumongoSegment.java From lumongo with Apache License 2.0 | 6 votes |
private List<LumongoHighlighter> getHighlighterList(List<HighlightRequest> highlightRequests, Query q) { if (highlightRequests.isEmpty()) { return Collections.emptyList(); } List<LumongoHighlighter> highlighterList = new ArrayList<>(); for (HighlightRequest highlight : highlightRequests) { QueryScorer queryScorer = new QueryScorer(q, highlight.getField()); queryScorer.setExpandMultiTermQuery(true); Fragmenter fragmenter = new SimpleSpanFragmenter(queryScorer, highlight.getFragmentLength()); SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter(highlight.getPreTag(), highlight.getPostTag()); LumongoHighlighter highlighter = new LumongoHighlighter(simpleHTMLFormatter, queryScorer, highlight); highlighter.setTextFragmenter(fragmenter); highlighterList.add(highlighter); } return highlighterList; }