mirror of https://github.com/apache/lucene.git
SOLR-9897: Add hl.requireFieldMatch=false support when using the UnifiedHighlighter
This commit is contained in:
parent
f29d2b5668
commit
20362deb7e
|
@ -109,8 +109,8 @@ Upgrade Notes
|
|||
|
||||
* SOLR-9708: You are encouraged to try out the UnifiedHighlighter by setting hl.method=unified and report feedback. It
|
||||
might become the default in 7.0. It's more efficient/faster than the other highlighters, especially compared to the
|
||||
original Highlighter. That said, some options aren't supported yet, notably hl.fragsize and
|
||||
hl.requireFieldMatch=false. It will get more features in time, especially with your input. See HighlightParams.java
|
||||
original Highlighter. That said, some options aren't supported yet, notably hl.fragsize.
|
||||
It will get more features in time, especially with your input. See HighlightParams.java
|
||||
for a listing of highlight parameters annotated with which highlighters use them.
|
||||
hl.useFastVectorHighlighter is now considered deprecated in lieu of hl.method=fastVector.
|
||||
|
||||
|
@ -199,6 +199,9 @@ New Features
|
|||
|
||||
* SOLR-9880: Add Ganglia, Graphite and SLF4J metrics reporters. (ab)
|
||||
|
||||
* SOLR-9897: Add hl.requireFieldMatch toggle support when using the UnifiedHighlighter. Defaults to false like the
|
||||
other highlighters that support this. (David Smiley)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
|
@ -221,9 +222,10 @@ public class UnifiedSolrHighlighter extends SolrHighlighter implements PluginInf
|
|||
* From {@link #getHighlighter(org.apache.solr.request.SolrQueryRequest)}.
|
||||
*/
|
||||
protected static class SolrExtendedUnifiedHighlighter extends UnifiedHighlighter {
|
||||
protected final static Predicate<String> NOT_REQUIRED_FIELD_MATCH_PREDICATE = s -> true;
|
||||
protected final SolrParams params;
|
||||
protected final IndexSchema schema;
|
||||
|
||||
protected final IndexSchema schema;
|
||||
protected final RTimerTree loadFieldValuesTimer;
|
||||
|
||||
public SolrExtendedUnifiedHighlighter(SolrQueryRequest req) {
|
||||
|
@ -360,6 +362,17 @@ public class UnifiedSolrHighlighter extends SolrHighlighter implements PluginInf
|
|||
return params.getFieldBool(field, HighlightParams.USE_PHRASE_HIGHLIGHTER, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getFieldMatcher(String field) {
|
||||
// TODO define hl.queryFieldPattern as a more advanced alternative to hl.requireFieldMatch.
|
||||
|
||||
// note that the UH & PH at Lucene level default to effectively "true"
|
||||
if (params.getFieldBool(field, HighlightParams.FIELD_MATCH, false)) {
|
||||
return field::equals; // requireFieldMatch
|
||||
} else {
|
||||
return NOT_REQUIRED_FIELD_MATCH_PREDICATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -225,5 +225,15 @@ public class TestUnifiedSolrHighlighter extends SolrTestCaseJ4 {
|
|||
req("q", "text:document", "sort", "id asc", "hl", "true", "hl.encoder", "html"),
|
||||
"//lst[@name='highlighting']/lst[@name='103']/arr[@name='text']/str='<em>Document</em> one has a first <i>sentence</i>.'");
|
||||
}
|
||||
|
||||
public void testRequireFieldMatch() {
|
||||
// We highlight on field text3 (hl.fl), but our query only references the "text" field. Nonetheless, the query word
|
||||
// "document" is found in all fields here.
|
||||
|
||||
assertQ(req("q", "id:101", "hl", "true", "hl.q", "text:document", "hl.fl", "text3"), //hl.requireFieldMatch is false by default
|
||||
"count(//lst[@name='highlighting']/lst[@name='101']/arr[@name='text3']/*)=1");
|
||||
assertQ(req("q", "id:101", "hl", "true", "hl.q", "text:document", "hl.fl", "text3", "hl.requireFieldMatch", "true"),
|
||||
"count(//lst[@name='highlighting']/lst[@name='101']/arr[@name='text3']/*)=0");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public interface HighlightParams {
|
|||
// query interpretation
|
||||
public static final String Q = HIGHLIGHT+".q"; // all
|
||||
public static final String QPARSER = HIGHLIGHT+".qparser"; // all
|
||||
public static final String FIELD_MATCH = HIGHLIGHT+".requireFieldMatch"; // OH, FVH
|
||||
public static final String FIELD_MATCH = HIGHLIGHT+".requireFieldMatch"; // OH, FVH, UH
|
||||
public static final String USE_PHRASE_HIGHLIGHTER = HIGHLIGHT+".usePhraseHighlighter"; // OH, FVH, UH
|
||||
public static final String HIGHLIGHT_MULTI_TERM = HIGHLIGHT+".highlightMultiTerm"; // all
|
||||
|
||||
|
|
Loading…
Reference in New Issue