mirror of https://github.com/apache/lucene.git
SOLR-2996: treat un-fielded * as *:*
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1451906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
89c7a3a6eb
commit
73a0270ad8
|
@ -257,6 +257,11 @@ Other Changes
|
|||
* SOLR-4458: Sort directions (asc, desc) are now case insensitive
|
||||
(Shawn Heisey via hossman)
|
||||
|
||||
* SOLR-2996: A bare * without a field specification is treated as *:*
|
||||
by the lucene and edismax query paesers.
|
||||
(hossman, Jan Høydahl, Alan Woodward, yonik)
|
||||
|
||||
|
||||
================== 4.1.0 ==================
|
||||
|
||||
Versions of Major Components
|
||||
|
|
|
@ -179,11 +179,20 @@ public abstract class SolrQueryParserBase {
|
|||
return this.defaultField;
|
||||
}
|
||||
|
||||
protected String explicitField;
|
||||
/** Handles the default field if null is passed */
|
||||
public String getField(String fieldName) {
|
||||
explicitField = fieldName;
|
||||
return fieldName != null ? fieldName : this.defaultField;
|
||||
}
|
||||
|
||||
/** For a fielded query, returns the actual field specified (i.e. null if default is being used)
|
||||
* myfield:A or myfield:(A B C) will both return "myfield"
|
||||
*/
|
||||
public String getExplicitField() {
|
||||
return explicitField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setAutoGeneratePhraseQueries(boolean)
|
||||
*/
|
||||
|
@ -725,7 +734,6 @@ public abstract class SolrQueryParserBase {
|
|||
Query handleBareTokenQuery(String qfield, Token term, Token fuzzySlop, boolean prefix, boolean wildcard, boolean fuzzy, boolean regexp) throws SyntaxError {
|
||||
Query q;
|
||||
|
||||
String termImage=discardEscapeChar(term.image);
|
||||
if (wildcard) {
|
||||
q = getWildcardQuery(qfield, term.image);
|
||||
} else if (prefix) {
|
||||
|
@ -744,8 +752,10 @@ public abstract class SolrQueryParserBase {
|
|||
} else if (fms >= 1.0f && fms != (int) fms) {
|
||||
throw new SyntaxError("Fractional edit distances are not allowed!");
|
||||
}
|
||||
String termImage=discardEscapeChar(term.image);
|
||||
q = getFuzzyQuery(qfield, termImage, fms);
|
||||
} else {
|
||||
String termImage=discardEscapeChar(term.image);
|
||||
q = getFieldQuery(qfield, termImage, false);
|
||||
}
|
||||
return q;
|
||||
|
@ -970,9 +980,12 @@ public abstract class SolrQueryParserBase {
|
|||
protected Query getWildcardQuery(String field, String termStr) throws SyntaxError {
|
||||
checkNullField(field);
|
||||
// *:* -> MatchAllDocsQuery
|
||||
if ("*".equals(field) && "*".equals(termStr)) {
|
||||
return newMatchAllDocsQuery();
|
||||
if ("*".equals(termStr)) {
|
||||
if ("*".equals(field) || getExplicitField() == null) {
|
||||
return newMatchAllDocsQuery();
|
||||
}
|
||||
}
|
||||
|
||||
FieldType fieldType = schema.getFieldType(field);
|
||||
termStr = analyzeIfMultitermTermText(field, termStr, fieldType);
|
||||
// can we use reversed wildcards in this field?
|
||||
|
|
|
@ -1055,7 +1055,7 @@ public class ExtendedDismaxQParser extends QParser {
|
|||
@Override
|
||||
protected Query getWildcardQuery(String field, String val) throws SyntaxError {
|
||||
if (val.equals("*")) {
|
||||
if (field.equals("*")) {
|
||||
if (field.equals("*") || getExplicitField() == null) {
|
||||
return new MatchAllDocsQuery();
|
||||
} else{
|
||||
return getPrefixQuery(field,"");
|
||||
|
|
|
@ -80,6 +80,23 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
|
|||
assertU(commit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyntax() throws Exception {
|
||||
// a bare * should be treated as *:*
|
||||
assertJQ(req("defType","edismax", "q","*", "df","doesnotexist_s")
|
||||
,"/response/docs/[0]==" // make sure we get something...
|
||||
);
|
||||
assertJQ(req("defType","edismax", "q","doesnotexist_s:*")
|
||||
,"/response/numFound==0" // nothing should be found
|
||||
);
|
||||
assertJQ(req("defType","edismax","q","doesnotexist_s:*")
|
||||
,"/response/numFound==0" // nothing should be found
|
||||
);
|
||||
assertJQ(req("defType","edismax","q","doesnotexist_s:( * * * )")
|
||||
,"/response/numFound==0" // nothing should be found
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testTrailingOperators() throws Exception {
|
||||
// really just test that exceptions aren't thrown by
|
||||
|
|
|
@ -92,4 +92,19 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
|
|||
,"/response/numFound==1"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyntax() throws Exception {
|
||||
// a bare * should be treated as *:*
|
||||
assertJQ(req("q","*", "df","doesnotexist_s")
|
||||
,"/response/docs/[0]==" // make sure we get something...
|
||||
);
|
||||
assertJQ(req("q","doesnotexist_s:*")
|
||||
,"/response/numFound==0" // nothing should be found
|
||||
);
|
||||
assertJQ(req("q","doesnotexist_s:( * * * )")
|
||||
,"/response/numFound==0" // nothing should be found
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue