lucene-solr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: QueryParser default operator - AND
Date Thu, 20 Jul 2006 21:38:46 GMT

: 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 think by now everyone knows my prediliction for writing custom
RequestHandlers -- but i agree that something like this would be a good
idea as a way to modify the properties of the "default" SolrQueryParser.

my one suggestion would be that we should support schema.xml declarations
for all of the "setable" properties of the Lucene QueryParser...

  <solrQueryParser defaultOperator="AND"
                   fuzzyMinSim="0.5"
                   fuzzyPrefixLength="2"
                   locale="???"
                   lowerCaseExpandTerms="true"
                   phraseSlop="5"   />

...i'm not saying I expect Erik to put in all the code to deal with all of
those now (unless you really want to Erik), just that it would be a good
idea if the config syntax for the default OP left room for them as
children of a larger solrQueryParser config block.



:
: 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 {
:



-Hoss


Mime
View raw message