Added unit tests for internalSearch
This commit is contained in:
parent
2904b1a5db
commit
3d55b60add
|
@ -184,9 +184,12 @@ class QueryBuilder {
|
|||
}
|
||||
|
||||
const contains = (key, value, mode = "AND") => {
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
if (Array.isArray(value) && value.length === 0) {
|
||||
return null
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return `${key}:${value}`
|
||||
}
|
||||
let statement = `${builder.preprocess(value[0], { escape: true })}`
|
||||
for (let i = 1; i < value.length; i++) {
|
||||
statement += ` ${mode} ${builder.preprocess(value[i], {
|
||||
|
@ -197,7 +200,8 @@ class QueryBuilder {
|
|||
}
|
||||
|
||||
const notContains = (key, value) => {
|
||||
return "*:* AND NOT " + contains(key, value)
|
||||
const allPrefix = allOr === "" ? "*:* AND" : ""
|
||||
return allPrefix + "NOT " + contains(key, value)
|
||||
}
|
||||
|
||||
const containsAny = (key, value) => {
|
||||
|
|
|
@ -129,9 +129,10 @@ describe("internal search", () => {
|
|||
const response = await search.paginatedSearch({
|
||||
contains: {
|
||||
"column": "a",
|
||||
"colArr": [1, 2, 3],
|
||||
},
|
||||
}, PARAMS)
|
||||
checkLucene(response, `*:* AND column:a`, PARAMS)
|
||||
checkLucene(response, `*:* AND column:a AND colArr:(1 AND 2 AND 3)`, PARAMS)
|
||||
})
|
||||
|
||||
it("test multiple of same column", async () => {
|
||||
|
@ -154,4 +155,22 @@ describe("internal search", () => {
|
|||
}, PARAMS)
|
||||
checkLucene(response, `*:* AND 1\\:column:"a"`, PARAMS)
|
||||
})
|
||||
|
||||
it("test containsAny query", async () => {
|
||||
const response = await search.paginatedSearch({
|
||||
containsAny: {
|
||||
"column": ["a", "b", "c"]
|
||||
},
|
||||
}, PARAMS)
|
||||
checkLucene(response, `*:* AND column:(a OR b OR c)`, PARAMS)
|
||||
})
|
||||
|
||||
it("test notContains query", async () => {
|
||||
const response = await search.paginatedSearch({
|
||||
notContains: {
|
||||
"column": ["a", "b", "c"]
|
||||
},
|
||||
}, PARAMS)
|
||||
checkLucene(response, `*:* AND NOT column:(a AND b AND c)`, PARAMS)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue