mirror of https://github.com/apache/lucene.git
reverting some of Erik's recent changes to the SolrQueryParser constructor and implementing the intent in a new IndexSchema.getSolrQueryParser method
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@510689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bebe033fb5
commit
81fef0c161
|
@ -130,6 +130,13 @@ Changes in runtime behavior
|
|||
listings). Fix JSON output bug for null values. Internal JAVA API:
|
||||
change most uses of NamedList to SimpleOrderedMap. (yonik)
|
||||
|
||||
3. A new method "getSolrQueryParser" has been added to the IndexSchema
|
||||
class for retrieving a new SolrQueryParser instance with all options
|
||||
specified in the schema.xml's <solrQueryParser> block set. The
|
||||
documentation for the SolrQueryParser constructor and it's use of
|
||||
IndexSchema have also been clarified.
|
||||
(Erik Hatcher and hossman)
|
||||
|
||||
Optimizations
|
||||
1. SOLR-114: HashDocSet specific implementations of union() and andNot()
|
||||
for a 20x performance improvement for those set operations, and a new
|
||||
|
|
|
@ -182,7 +182,7 @@ public class DisMaxRequestHandler extends RequestHandlerBase {
|
|||
int qslop = params.getInt(DMP.QS, 0);
|
||||
|
||||
/* a generic parser for parsing regular lucene queries */
|
||||
QueryParser p = new SolrQueryParser(schema, null);
|
||||
QueryParser p = schema.getSolrQueryParser(null);
|
||||
|
||||
/* a parser for dealing with user input, which will convert
|
||||
* things to DisjunctionMaxQueries
|
||||
|
|
|
@ -106,7 +106,7 @@ public class SimpleFacets {
|
|||
* If user doesn't want schema default for facet.query, they should be
|
||||
* explicit.
|
||||
*/
|
||||
SolrQueryParser qp = new SolrQueryParser(searcher.getSchema(),null);
|
||||
SolrQueryParser qp = searcher.getSchema().getSolrQueryParser(null);
|
||||
|
||||
String[] facetQs = params.getParams(SolrParams.FACET_QUERY);
|
||||
if (null != facetQs && 0 != facetQs.length) {
|
||||
|
|
|
@ -23,11 +23,13 @@ import org.apache.lucene.document.Field;
|
|||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.DefaultSimilarity;
|
||||
import org.apache.lucene.search.Similarity;
|
||||
import org.apache.lucene.queryParser.QueryParser;
|
||||
import org.apache.solr.core.SolrException;
|
||||
import org.apache.solr.core.Config;
|
||||
import org.apache.solr.analysis.TokenFilterFactory;
|
||||
import org.apache.solr.analysis.TokenizerChain;
|
||||
import org.apache.solr.analysis.TokenizerFactory;
|
||||
import org.apache.solr.search.SolrQueryParser;
|
||||
import org.apache.solr.util.DOMUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
@ -149,12 +151,33 @@ public final class IndexSchema {
|
|||
private String defaultSearchFieldName=null;
|
||||
private String queryParserDefaultOperator = "OR";
|
||||
|
||||
/** Name of the default search field specified in the schema file */
|
||||
/**
|
||||
* A SolrQueryParser linked to this IndexSchema for field datatype
|
||||
* information, and populated with default options from the
|
||||
* <solrQueryParser> configuration for this IndexSchema.
|
||||
*
|
||||
* @param defaultField if non-null overrides the schema default
|
||||
*/
|
||||
public SolrQueryParser getSolrQueryParser(String defaultField) {
|
||||
SolrQueryParser qp = new SolrQueryParser(this,defaultField);
|
||||
String operator = getQueryParserDefaultOperator();
|
||||
qp.setDefaultOperator("AND".equals(operator) ?
|
||||
QueryParser.Operator.AND : QueryParser.Operator.OR);
|
||||
return qp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the default search field specified in the schema file
|
||||
* @deprecated use getSolrQueryParser().getField()
|
||||
*/
|
||||
public String getDefaultSearchFieldName() {
|
||||
return defaultSearchFieldName;
|
||||
}
|
||||
|
||||
/** default operator ("AND" or "OR") for QueryParser */
|
||||
/**
|
||||
* default operator ("AND" or "OR") for QueryParser
|
||||
* @deprecated use getSolrQueryParser().getDefaultOperator()
|
||||
*/
|
||||
public String getQueryParserDefaultOperator() {
|
||||
return queryParserDefaultOperator;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class QueryParsing {
|
|||
*/
|
||||
public static Query parseQuery(String qs, String defaultField, IndexSchema schema) {
|
||||
try {
|
||||
Query query = new SolrQueryParser(schema, defaultField).parse(qs);
|
||||
Query query = schema.getSolrQueryParser(defaultField).parse(qs);
|
||||
|
||||
if (SolrCore.log.isLoggable(Level.FINEST)) {
|
||||
SolrCore.log.finest("After QueryParser:" + query);
|
||||
|
@ -85,7 +85,7 @@ public class QueryParsing {
|
|||
*/
|
||||
public static Query parseQuery(String qs, String defaultField, SolrParams params, IndexSchema schema) {
|
||||
try {
|
||||
SolrQueryParser parser = new SolrQueryParser(schema, defaultField);
|
||||
SolrQueryParser parser = schema.getSolrQueryParser(defaultField);
|
||||
String opParam = params.get(OP);
|
||||
if (opParam != null) {
|
||||
parser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR);
|
||||
|
|
|
@ -52,16 +52,19 @@ public class SolrQueryParser extends QueryParser {
|
|||
protected final IndexSchema schema;
|
||||
|
||||
/**
|
||||
* Constructs a SolrQueryParser using the schema to understand the
|
||||
* formats and datatypes of each field. Only the defaultSearchField
|
||||
* will be used from the IndexSchema (unless overridden),
|
||||
* <solrQueryParser> will not be used.
|
||||
*
|
||||
* @param schema Used for default search field name if defaultField is null and field information is used for analysis
|
||||
* @param defaultField default field used for unspecified search terms. if null, the schema default field is used
|
||||
* @see IndexSchema.getSolrQueryParser
|
||||
*/
|
||||
public SolrQueryParser(IndexSchema schema, String defaultField) {
|
||||
super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer());
|
||||
this.schema = schema;
|
||||
setLowercaseExpandedTerms(false);
|
||||
String operator = schema.getQueryParserDefaultOperator();
|
||||
setDefaultOperator("AND".equals(operator) ? QueryParser.Operator.AND : QueryParser.Operator.OR);
|
||||
}
|
||||
|
||||
protected Query getFieldQuery(String field, String queryText) throws ParseException {
|
||||
|
|
|
@ -700,6 +700,8 @@ public class SolrPluginUtils {
|
|||
|
||||
public DisjunctionMaxQueryParser(IndexSchema s, String defaultField) {
|
||||
super(s,defaultField);
|
||||
// don't trust that our parent class won't ever change it's default
|
||||
setDefaultOperator(QueryParser.Operator.OR);
|
||||
}
|
||||
public DisjunctionMaxQueryParser(IndexSchema s) {
|
||||
this(s,null);
|
||||
|
|
Loading…
Reference in New Issue