You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2016/12/30 15:57:11 UTC
[35/50] [abbrv] lucene-solr:jira/solr-9854: SOLR-9897: Add
hl.requireFieldMatch=false support when using the UnifiedHighlighter
SOLR-9897: Add hl.requireFieldMatch=false support when using the UnifiedHighlighter
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/20362deb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/20362deb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/20362deb
Branch: refs/heads/jira/solr-9854
Commit: 20362deb7e6814c1922163595e7edeb652d3ce37
Parents: f29d2b5
Author: David Smiley <ds...@apache.org>
Authored: Wed Dec 28 22:57:44 2016 -0500
Committer: David Smiley <ds...@apache.org>
Committed: Wed Dec 28 22:57:44 2016 -0500
----------------------------------------------------------------------
solr/CHANGES.txt | 7 +++++--
.../solr/highlight/UnifiedSolrHighlighter.java | 15 ++++++++++++++-
.../solr/highlight/TestUnifiedSolrHighlighter.java | 10 ++++++++++
.../apache/solr/common/params/HighlightParams.java | 2 +-
4 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/20362deb/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 501527a..852a306 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/20362deb/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java
index c38546e..910fa2b 100644
--- a/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java
+++ b/solr/core/src/java/org/apache/solr/highlight/UnifiedSolrHighlighter.java
@@ -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;
+ }
+ }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/20362deb/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java b/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java
index 95754a4..e2511be 100644
--- a/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java
+++ b/solr/core/src/test/org/apache/solr/highlight/TestUnifiedSolrHighlighter.java
@@ -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");
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/20362deb/solr/solrj/src/java/org/apache/solr/common/params/HighlightParams.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/HighlightParams.java b/solr/solrj/src/java/org/apache/solr/common/params/HighlightParams.java
index fd752bf..917e9f5 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/HighlightParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/HighlightParams.java
@@ -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