You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2008/04/08 23:48:51 UTC
svn commit: r646092 - in /lucene/solr/trunk: CHANGES.txt
src/java/org/apache/solr/search/SolrQueryParser.java
Author: hossman
Date: Tue Apr 8 14:48:50 2008
New Revision: 646092
URL: http://svn.apache.org/viewvc?rev=646092&view=rev
Log:
SOLR-529 - Better error messages from SolrQueryParser when field isn't specified and there is no defaultSearchField in schema.xml
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=646092&r1=646091&r2=646092&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Apr 8 14:48:50 2008
@@ -323,6 +323,10 @@
20. SOLR-535: Fixed typo (Tokenzied -> Tokenized) in schema.jsp (Thomas Peuss via billa)
+21. SOLR-529: Better error messages from SolrQueryParser when field isn't
+ specified and there is no defaultSearchField in schema.xml
+ (Lars Kotthoff via hossman)
+
Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and
Modified: lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java?rev=646092&r1=646091&r2=646092&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java Tue Apr 8 14:48:50 2008
@@ -22,6 +22,7 @@
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.ConstantScoreRangeQuery;
import org.apache.lucene.search.Query;
+import org.apache.solr.common.SolrException;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
@@ -51,6 +52,7 @@
public class SolrQueryParser extends QueryParser {
protected final IndexSchema schema;
protected final QParser parser;
+ protected final String defaultField;
/**
* Constructs a SolrQueryParser using the schema to understand the
@@ -66,6 +68,7 @@
super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer());
this.schema = schema;
this.parser = null;
+ this.defaultField = defaultField;
setLowercaseExpandedTerms(false);
}
@@ -73,11 +76,20 @@
super(defaultField, parser.getReq().getSchema().getQueryAnalyzer());
this.schema = parser.getReq().getSchema();
this.parser = parser;
+ this.defaultField = defaultField;
setLowercaseExpandedTerms(false);
}
+ private void checkNullField(String field) throws SolrException {
+ if (field == null && defaultField == null) {
+ throw new SolrException
+ (SolrException.ErrorCode.BAD_REQUEST,
+ "no field name specified in query and no defaultSearchField defined in schema.xml");
+ }
+ }
protected Query getFieldQuery(String field, String queryText) throws ParseException {
+ checkNullField(field);
// intercept magic field name of "_" to use as a hook for our
// own functions.
if (field.charAt(0) == '_') {
@@ -98,6 +110,7 @@
}
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
+ checkNullField(field);
FieldType ft = schema.getFieldType(field);
return new ConstantScoreRangeQuery(
field,
@@ -107,6 +120,7 @@
}
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
+ checkNullField(field);
if (getLowercaseExpandedTerms()) {
termStr = termStr.toLowerCase();
}