If you see anything fishy with this, by all means let me know. This was an odd one... my custom request handler calls QueryParsing.parseQuery(String,String,IndexSchema) and it confused me for a while why our default AND operator was not working. I had implemented this feature, but for a different application that uses the standard request handler which calls QueryParsing.parseQuery (String,String,SolrParams,IndexSchema).

I believe now having SolrQueryParser set the operator based on the schema configuration is much more sensible.

        Erik


On Feb 21, 2007, at 8:00 PM, [EMAIL PROTECTED] wrote:

Author: ehatcher
Date: Wed Feb 21 17:00:23 2007
New Revision: 510334

URL: http://svn.apache.org/viewvc?view=rev&rev=510334
Log:
QueryParsing.parseQuery(String,IndexSchema) and QueryParsing.parseQuery(String,String,IndexSchema) now respects the schema.xml <solrQueryParser defaultOperator="..."/> setting. Before, only QueryParsing.parseQuery(String,String,SolrParams,IndexSchema) respected the schema setting.

SolrQueryParser itself now sets the default operator based on the schema setting, and is overridden with the q.op param when the latter QueryParsing.parseQuery() method is used.


Modified:
lucene/solr/trunk/src/java/org/apache/solr/search/ QueryParsing.java lucene/solr/trunk/src/java/org/apache/solr/search/ SolrQueryParser.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/ QueryParsing.java URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/ apache/solr/search/QueryParsing.java? view=diff&rev=510334&r1=510333&r2=510334 ====================================================================== ======== --- lucene/solr/trunk/src/java/org/apache/solr/search/ QueryParsing.java (original) +++ lucene/solr/trunk/src/java/org/apache/solr/search/ QueryParsing.java Wed Feb 21 17:00:23 2007
@@ -85,10 +85,11 @@
    */
public static Query parseQuery(String qs, String defaultField, SolrParams params, IndexSchema schema) {
     try {
- String opParam = params.get(OP, schema.getQueryParserDefaultOperator()); - QueryParser.Operator defaultOperator = "AND".equals (opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR; SolrQueryParser parser = new SolrQueryParser(schema, defaultField);
-      parser.setDefaultOperator(defaultOperator);
+      String opParam = params.get(OP);
+      if (opParam != null) {
+ parser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR);
+      }
       Query query = parser.parse(qs);

       if (SolrCore.log.isLoggable(Level.FINEST)) {

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? view=diff&rev=510334&r1=510333&r2=510334 ====================================================================== ======== --- lucene/solr/trunk/src/java/org/apache/solr/search/ SolrQueryParser.java (original) +++ lucene/solr/trunk/src/java/org/apache/solr/search/ SolrQueryParser.java Wed Feb 21 17:00:23 2007
@@ -60,6 +60,8 @@
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 {


Reply via email to