You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/05/07 17:06:28 UTC

[GitHub] [lucene-solr] madrob commented on a change in pull request #1496: Bugfix for FuzzyQuery false negative when prefix length == search term length

madrob commented on a change in pull request #1496:
URL: https://github.com/apache/lucene-solr/pull/1496#discussion_r421656988



##########
File path: lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
##########
@@ -99,7 +103,24 @@ public FuzzyQuery(Term term, int maxEdits, int prefixLength, int maxExpansions,
     this.prefixLength = prefixLength;
     this.transpositions = transpositions;
     this.maxExpansions = maxExpansions;
-    setRewriteMethod(new MultiTermQuery.TopTermsBlendedFreqScoringRewrite(maxExpansions));
+    if (term.text().length() == prefixLength) {
+      setRewriteAsPrefixedQuery();
+    } else {
+      setRewriteMethod(new MultiTermQuery.TopTermsBlendedFreqScoringRewrite(maxExpansions));
+    }
+  }
+
+  private void setRewriteAsPrefixedQuery() {

Review comment:
       Can we refactor this into a static inner class?

##########
File path: lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
##########
@@ -225,6 +225,39 @@ public void testFuzziness() throws Exception {
     directory.close();
   }
   
+  public void testPrefixLengthEqualStringLength() throws Exception {
+    Directory directory = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
+    addDoc("b*a", writer);

Review comment:
       Can you add a test case with multi-byte strings as well?

##########
File path: lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
##########
@@ -99,7 +103,24 @@ public FuzzyQuery(Term term, int maxEdits, int prefixLength, int maxExpansions,
     this.prefixLength = prefixLength;
     this.transpositions = transpositions;
     this.maxExpansions = maxExpansions;
-    setRewriteMethod(new MultiTermQuery.TopTermsBlendedFreqScoringRewrite(maxExpansions));
+    if (term.text().length() == prefixLength) {

Review comment:
       I think the problem is that we're checking this in `getTermsEnum` and potentially returning a `SingleTermsEnum`. Checking it here and modifying rewriteMethod feels inconsistent.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org