lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dor...@apache.org
Subject svn commit: r635839 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
Date Tue, 11 Mar 2008 08:06:56 GMT
Author: doronc
Date: Tue Mar 11 01:06:54 2008
New Revision: 635839

URL: http://svn.apache.org/viewvc?rev=635839&view=rev
Log:
LUCENE-1213: MultiFieldQueryParser ignored slop for single field phrases.

Modified:
    lucene/java/trunk/CHANGES.txt
    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/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=635839&r1=635838&r2=635839&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Mar 11 01:06:54 2008
@@ -67,6 +67,9 @@
     scorer.next(). (Eks Dev, Michael Busch)
 
  3. LUCENE-1182: Added scorePayload to SimilarityDelegator (Andi Vajda via Grant Ingersoll)
+ 
+ 4. LUCENE-1213: MultiFieldQueryParser was ignoring slop in case
+    of a single field phrase. (Trejkaz via Doron Cohen)
 	
 New features
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java?rev=635839&r1=635838&r2=635839&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 Tue
Mar 11 01:06:54 2008
@@ -99,7 +99,7 @@
     if (field == null) {
       Vector clauses = new Vector();
       for (int i = 0; i < fields.length; i++) {
-        Query q = getFieldQuery(fields[i], queryText);
+        Query q = super.getFieldQuery(fields[i], queryText);
         if (q != null) {
           //If the user passes a map of boosts
           if (boosts != null) {
@@ -109,12 +109,7 @@
               q.setBoost(boost.floatValue());
             }
           }
-          if (q instanceof PhraseQuery) {
-            ((PhraseQuery) q).setSlop(slop);
-          }
-          if (q instanceof MultiPhraseQuery) {
-            ((MultiPhraseQuery) q).setSlop(slop);
-          }
+          applySlop(q,slop);
           clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
         }
       }
@@ -122,7 +117,17 @@
         return null;
       return getBooleanQuery(clauses, true);
     }
-    return super.getFieldQuery(field, queryText);
+    Query q = super.getFieldQuery(field, queryText);
+    applySlop(q,slop);
+    return q;
+  }
+
+  private void applySlop(Query q, int slop) {
+    if (q instanceof PhraseQuery) {
+      ((PhraseQuery) q).setSlop(slop);
+    } else if (q instanceof MultiPhraseQuery) {
+      ((MultiPhraseQuery) q).setSlop(slop);
+    }
   }
   
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java?rev=635839&r1=635838&r2=635839&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
Tue Mar 11 01:06:54 2008
@@ -113,6 +113,10 @@
     q = mfqp.parse("\"foo bar\"~4");
     assertEquals("b:\"foo bar\"~4 t:\"foo bar\"~4", q.toString());
 
+    // LUCENE-1213: MultiFieldQueryParser was ignoring slop when phrase had a field.
+    q = mfqp.parse("b:\"foo bar\"~4"); 
+    assertEquals("b:\"foo bar\"~4", q.toString());
+
     // make sure that terms which have a field are not touched:
     q = mfqp.parse("one f:two");
     assertEquals("(b:one t:one) f:two", q.toString());



Mime
View raw message