From 3c5d99e1280845e5bc9a65b04e883761e66deae9 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Wed, 10 May 2023 13:48:22 +0200 Subject: [PATCH] Improve preprocessing: detect `-negation`, avoid empty terms (#614) --- app/controllers/nwbib/Lobid.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/nwbib/Lobid.java b/app/controllers/nwbib/Lobid.java index 291b6f8..a0ab716 100644 --- a/app/controllers/nwbib/Lobid.java +++ b/app/controllers/nwbib/Lobid.java @@ -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: