lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r294924 - in /lucene/java/trunk/src: java/org/apache/lucene/queryParser/MultiFieldQueryParser.java test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java
Date Tue, 04 Oct 2005 21:30:44 GMT
Author: dnaber
Date: Tue Oct  4 14:30:37 2005
New Revision: 294924

URL: http://svn.apache.org/viewcvs?rev=294924&view=rev
Log:
don't let MultiFieldQueryParser create empty clauses for stopwords

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=294924&r1=294923&r2=294924&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
Oct  4 14:30:37 2005
@@ -76,6 +76,8 @@
           clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
         }
       }
+      if (clauses.size() == 0)  // happens for stopwords
+        return null;
       return getBooleanQuery(clauses, true);
     }
     return super.getFieldQuery(field, queryText);

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=294924&r1=294923&r2=294924&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 Oct  4 14:30:37 2005
@@ -24,7 +24,14 @@
 import org.apache.lucene.analysis.Token;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
 
 /**
  * Tests QueryParser.
@@ -181,6 +188,25 @@
     assertEquals("f1:[a TO c] f2:[a TO c] f3:[a TO c]", q.toString());
   }
 
+  public void testStopWordSearching() throws Exception {
+    Analyzer analyzer = new StandardAnalyzer();
+    Directory ramDir = new RAMDirectory();
+    IndexWriter iw =  new IndexWriter(ramDir, analyzer, true);
+    Document doc = new Document();
+    doc.add(new Field("body", "blah the footest blah", Field.Store.NO, Field.Index.TOKENIZED));
+    iw.addDocument(doc);
+    iw.close();
+    
+    MultiFieldQueryParser mfqp = 
+      new MultiFieldQueryParser(new String[] {"body"}, analyzer);
+    mfqp.setDefaultOperator(QueryParser.Operator.AND);
+    Query q = mfqp.parse("the footest");
+    IndexSearcher is = new IndexSearcher(ramDir);
+    Hits hits = is.search(q);
+    assertEquals(1, hits.length());
+    is.close();
+  }
+  
   /**
    * Return empty tokens for field "f1".
    */



Mime
View raw message