Skip to content

Commit

Permalink
Merge pull request #90 from abes-esr/test
Browse files Browse the repository at this point in the history
correction des bugs liés aux booléens OR et NOT et aux dates entre crochets
  • Loading branch information
julg authored May 31, 2024
2 parents 0f40162 + 73184c7 commit a06277a
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SearchQueryBuilder {
private FacetProps facetProps;

private Query buildQuery(String chaine) {
chaine = chaine.trim();
chaine = replaceAndOutsideQuotes(chaine);
chaine = replaceSpacesOutsideQuotes(chaine);

Expand Down Expand Up @@ -106,18 +107,41 @@ 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);

if (c == '"') {
insideQuotes = !insideQuotes;
result.append(c);
} else if (c == ' ' && !insideQuotes) {
result.append(" AND ");
} else if (c == '[') {
insideBrackets = true;
result.append(c);
} else if (c == ']') {
insideBrackets = false;
result.append(c);
}
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 (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 {
result.append(c);
}
} else {
result.append(c);

}

}

return result.toString();
Expand Down

0 comments on commit a06277a

Please # to comment.