From 181b3688dabba9e2cba341d4ab53e9de988b27d0 Mon Sep 17 00:00:00 2001 From: gibert Date: Thu, 30 May 2024 14:38:39 +0200 Subject: [PATCH 1/3] [bug THE-1329] : la recherche avec dates ne fonctionnait plus ( = il ne faut pas remplacer les espaces par des AND quand on est entre crochets). --- .../theses/builder/SearchQueryBuilder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java index 23fb60d..a5c8421 100644 --- a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java +++ b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java @@ -106,6 +106,7 @@ private Query buildQuery(String chaine) { private String replaceSpacesOutsideQuotes(String input) { StringBuilder result = new StringBuilder(); boolean insideQuotes = false; + boolean insideBrackets = false; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); @@ -113,7 +114,13 @@ private String replaceSpacesOutsideQuotes(String input) { if (c == '"') { insideQuotes = !insideQuotes; result.append(c); - } else if (c == ' ' && !insideQuotes) { + } else if (c == '[') { + insideBrackets = true; + result.append(c); + } else if (c == ']') { + insideBrackets = false; + result.append(c); + } else if (c == ' ' && !insideQuotes && !insideBrackets) { result.append(" AND "); } else { result.append(c); From 7d80a74d23da5b4198a33bb682ef51f052acb7c1 Mon Sep 17 00:00:00 2001 From: gibert Date: Fri, 31 May 2024 15:01:24 +0200 Subject: [PATCH 2/3] =?UTF-8?q?[bug]=20il=20faut=20=C3=A9chapper=20le=20OR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theses/builder/SearchQueryBuilder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java index a5c8421..97441ca 100644 --- a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java +++ b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java @@ -108,6 +108,7 @@ private String replaceSpacesOutsideQuotes(String input) { boolean insideQuotes = false; boolean insideBrackets = false; + for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); @@ -120,11 +121,22 @@ private String replaceSpacesOutsideQuotes(String input) { } else if (c == ']') { insideBrackets = false; result.append(c); - } else if (c == ' ' && !insideQuotes && !insideBrackets) { - result.append(" AND "); + } + else if (c == ' ') { + if (i + 2 < input.length() && input.charAt(i + 1) == 'O'&& input.charAt(i + 2) == 'R') { + + result.append(" OR "); + i+= 3; + } else if (!insideQuotes && !insideBrackets) { + result.append(" AND "); + } else { + result.append(c); + } } else { result.append(c); + } + } return result.toString(); From 62908e32815bf9910661a4f6f8037631f23aa296 Mon Sep 17 00:00:00 2001 From: gibert Date: Fri, 31 May 2024 16:30:27 +0200 Subject: [PATCH 3/3] =?UTF-8?q?[bug]=20il=20faut=20=C3=A9chapper=20le=20NO?= =?UTF-8?q?T?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theses/builder/SearchQueryBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java index 97441ca..c6c944e 100644 --- a/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java +++ b/src/main/java/fr/abes/thesesapirecherche/theses/builder/SearchQueryBuilder.java @@ -55,6 +55,7 @@ public class SearchQueryBuilder { private FacetProps facetProps; private Query buildQuery(String chaine) { + chaine = chaine.trim(); chaine = replaceAndOutsideQuotes(chaine); chaine = replaceSpacesOutsideQuotes(chaine); @@ -127,6 +128,10 @@ else if (c == ' ') { result.append(" OR "); i+= 3; + } else if (i + 3 < input.length() && input.charAt(i + 1) == 'N' && input.charAt(i + 2) == 'O' && input.charAt(i + 3) == 'T') { + + result.append(" NOT "); + i+= 4; } else if (!insideQuotes && !insideBrackets) { result.append(" AND "); } else {