Add multiselect contains filters to custom query
This commit is contained in:
parent
52408a13f8
commit
3819dd3c4f
|
@ -121,7 +121,11 @@ export const buildLuceneQuery = filter => {
|
||||||
if (type === "boolean") {
|
if (type === "boolean") {
|
||||||
value = `${value}`?.toLowerCase() === "true"
|
value = `${value}`?.toLowerCase() === "true"
|
||||||
}
|
}
|
||||||
if (["contains", "notContains", "containsAny"].includes(operator) && type === "array" && typeof value === "string") {
|
if (
|
||||||
|
["contains", "notContains", "containsAny"].includes(operator) &&
|
||||||
|
type === "array" &&
|
||||||
|
typeof value === "string"
|
||||||
|
) {
|
||||||
value = value.split(",")
|
value = value.split(",")
|
||||||
}
|
}
|
||||||
if (operator.startsWith("range")) {
|
if (operator.startsWith("range")) {
|
||||||
|
@ -240,6 +244,18 @@ export const runLuceneQuery = (docs, query) => {
|
||||||
return !testValue?.includes(docValue)
|
return !testValue?.includes(docValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const containsAny = match("containsAny", (docValue, testValue) => {
|
||||||
|
return !docValue?.includes(...testValue)
|
||||||
|
})
|
||||||
|
|
||||||
|
const contains = match("contains", (docValue, testValue) => {
|
||||||
|
return !testValue?.every(item => docValue?.includes(item))
|
||||||
|
})
|
||||||
|
|
||||||
|
const notContains = match("notContains", (docValue, testValue) => {
|
||||||
|
return testValue?.every(item => docValue?.includes(item))
|
||||||
|
})
|
||||||
|
|
||||||
// Match a document against all criteria
|
// Match a document against all criteria
|
||||||
const docMatch = doc => {
|
const docMatch = doc => {
|
||||||
return (
|
return (
|
||||||
|
@ -250,7 +266,10 @@ export const runLuceneQuery = (docs, query) => {
|
||||||
notEqualMatch(doc) &&
|
notEqualMatch(doc) &&
|
||||||
emptyMatch(doc) &&
|
emptyMatch(doc) &&
|
||||||
notEmptyMatch(doc) &&
|
notEmptyMatch(doc) &&
|
||||||
oneOf(doc)
|
oneOf(doc) &&
|
||||||
|
contains(doc) &&
|
||||||
|
containsAny(doc) &&
|
||||||
|
notContains(doc)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue