lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r825998 - in /lucene/java/branches/lucene_2_9: CHANGES.txt src/java/org/apache/lucene/search/FuzzyQuery.java src/test/org/apache/lucene/search/TestFuzzyQuery.java
Date Fri, 16 Oct 2009 16:49:00 GMT
Author: mikemccand
Date: Fri Oct 16 16:48:59 2009
New Revision: 825998

URL: http://svn.apache.org/viewvc?rev=825998&view=rev
Log:
LUCENE-1124: make sure FuzzyQuery always matches the exact term

Modified:
    lucene/java/branches/lucene_2_9/CHANGES.txt
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/FuzzyQuery.java
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFuzzyQuery.java

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=825998&r1=825997&r2=825998&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Fri Oct 16 16:48:59 2009
@@ -9,6 +9,9 @@
    BooleanScorer for scoring), whereby some matching documents fail to
    be collected.  (Fulin Tang via Mike McCandless)
 
+ * LUCENE-1124: Make sure FuzzyQuery always matches the precise term.
+   (stefatwork@gmail.com via Mike McCandless)
+
 ======================= Release 2.9.0 2009-09-23 =======================
 
 Changes in backwards compatibility policy

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=825998&r1=825997&r2=825998&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/FuzzyQuery.java Fri
Oct 16 16:48:59 2009
@@ -126,8 +126,8 @@
   }
   
   public Query rewrite(IndexReader reader) throws IOException {
-    if(!termLongEnough) {  // can't match
-      return new BooleanQuery();
+    if(!termLongEnough) {  // can only match if it's exact
+      return new TermQuery(term);
     }
 
     FilteredTermEnum enumerator = getEnum(reader);

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFuzzyQuery.java?rev=825998&r1=825997&r2=825998&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFuzzyQuery.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestFuzzyQuery.java
Fri Oct 16 16:48:59 2009
@@ -19,13 +19,18 @@
 
 import java.io.IOException;
 
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.queryParser.QueryParser;
 
 /**
  * Tests {@link FuzzyQuery}.
@@ -281,6 +286,43 @@
     assertEquals(0, hits.length);
   }
   
+  public void testGiga() throws Exception {
+
+    StandardAnalyzer analyzer = new StandardAnalyzer();
+
+    Directory index = new MockRAMDirectory();
+    IndexWriter w = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
+
+    addDoc("Lucene in Action", w);
+    addDoc("Lucene for Dummies", w);
+
+    //addDoc("Giga", w);
+    addDoc("Giga byte", w);
+
+    addDoc("ManagingGigabytesManagingGigabyte", w);
+    addDoc("ManagingGigabytesManagingGigabytes", w);
+
+    addDoc("The Art of Computer Science", w);
+    addDoc("J. K. Rowling", w);
+    addDoc("JK Rowling", w);
+    addDoc("Joanne K Roling", w);
+    addDoc("Bruce Willis", w);
+    addDoc("Willis bruce", w);
+    addDoc("Brute willis", w);
+    addDoc("B. willis", w);
+    IndexReader r = w.getReader();
+    w.close();
+
+    Query q = new QueryParser("field", analyzer).parse( "giga~0.9" );
+
+    // 3. search
+    IndexSearcher searcher = new IndexSearcher(r);
+    ScoreDoc[] hits = searcher.search(q, 10).scoreDocs;
+    assertEquals(1, hits.length);
+    assertEquals("Giga byte", searcher.doc(hits[0].doc).get("field"));
+    r.close();
+  }
+
   private void addDoc(String text, IndexWriter writer) throws IOException {
     Document doc = new Document();
     doc.add(new Field("field", text, Field.Store.YES, Field.Index.ANALYZED));



Mime
View raw message