44import org .springframework .util .StringUtils ;
55
66import java .util .List ;
7+ import java .util .Set ;
78import java .util .stream .Collectors ;
89import java .util .stream .Stream ;
910
1011public class FullSearchQueryParser {
1112
1213 //SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD;
13- private static final List <String > stopWords = List .of (
14+ private static final Set <String > stopWords = Set .of (
1415 "a" , "about" , "an" , "are" ,
1516 "as" , "at" , "be" , "by" ,
1617 "com" , "de" , "en" , "for" ,
@@ -19,7 +20,7 @@ public class FullSearchQueryParser {
1920 "on" , "or" , "that" , "the" ,
2021 "this" , "to" , "was" , "what" ,
2122 "when" , "where" , "who" , "will" ,
22- "with" , "und" , "the" , " www"
23+ "with" , "und" , "www"
2324 );
2425
2526 private FullSearchQueryParser () {
@@ -34,6 +35,11 @@ public static String parse(String query) {
3435 .filter (part -> !(part .length () < 3 || stopWords .contains (part .toLowerCase ())))
3536 .map (part -> "+" + part )
3637 .collect (Collectors .joining (" " ));
38+
39+ if (parsedQuery .isEmpty ()) {
40+ throw new InvalidInputException ("Search query contains no usable terms after filtering" );
41+ }
42+
3743 return parsedQuery + "*" ;
3844 }
3945}
0 commit comments