mirror of
https://github.com/apache/lucene.git
synced 2025-03-09 01:59:27 +00:00
SOLR-529 - Better error messages from SolrQueryParser when field isn't specified and there is no defaultSearchField in schema.xml
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@646092 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7adcd21ce1
commit
6042bdbad0
@ -323,6 +323,10 @@ Bug Fixes
|
|||||||
|
|
||||||
20. SOLR-535: Fixed typo (Tokenzied -> Tokenized) in schema.jsp (Thomas Peuss via billa)
|
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
|
Other Changes
|
||||||
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
|
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
|
build scripts to make two jars: apache-solr-1.3.jar and
|
||||||
|
@ -22,6 +22,7 @@ import org.apache.lucene.queryParser.ParseException;
|
|||||||
import org.apache.lucene.queryParser.QueryParser;
|
import org.apache.lucene.queryParser.QueryParser;
|
||||||
import org.apache.lucene.search.ConstantScoreRangeQuery;
|
import org.apache.lucene.search.ConstantScoreRangeQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.schema.FieldType;
|
import org.apache.solr.schema.FieldType;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ import org.apache.solr.schema.IndexSchema;
|
|||||||
public class SolrQueryParser extends QueryParser {
|
public class SolrQueryParser extends QueryParser {
|
||||||
protected final IndexSchema schema;
|
protected final IndexSchema schema;
|
||||||
protected final QParser parser;
|
protected final QParser parser;
|
||||||
|
protected final String defaultField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a SolrQueryParser using the schema to understand the
|
* Constructs a SolrQueryParser using the schema to understand the
|
||||||
@ -66,6 +68,7 @@ public class SolrQueryParser extends QueryParser {
|
|||||||
super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer());
|
super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer());
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
this.parser = null;
|
this.parser = null;
|
||||||
|
this.defaultField = defaultField;
|
||||||
setLowercaseExpandedTerms(false);
|
setLowercaseExpandedTerms(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,11 +76,20 @@ public class SolrQueryParser extends QueryParser {
|
|||||||
super(defaultField, parser.getReq().getSchema().getQueryAnalyzer());
|
super(defaultField, parser.getReq().getSchema().getQueryAnalyzer());
|
||||||
this.schema = parser.getReq().getSchema();
|
this.schema = parser.getReq().getSchema();
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
|
this.defaultField = defaultField;
|
||||||
setLowercaseExpandedTerms(false);
|
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 {
|
protected Query getFieldQuery(String field, String queryText) throws ParseException {
|
||||||
|
checkNullField(field);
|
||||||
// intercept magic field name of "_" to use as a hook for our
|
// intercept magic field name of "_" to use as a hook for our
|
||||||
// own functions.
|
// own functions.
|
||||||
if (field.charAt(0) == '_') {
|
if (field.charAt(0) == '_') {
|
||||||
@ -98,6 +110,7 @@ public class SolrQueryParser extends QueryParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
|
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
|
||||||
|
checkNullField(field);
|
||||||
FieldType ft = schema.getFieldType(field);
|
FieldType ft = schema.getFieldType(field);
|
||||||
return new ConstantScoreRangeQuery(
|
return new ConstantScoreRangeQuery(
|
||||||
field,
|
field,
|
||||||
@ -107,6 +120,7 @@ public class SolrQueryParser extends QueryParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
|
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
|
||||||
|
checkNullField(field);
|
||||||
if (getLowercaseExpandedTerms()) {
|
if (getLowercaseExpandedTerms()) {
|
||||||
termStr = termStr.toLowerCase();
|
termStr = termStr.toLowerCase();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user