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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1459537 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2013-03-21 21:31:19 +00:00
parent ba7fabb680
commit 7584c40c7a
3 changed files with 69 additions and 9 deletions

View File

@ -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
----------------------

View File

@ -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);

View File

@ -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'"
);
}
}