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:
us...@infra.apache.org



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

Reply via email to