mirror of https://github.com/apache/lucene.git
SOLR-6916: hl.payloads
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1651076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
221cbaad10
commit
1f2d431273
|
@ -214,7 +214,7 @@ New Features
|
|||
* SOLR-6605: Make ShardHandlerFactory maxConnections configurable.
|
||||
(Christine Poerschke via shalin)
|
||||
|
||||
* SOLR-6585: RequestHandlers can optionaly handle sub paths as well (Noble Paul)
|
||||
* SOLR-6585: RequestHandlers can optionally handle sub paths as well (Noble Paul)
|
||||
|
||||
* SOLR-6617: /update/json/docs path will use fully qualified node names by default
|
||||
(Noble Paul)
|
||||
|
@ -288,6 +288,9 @@ New Features
|
|||
|
||||
* SOLR-2035: Add a VelocityResponseWriter $resource tool for locale-specific string lookups.
|
||||
(Erik Hatcher)
|
||||
|
||||
* SOLR-6916: Toggle payload support for the default highlighter via hl.payloads. It's auto
|
||||
enabled when the index has payloads. (David Smiley)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
|
|
@ -240,16 +240,11 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
|||
* @param request The SolrQueryRequest
|
||||
*/
|
||||
private QueryScorer getSpanQueryScorer(Query query, String fieldName, TokenStream tokenStream, SolrQueryRequest request) {
|
||||
boolean reqFieldMatch = request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false);
|
||||
boolean highlightMultiTerm = request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM, true);
|
||||
QueryScorer scorer;
|
||||
if (reqFieldMatch) {
|
||||
scorer = new QueryScorer(query, fieldName);
|
||||
}
|
||||
else {
|
||||
scorer = new QueryScorer(query, null);
|
||||
}
|
||||
scorer.setExpandMultiTermQuery(highlightMultiTerm);
|
||||
QueryScorer scorer = new QueryScorer(query,
|
||||
request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false) ? fieldName : null);
|
||||
scorer.setExpandMultiTermQuery(request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM, true));
|
||||
scorer.setUsePayloads(request.getParams().getFieldBool(fieldName, HighlightParams.PAYLOADS,
|
||||
request.getSearcher().getLeafReader().getFieldInfos().fieldInfo(fieldName).hasPayloads()));
|
||||
return scorer;
|
||||
}
|
||||
|
||||
|
@ -608,7 +603,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
|||
if (summaries.length > 0)
|
||||
docSummaries.add(fieldName, summaries);
|
||||
}
|
||||
// no summeries made, copy text from alternate field
|
||||
// no summaries made, copy text from alternate field
|
||||
if (summaries == null || summaries.length == 0) {
|
||||
alternateField( docSummaries, params, doc, fieldName );
|
||||
}
|
||||
|
|
|
@ -401,6 +401,16 @@
|
|||
</analyzer>
|
||||
</fieldType>
|
||||
|
||||
<fieldType name="payloadDelimited" class="solr.TextField">
|
||||
<analyzer type="index">
|
||||
<tokenizer class="solr.WhitespaceTokenizerFactory" />
|
||||
<filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="integer" />
|
||||
</analyzer>
|
||||
<analyzer type="query">
|
||||
<tokenizer class="solr.WhitespaceTokenizerFactory" />
|
||||
</analyzer>
|
||||
</fieldType>
|
||||
|
||||
</types>
|
||||
|
||||
|
||||
|
@ -536,6 +546,8 @@
|
|||
<field name="lower" type="lowertok" indexed="false" stored="true" multiValued="true" />
|
||||
<field name="_route_" type="string" indexed="true" stored="true" multiValued="false" />
|
||||
|
||||
<field name="payloadDelimited" type="payloadDelimited" />
|
||||
|
||||
<!-- Dynamic field definitions. If a field name is not found, dynamicFields
|
||||
will be used if the name matches any of the patterns.
|
||||
RESTRICTION: the glob-like pattern in the name attribute must have
|
||||
|
|
|
@ -17,17 +17,27 @@
|
|||
|
||||
package org.apache.solr.highlight;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.spans.SpanPayloadCheckQuery;
|
||||
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.params.HighlightParams;
|
||||
import org.apache.solr.handler.component.HighlightComponent;
|
||||
import org.apache.solr.handler.component.ResponseBuilder;
|
||||
import org.apache.solr.handler.component.SearchComponent;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.apache.solr.search.DocSet;
|
||||
import org.apache.solr.util.TestHarness;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -1053,4 +1063,37 @@ public class HighlighterTest extends SolrTestCaseJ4 {
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void payloadFilteringSpanQuery() throws IOException {
|
||||
clearIndex();
|
||||
|
||||
String FIELD_NAME = "payloadDelimited";
|
||||
assertU(adoc("id", "0", FIELD_NAME, "word|7 word|2"));
|
||||
assertU(commit());
|
||||
|
||||
//We search at a lower level than typical Solr tests because there's no QParser for payloads
|
||||
|
||||
//Create query matching this payload
|
||||
Query query = new SpanPayloadCheckQuery(new SpanTermQuery(new Term(FIELD_NAME, "word")),
|
||||
Collections.singleton(new byte[]{0,0,0,7}));//bytes for integer 7
|
||||
|
||||
//invoke highlight component... the hard way
|
||||
final SearchComponent hlComp = h.getCore().getSearchComponent("highlight");
|
||||
SolrQueryRequest req = req("hl", "true", "hl.fl", FIELD_NAME, HighlightParams.USE_PHRASE_HIGHLIGHTER, "true");
|
||||
try {
|
||||
SolrQueryResponse resp = new SolrQueryResponse();
|
||||
ResponseBuilder rb = new ResponseBuilder(req, resp, Collections.singletonList(hlComp));
|
||||
rb.setHighlightQuery(query);
|
||||
rb.setResults(req.getSearcher().getDocListAndSet(query, (DocSet) null, null, 0, 1));
|
||||
//highlight:
|
||||
hlComp.prepare(rb);
|
||||
hlComp.process(rb);
|
||||
//inspect response
|
||||
final String[] snippets = (String[]) resp.getValues().findRecursive("highlighting", "0", FIELD_NAME);
|
||||
assertEquals("<em>word|7</em> word|2", snippets[0]);
|
||||
} finally {
|
||||
req.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public interface HighlightParams {
|
|||
|
||||
public static final String USE_PHRASE_HIGHLIGHTER = HIGHLIGHT+".usePhraseHighlighter";
|
||||
public static final String HIGHLIGHT_MULTI_TERM = HIGHLIGHT+".highlightMultiTerm";
|
||||
public static final String PAYLOADS = HIGHLIGHT+".payloads";
|
||||
|
||||
public static final String MERGE_CONTIGUOUS_FRAGMENTS = HIGHLIGHT + ".mergeContiguous";
|
||||
|
||||
|
|
Loading…
Reference in New Issue