Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

correction des bugs liés aux booléens OR et NOT et aux dates entre crochets #90

Merged
merged 6 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading