SOLR-3377: edismax fails to correctly parse a fielded query wrapped by parens

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1361091 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-07-13 08:32:57 +00:00
parent e7d1278836
commit 7993e39d38
3 changed files with 31 additions and 4 deletions

View File

@ -80,6 +80,10 @@ Bug Fixes
* SOLR-3610: After reloading a core, indexing would fail on any newly added fields to the schema. (Brent Mills, rmuir)
* SOLR-3377: edismax fails to correctly parse a fielded query wrapped by parens.
This regression was introduced in 3.6. (Bernd Fehling, Jan Høydahl, yonik)
Other Changes
* SOLR-3524: Make discarding punctuation configurable in JapaneseTokenizerFactory.

View File

@ -624,6 +624,7 @@ class ExtendedDismaxQParser extends QParser {
}
String field;
String rawField; // if the clause is +(foo:bar) then rawField=(foo
boolean isPhrase;
boolean hasWhitespace;
boolean hasSpecialSyntax;
@ -667,7 +668,9 @@ class ExtendedDismaxQParser extends QParser {
}
if (clause.field != null) {
disallowUserField = false;
pos += clause.field.length(); // skip the field name
int colon = s.indexOf(':',pos);
clause.rawField = s.substring(pos, colon);
pos += colon - pos; // skip the field name
pos++; // skip the ':'
}
@ -798,6 +801,10 @@ class ExtendedDismaxQParser extends QParser {
// make sure there is space after the colon, but not whitespace
if (colon<=pos || colon+1>=end || Character.isWhitespace(s.charAt(colon+1))) return null;
char ch = s.charAt(p++);
while ((ch=='(' || ch=='+' || ch=='-') && (pos<end)) {
ch = s.charAt(p++);
pos++;
}
if (!Character.isJavaIdentifierPart(ch)) return null;
while (p<colon) {
ch = s.charAt(p++);

View File

@ -52,7 +52,7 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase {
"text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!"));
assertU(adoc("id", "48", "text_sw", "this has gigabyte potential", "foo_i","100"));
assertU(adoc("id", "49", "text_sw", "start the big apple end", "foo_i","-100"));
assertU(adoc("id", "50", "text_sw", "start new big city end"));
assertU(adoc("id", "50", "text_sw", "start new big city end"));
assertU(adoc("id", "51", "store", "12.34,-56.78"));
assertU(adoc("id", "52", "text_sw", "tekna theou klethomen"));
assertU(adoc("id", "53", "text_sw", "nun tekna theou esmen"));
@ -352,6 +352,7 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase {
}
public void testUserFields() {
String allr = "*[count(//doc)=10]";
String oner = "*[count(//doc)=1]";
String nor = "*[count(//doc)=0]";
@ -365,9 +366,24 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase {
assertQ(req("defType","edismax", "q","id:42"),
oner);
assertQ(req("defType","edismax", "uf","*", "q","id:42"),
// SOLR-3377 - parens should be allowed immediately before field name
assertQ(req("defType","edismax", "q","( id:42 )"),
oner);
assertQ(req("defType","edismax", "q","(id:42)"),
oner);
assertQ(req("defType","edismax", "q","(+id:42)"),
oner);
assertQ(req("defType","edismax", "q","+(+id:42)"),
oner);
assertQ(req("defType","edismax", "q","+(+((id:42)))"),
oner);
assertQ(req("defType","edismax", "q","+(+((+id:42)))"),
oner);
assertQ(req("defType","edismax", "q"," +( +( ( +id:42) ) ) "),
oner);
assertQ(req("defType","edismax", "q","(id:(*:*)^200)"),
allr);
assertQ(req("defType","edismax", "uf","id", "q","id:42"),
oner);