I'm for making it configurable (somehow)...

Maybe it belongs in solrconfig.xml as an option on the standard
request handler init()... after all, it wouldn't apply to the dismax
handler right (or could it...)?  If we ever got a handler that
accepted XML with explicit optional/required/prohibited, it wouldn't
apply there either.

As far as the default being "AND", one problem besides breaking
existing queries is that the QueryParser with an AND default has less
expressive power than an "OR" default.  This is because there are "+"
and "-" symbols for required and prohibited, but no symbol for
optional.  So you can't currently express "+a -b c"

-Yonik

On 7/20/06, Erik Hatcher <[EMAIL PROTECTED]> wrote:
My application needs the QueryParser (by way of QueryParsing) to be
set to AND mode, not the default of OR.  There isn't currently a
setting to control this.

I've added it locally using the patch below.  Any objections to me
committing this?

I actually feel strongly that the default setting should be AND
instead of OR, but I left it at OR in this patch for backwards
compatibility :)  (but would gladly change it to AND if there is
consensus).

Thanks,
        Erik


Index: src/java/org/apache/solr/schema/IndexSchema.java
===================================================================
--- src/java/org/apache/solr/schema/IndexSchema.java    (revision
423124)
+++ src/java/org/apache/solr/schema/IndexSchema.java    (working copy)
@@ -140,12 +140,18 @@
    public Analyzer getQueryAnalyzer() { return queryAnalyzer; }
    private String defaultSearchFieldName=null;
+  private String queryParserDefaultOperator = "OR";
    /** Name of the default search field specified in the schema file */
    public String getDefaultSearchFieldName() {
      return defaultSearchFieldName;
    }
+  /** default operator ("AND" or "OR") for QueryParser */
+  public String getQueryParserDefaultOperator() {
+    return queryParserDefaultOperator;
+  }
+
    private SchemaField uniqueKeyField;
    /**
@@ -366,6 +372,14 @@
        log.info("default search field is "+defaultSearchFieldName);
      }
+    node = (Node) xpath.evaluate("/schema/queryParserDefaultOperator/
text()", document, XPathConstants.NODE);
+    if (node==null) {
+      log.warning("no query parser default operator specified in
schema.");
+    } else {
+      queryParserDefaultOperator=node.getNodeValue().trim();
+      log.info("query parser default operator is
"+queryParserDefaultOperator);
+    }
+
      node = (Node) xpath.evaluate("/schema/uniqueKey/text()",
document, XPathConstants.NODE);
      if (node==null) {
        log.warning("no uniqueKey specified in schema.");
Index: src/java/org/apache/solr/search/SolrQueryParser.java
===================================================================
--- src/java/org/apache/solr/search/SolrQueryParser.java
(revision 423124)
+++ src/java/org/apache/solr/search/SolrQueryParser.java
(working copy)
@@ -37,6 +37,7 @@
      super(defaultField == null ? schema.getDefaultSearchFieldName
() : defaultField, schema.getQueryAnalyzer());
      this.schema = schema;
      setLowercaseExpandedTerms(false);
+    setDefaultOperator("AND".equals
(schema.getQueryParserDefaultOperator()) ? QueryParser.Operator.AND :
QueryParser.Operator.OR);
    }
    protected Query getFieldQuery(String field, String queryText)
throws ParseException {

Reply via email to