@@ -573,6 +573,8 @@ fn correct_query_helper(
573
573
) -> CorrectedQuery {
574
574
let query_words: Vec < & str > = query. query . split_whitespace ( ) . collect ( ) ;
575
575
let mut corrections = HashMap :: new ( ) ;
576
+ let mut new_quote_words = Vec :: new ( ) ;
577
+
576
578
let excluded_words: HashSet < _ > = options
577
579
. disable_on_word
578
580
. clone ( )
@@ -608,7 +610,10 @@ fn correct_query_helper(
608
610
continue ;
609
611
}
610
612
611
- if !tree. find ( word. to_string ( ) , 0 ) . is_empty ( ) {
613
+ if options. auto_require_non_english_words . unwrap_or ( true )
614
+ && !tree. find ( word. to_string ( ) , 0 ) . is_empty ( )
615
+ {
616
+ new_quote_words. push ( word) ;
612
617
query. quote_words = match query. quote_words {
613
618
Some ( mut existing_words) => {
614
619
existing_words. push ( word. to_string ( ) ) ;
@@ -659,16 +664,22 @@ fn correct_query_helper(
659
664
}
660
665
}
661
666
662
- if corrections. is_empty ( ) {
667
+ if corrections. is_empty ( ) && new_quote_words . is_empty ( ) {
663
668
CorrectedQuery {
664
669
query : Some ( query) ,
665
670
corrected : false ,
666
671
}
667
672
} else {
668
673
let mut corrected_query = query. query . clone ( ) ;
674
+
669
675
for ( original, correction) in corrections {
670
676
corrected_query = corrected_query. replace ( original, & correction) ;
671
677
}
678
+
679
+ for word in new_quote_words {
680
+ corrected_query = corrected_query. replace ( word, & format ! ( "\" {}\" " , word) ) ;
681
+ }
682
+
672
683
query. query = corrected_query;
673
684
CorrectedQuery {
674
685
query : Some ( query) ,
0 commit comments