Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4625: fix boosts and phrase slops on sub parsers

Yonik Seeley7584c40c7a30
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f9ed0cedf88..c48227a4e15 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -209,6 +209,10 @@ Bug Fixes
* SOLR-4608: Update Log replay and PeerSync replay should use the default
processor chain to update the index. (Ludovic Boutros, yonik)
+* SOLR-4625: The solr (lucene syntax) query parser lost top-level boost
+ values and top-level phrase slops on queries produced by nested
+ sub-parsers. (yonik)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
index 4738af38997..f92febc0c5d 100644
--- a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
+++ b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
@@ -573,11 +573,17 @@ public abstract class SolrQueryParserBase {
throws SyntaxError {
Query query = getFieldQuery(field, queryText, true);
- if (query instanceof PhraseQuery) {
- ((PhraseQuery) query).setSlop(slop);
- }
- if (query instanceof MultiPhraseQuery) {
- ((MultiPhraseQuery) query).setSlop(slop);
+ // only set slop of the phrase query was a result of this parser
+ // and not a sub-parser.
+ if (subQParser == null) {
+
+ if (query instanceof PhraseQuery) {
+ ((PhraseQuery) query).setSlop(slop);
+ }
+ if (query instanceof MultiPhraseQuery) {
+ ((MultiPhraseQuery) query).setSlop(slop);
+ }
+
}
return query;
@@ -779,7 +785,7 @@ public abstract class SolrQueryParserBase {
float boostVal = Float.parseFloat(boost.image);
// avoid boosting null queries, such as those caused by stop words
if (q != null) {
- q.setBoost(boostVal);
+ q.setBoost(q.getBoost() * boostVal);
}
}
return q;
@@ -932,7 +938,8 @@ public abstract class SolrQueryParserBase {
}
- // called from parser
+ private QParser subQParser = null;
+
protected Query getFieldQuery(String field, String queryText, boolean quoted) throws SyntaxError {
checkNullField(field);
// intercept magic field name of "_" to use as a hook for our
@@ -940,8 +947,8 @@ public abstract class SolrQueryParserBase {
if (field.charAt(0) == '_' && parser != null) {
MagicFieldName magic = MagicFieldName.get(field);
if (null != magic) {
- QParser nested = parser.subQuery(queryText, magic.subParser);
- return nested.getQuery();
+ subQParser = parser.subQuery(queryText, magic.subParser);
+ return subQParser.getQuery();
}
}
SchemaField sf = schema.getFieldOrNull(field);
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
index a8864d3a515..114b1c83b80 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
@@ -112,4 +112,53 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
);
}
+ @Test
+ public void testNestedQueryModifiers() throws Exception {
+ // One previous error was that for nested queries, outer parameters overrode nested parameters.
+ // For example _query_:"\"a b\"~2" was parsed as "a b"
+
+ String subqq="_query_:\"{!v=$qq}\"";
+
+ assertJQ(req("q","_query_:\"\\\"how brown\\\"~2\""
+ , "debug","query"
+ )
+ ,"/response/docs/[0]/id=='1'"
+ );
+
+ assertJQ(req("q",subqq, "qq","\"how brown\"~2"
+ , "debug","query"
+ )
+ ,"/response/docs/[0]/id=='1'"
+ );
+
+ // Should explicit slop override? It currently does not, but that could be considered a bug.
+ assertJQ(req("q",subqq+"~1", "qq","\"how brown\"~2"
+ , "debug","query"
+ )
+ ,"/response/docs/[0]/id=='1'"
+ );
+
+ // Should explicit slop override? It currently does not, but that could be considered a bug.
+ assertJQ(req("q"," {!v=$qq}~1", "qq","\"how brown\"~2"
+ , "debug","query"
+ )
+ ,"/response/docs/[0]/id=='1'"
+ );
+
+ // boost should multiply
+ assertJQ(req("fq","id:1", "fl","id,score", "q", subqq+"^3", "qq","text:x^2"
+ , "debug","query"
+ )
+ ,"/debug/parsedquery=='text:x^6.0'"
+ );
+
+ // boost should multiply
+ assertJQ(req("fq","id:1", "fl","id,score", "q", " {!v=$qq}^3", "qq","text:x^2"
+ , "debug","query"
+ )
+ ,"/debug/parsedquery=='text:x^6.0'"
+ );
+
+ }
+
}