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: svn commit: r510334 - in /lucene/solr/trunk/src/java/org/apache/solr/search: QueryParsing.java SolrQueryParser.java
Date Thu, 22 Feb 2007 18:58:48 GMT

: Does DisjunctionMaxQueryParser require the operator to be AND?   Does
: it always need to be set one way or the other?  If so, we could just
: override that setting in the constructor, eh?

DisjunctionMaxQueryParser assumes that calling super(schema,defaultField)
will set the schema (for the purposes of field parsing), and the
defaultField, and have no other side affects.

: Sure, the QueryParsing.parseQuery methods could set it, and I'll
: change it if needed, but I want to understand how this breaks
: DisjunctionMaxQueryParser first.  Can q.op be set specifically for
: the DisjunctionMaxQueryParser?

DisjunctionMaxQueryParser uses "mm" to determine how many clauses
should match (so if you want all to be mandatory you set mm=100%) so it
doesn't use q.op or '<solrQueryParser defaultOperator="AND"/>'

with the change you made, someone setting <solrQueryParser
defaultOperator="AND"/> causes DisjunctionMaxQueryParser to treat every
clause as mandatory (ignoringthe mm)

we could make the constructor for DisjunctionMaxQueryParser explicitly
call setDefaultOperator(QueryParser.Operator.OR) ... that's probably wise
anyway, but in general I worry about putting "side effects" in the
constructor for SolrQueryParser that users may not no they need to "unset"
when constructing an instance.  (particulararly if/when we start adding
more options in the <solrQueryParser/> block)


What do you think of this patch (to the current trunk) ? ....


Index: src/java/org/apache/solr/schema/IndexSchema.java
===================================================================
--- src/java/org/apache/solr/schema/IndexSchema.java	(revision 510622)
+++ src/java/org/apache/solr/schema/IndexSchema.java	(working copy)
@@ -23,11 +23,13 @@
 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 @@
   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
+   * &lt;solrQueryParser&gt; 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;
   }
Index: src/java/org/apache/solr/search/SolrQueryParser.java
===================================================================
--- src/java/org/apache/solr/search/SolrQueryParser.java	(revision 510622)
+++ src/java/org/apache/solr/search/SolrQueryParser.java	(working copy)
@@ -52,16 +52,19 @@
   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),
+   * &lt;solrQueryParser&gt; 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 {
Index: src/java/org/apache/solr/search/QueryParsing.java
===================================================================
--- src/java/org/apache/solr/search/QueryParsing.java	(revision 510622)
+++ src/java/org/apache/solr/search/QueryParsing.java	(working copy)
@@ -62,7 +62,7 @@
    */
   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 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);
Index: src/java/org/apache/solr/request/SimpleFacets.java
===================================================================
--- src/java/org/apache/solr/request/SimpleFacets.java	(revision 510622)
+++ src/java/org/apache/solr/request/SimpleFacets.java	(working copy)
@@ -106,7 +106,7 @@
      * 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) {
Index: src/java/org/apache/solr/request/DisMaxRequestHandler.java
===================================================================
--- src/java/org/apache/solr/request/DisMaxRequestHandler.java	(revision 510622)
+++ src/java/org/apache/solr/request/DisMaxRequestHandler.java	(working copy)
@@ -182,7 +182,7 @@
       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
Index: src/java/org/apache/solr/util/SolrPluginUtils.java
===================================================================
--- src/java/org/apache/solr/util/SolrPluginUtils.java	(revision 510622)
+++ src/java/org/apache/solr/util/SolrPluginUtils.java	(working copy)
@@ -700,6 +700,8 @@

     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);

Mime
View raw message