Handle managing the search query smarter

This commit is contained in:
Mark Veidemanis 2022-08-03 07:20:30 +01:00
parent 5cc04863ac
commit 8e0385e809
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 8 additions and 2 deletions

View File

@ -8,17 +8,23 @@
var present = true;
if (present == true) {
var toAppend = ` AND ${field}: "${value}"`;
var toRemove = `${field}: "${value}"`;
} else {
var toAppend = ` AND NOT ${field}: "${value}"`;
var toRemove = `NOT ${field}: "${value}"`;
}
if (!queryElement.value.includes(toAppend)) {
if (!queryElement.value.includes(toAppend) && !queryElement.value.includes(toRemove)) {
queryElement.value+=toAppend;
} else {
queryElement.value = queryElement.value.replace(toAppend, "");
queryElement.value = queryElement.value.replaceAll(toAppend, "");
queryElement.value = queryElement.value.replaceAll(toRemove, "");
}
if (field == "src") {
document.getElementById("source").selectedIndex = 0;
}
if (queryElement.value.startsWith(" AND ")) {
queryElement.value = queryElement.value.replace(" AND ", "");
}
htmx.trigger("#search", "click");
}
</script>