You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2013/03/02 18:18:43 UTC
svn commit: r1451906 - in /lucene/dev/trunk/solr: ./
core/src/java/org/apache/solr/parser/ core/src/java/org/apache/solr/search/
core/src/test/org/apache/solr/search/
Author: yonik
Date: Sat Mar 2 17:18:43 2013
New Revision: 1451906
URL: http://svn.apache.org/r1451906
Log:
SOLR-2996: treat un-fielded * as *:*
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1451906&r1=1451905&r2=1451906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Sat Mar 2 17:18:43 2013
@@ -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
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java?rev=1451906&r1=1451905&r2=1451906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java Sat Mar 2 17:18:43 2013
@@ -179,11 +179,20 @@ public abstract class SolrQueryParserBas
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 SolrQueryParserBas
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 SolrQueryParserBas
} 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 SolrQueryParserBas
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?
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java?rev=1451906&r1=1451905&r2=1451906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java Sat Mar 2 17:18:43 2013
@@ -1055,7 +1055,7 @@ public class ExtendedDismaxQParser exten
@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,"");
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java?rev=1451906&r1=1451905&r2=1451906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java Sat Mar 2 17:18:43 2013
@@ -80,6 +80,23 @@ public class TestExtendedDismaxParser ex
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
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java?rev=1451906&r1=1451905&r2=1451906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java Sat Mar 2 17:18:43 2013
@@ -92,4 +92,19 @@ public class TestSolrQueryParser extends
,"/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
+ );
+ }
+
}