lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r219965 - in /lucene/java/trunk/src: java/org/apache/lucene/queryParser/MultiFieldQueryParser.java test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
Date Wed, 20 Jul 2005 19:11:44 GMT
Author: dnaber
Date: Wed Jul 20 12:11:43 2005
New Revision: 219965

URL: http://svn.apache.org/viewcvs?rev=219965&view=rev
Log:
fix parsing of sloppy phrase queries and wildcard queries

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
    lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java?rev=219965&r1=219964&r2=219965&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java Wed
Jul 20 12:11:43 2005
@@ -21,6 +21,8 @@
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.MultiPhraseQuery;
+import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 
 /**
@@ -59,19 +61,31 @@
     this.fields = fields;
   }
   
-  protected Query getFieldQuery(String field, String queryText) throws ParseException {
+  protected Query getFieldQuery(String field, String queryText, int slop) throws ParseException
{
     if (field == null) {
       Vector clauses = new Vector();
       for (int i = 0; i < fields.length; i++) {
         Query q = super.getFieldQuery(fields[i], queryText);
-        if (q != null)
+        if (q != null) {
+          if (q instanceof PhraseQuery) {
+            ((PhraseQuery) q).setSlop(slop);
+          }
+          if (q instanceof MultiPhraseQuery) {
+            ((MultiPhraseQuery) q).setSlop(slop);
+          }
           clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
+        }
       }
       return getBooleanQuery(clauses, true);
     }
     return super.getFieldQuery(field, queryText);
   }
   
+
+  protected Query getFieldQuery(String field, String queryText) throws ParseException {
+    return getFieldQuery(field, queryText, 0);
+  }
+  
   /**
    * @deprecated use {@link #getFieldQuery(String, String)}
    */
@@ -113,6 +127,18 @@
     return super.getPrefixQuery(field, termStr);
   }
 
+  protected Query getWildcardQuery(String field, String termStr) throws ParseException {
+    if (field == null) {
+      Vector clauses = new Vector();
+      for (int i = 0; i < fields.length; i++) {
+        clauses.add(new BooleanClause(super.getWildcardQuery(fields[i], termStr),
+            BooleanClause.Occur.SHOULD));
+      }
+      return getBooleanQuery(clauses, true);
+    }
+    return super.getWildcardQuery(field, termStr);
+  }
+  
   /** @throws ParseException
    * @deprecated use {@link #getRangeQuery(String, String, String, boolean)}
   */

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java?rev=219965&r1=219964&r2=219965&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
Wed Jul 20 12:11:43 2005
@@ -63,11 +63,17 @@
     q = mfqp.parse("[a TO c] two");
     assertEquals("(b:[a TO c] t:[a TO c]) (b:two t:two)", q.toString());
 
+    q = mfqp.parse("w?ldcard");
+    assertEquals("b:w?ldcard t:w?ldcard", q.toString());
+
     q = mfqp.parse("\"foo bar\"");
     assertEquals("b:\"foo bar\" t:\"foo bar\"", q.toString());
 
     q = mfqp.parse("\"aa bb cc\" \"dd ee\"");
     assertEquals("(b:\"aa bb cc\" t:\"aa bb cc\") (b:\"dd ee\" t:\"dd ee\")", q.toString());
+
+    q = mfqp.parse("\"foo bar\"~4");
+    assertEquals("b:\"foo bar\"~4 t:\"foo bar\"~4", q.toString());
 
     // make sure that terms which have a field are not touched:
     q = mfqp.parse("one f:two");



Mime
View raw message