Skip to content

Commit

Permalink
Improve preprocessing: detect -negation, avoid empty terms (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed May 10, 2023
1 parent 7aafd1c commit 3c5d99e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/controllers/nwbib/Lobid.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,13 @@ private static String setUpNwbibspatial(String nwbibspatial) {

private static String preprocess(final String q) {
String result = q.trim();
if (result.isEmpty() || result.matches(".*?([+~]|AND|OR|\\s-|\\*|:).*?")) {
if (result.isEmpty()
|| result.matches(".*?([+~]|AND|OR|\\s-[^\\s]|\\*|:).*?")) {
// if supported query string syntax is used, leave it alone
} else {
// else prepend '+' to all terms for AND search:
result = Arrays.asList(result.split("[\\s-]")).stream().map(x -> "+" + x)
result = Arrays.asList(result.split("[\\s-]")).stream()
.filter(x -> !x.trim().isEmpty()).map(x -> "+" + x)
.collect(Collectors.joining(" "));
}
return result// but escape unsupported query string syntax:
Expand Down

0 comments on commit 3c5d99e

Please sign in to comment.