lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r889622 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/search/
Date Fri, 11 Dec 2009 13:55:15 GMT
Author: uschindler
Date: Fri Dec 11 13:55:14 2009
New Revision: 889622

URL: http://svn.apache.org/viewvc?rev=889622&view=rev
Log:
LUCENE-2123: Remove the deprec ScoreTerm in FuzzyQuery, javadocs, better test for the PQ overflow

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyTermEnum.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestFuzzyQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=889622&r1=889621&r2=889622&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Dec 11 13:55:14 2009
@@ -8,6 +8,10 @@
   class is no longer used by Lucene.  (Gunnar Wagenknecht via Mike
   McCandless)
 
+* LUCENE-2123: Removed the protected inner class ScoreTerm from
+  FuzzyQuery. The class was never intended to be public.
+  (Uwe Schindler, Mike McCandless)
+
 Changes in runtime behavior
 
 API Changes

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=889622&r1=889621&r2=889622&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyQuery.java Fri Dec 11 13:55:14
2009
@@ -126,29 +126,6 @@
   public Term getTerm() {
     return term;
   }
-  
-  /**
-   * @deprecated This class was used in previous FuzzyQuery implementations, but is now replaced
by
-   * a new rewrite mode {@link MultiTermQuery#TOP_TERMS_SCORING_BOOLEAN_REWRITE}.
-   */
-  @Deprecated
-  protected static class ScoreTerm implements Comparable<ScoreTerm> {
-    public Term term;
-    public float score;
-    
-    public ScoreTerm(Term term, float score){
-      this.term = term;
-      this.score = score;
-    }
-    
-    public int compareTo(ScoreTerm other) {
-      if (this.score == other.score)
-        return this.term.compareTo(other.term);
-      else
-        // inverse ordering!!!
-        return Float.compare(other.score, this.score);
-    }
-  }
     
   @Override
   public String toString(String field) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyTermEnum.java?rev=889622&r1=889621&r2=889622&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyTermEnum.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FuzzyTermEnum.java Fri Dec 11 13:55:14
2009
@@ -157,7 +157,7 @@
    * based on how similar the Term is compared to a target term.  It returns
    * exactly 0.0f when
    * <pre>
-   *    editDistance &lt; maximumEditDistance</pre>
+   *    editDistance &gt; maximumEditDistance</pre>
    * Otherwise it returns:
    * <pre>
    *    1 - (editDistance / length)</pre>

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestFuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestFuzzyQuery.java?rev=889622&r1=889621&r2=889622&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestFuzzyQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestFuzzyQuery.java Fri Dec 11 13:55:14
2009
@@ -17,8 +17,7 @@
  * limitations under the License.
  */
 
-import java.util.Set;
-import java.util.HashSet;
+import java.util.List;
 import java.util.Arrays;
 import java.io.IOException;
 
@@ -80,18 +79,30 @@
     hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(1, hits.length);
     
+    // test scoring
+    query = new FuzzyQuery(new Term("field", "bbbbb"), FuzzyQuery.defaultMinSimilarity, 0);
  
+    hits = searcher.search(query, null, 1000).scoreDocs;
+    assertEquals("3 documents should match", 3, hits.length);
+    List<String> order = Arrays.asList("bbbbb","abbbb","aabbb");
+    for (int i = 0; i < hits.length; i++) {
+      final String term = searcher.doc(hits[i].doc).get("field");
+      //System.out.println(hits[i].score);
+      assertEquals(order.get(i), term);
+    }
+
     // test BooleanQuery.maxClauseCount
     int savedClauseCount = BooleanQuery.getMaxClauseCount();
     try {
       BooleanQuery.setMaxClauseCount(2);
-      // This query would normally return 3 documents, because 3 terms match:
-      query = new FuzzyQuery(new Term("field", "aaaab"), FuzzyQuery.defaultMinSimilarity,
3);   
+      // This query would normally return 3 documents, because 3 terms match (see above):
+      query = new FuzzyQuery(new Term("field", "bbbbb"), FuzzyQuery.defaultMinSimilarity,
0);   
       hits = searcher.search(query, null, 1000).scoreDocs;
       assertEquals("only 2 documents should match", 2, hits.length);
-      Set<String> possibleTerms = new HashSet<String>(Arrays.asList("aaaaa","aaaab"));
+      order = Arrays.asList("bbbbb","abbbb");
       for (int i = 0; i < hits.length; i++) {
         final String term = searcher.doc(hits[i].doc).get("field");
-        assertTrue("term '" + term + "' should not appear in results", possibleTerms.contains(term));
+        //System.out.println(hits[i].score);
+        assertEquals(order.get(i), term);
       }
     } finally {
       BooleanQuery.setMaxClauseCount(savedClauseCount);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java?rev=889622&r1=889621&r2=889622&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java Fri Dec 11
13:55:14 2009
@@ -31,6 +31,9 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Locale;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
 import java.text.Collator;
 
 
@@ -88,6 +91,40 @@
     searcher.close();
   }
 
+  /** This test should not be here, but it tests the fuzzy query rewrite mode (TOP_TERMS_SCORING_BOOLEAN_REWRITE)
+   * with constant score and checks, that only the lower end of terms is put into the range
*/
+  public void testTopTermsRewrite() throws Exception {
+    initializeIndex(new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"});
+
+    IndexSearcher searcher = new IndexSearcher(dir, true);
+    TermRangeQuery query = new TermRangeQuery("content", "B", "J", true, true);
+    checkBooleanTerms(searcher, query, "B", "C", "D", "E", "F", "G", "H", "I", "J");
+    
+    final int savedClauseCount = BooleanQuery.getMaxClauseCount();
+    try {
+      BooleanQuery.setMaxClauseCount(3);
+      checkBooleanTerms(searcher, query, "B", "C", "D");
+    } finally {
+      BooleanQuery.setMaxClauseCount(savedClauseCount);
+    }
+    searcher.close();
+  }
+  
+  private void checkBooleanTerms(Searcher searcher, TermRangeQuery query, String... terms)
throws IOException {
+    query.setRewriteMethod(MultiTermQuery.TOP_TERMS_SCORING_BOOLEAN_REWRITE);
+    final BooleanQuery bq = (BooleanQuery) searcher.rewrite(query);
+    final Set<String> allowedTerms = new HashSet<String>(Arrays.asList(terms));
+    assertEquals(allowedTerms.size(), bq.clauses().size());
+    for (BooleanClause c : bq.clauses()) {
+      assertTrue(c.getQuery() instanceof TermQuery);
+      final TermQuery tq = (TermQuery) c.getQuery();
+      final String term = tq.getTerm().text();
+      assertTrue("invalid term: "+ term, allowedTerms.contains(term));
+      allowedTerms.remove(term); // remove to fail on double terms
+    }
+    assertEquals(0, allowedTerms.size());
+  }
+
   public void testEqualsHashcode() {
     Query query = new TermRangeQuery("content", "A", "C", true, true);
     



Mime
View raw message