Skip to content

Commit 481c040

Browse files
committed
WIP for wildcard search improvements
1 parent f1c3b93 commit 481c040

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

server/src/main/java/access/api/FullSearchQueryParser.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import org.springframework.util.StringUtils;
55

66
import java.util.List;
7+
import java.util.Set;
78
import java.util.stream.Collectors;
89
import java.util.stream.Stream;
910

1011
public 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
}

server/src/test/java/access/api/FullSearchQueryParserTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void parseEmpty() {
2828
assertThrows(InvalidInputException.class, () -> FullSearchQueryParser.parse(null));
2929
assertThrows(InvalidInputException.class, () -> FullSearchQueryParser.parse(""));
3030
assertThrows(InvalidInputException.class, () -> FullSearchQueryParser.parse(" "));
31+
assertThrows(InvalidInputException.class, () -> FullSearchQueryParser.parse("no no no"));
3132
}
3233

3334
}

0 commit comments

Comments
 (0)