1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Fix fuzzy search internal DB

This commit is contained in:
Mel O'Hagan 2023-04-20 18:14:41 +01:00
parent 68ba2402a0
commit 66a573dcc9
2 changed files with 15 additions and 19 deletions

View file

@ -309,7 +309,7 @@ export class QueryBuilder<T> {
return null
}
if (!Array.isArray(value)) {
return `${key}:/.*${value?.toLowerCase()}.*/`
return `${key}:${value}`
}
let statement = `${builder.preprocess(value[0], { escape: true })}`
for (let i = 1; i < value.length; i++) {
@ -320,6 +320,18 @@ export class QueryBuilder<T> {
return `${key}:(${statement})`
}
const fuzzy = (key: string, value: any) => {
if (!value) {
return null
}
value = builder.preprocess(value, {
escape: true,
lowercase: true,
type: "fuzzy",
})
return `${key}:/.*${value}.*/`
}
const notContains = (key: string, value: any) => {
const allPrefix = allOr ? "*:* AND " : ""
const mode = allOr ? "AND" : undefined
@ -408,17 +420,7 @@ export class QueryBuilder<T> {
})
}
if (this.#query.fuzzy) {
build(this.#query.fuzzy, (key: string, value: any) => {
if (!value) {
return null
}
value = builder.preprocess(value, {
escape: true,
lowercase: true,
type: "fuzzy",
})
return `${key}:${value}~`
})
build(this.#query.fuzzy, fuzzy)
}
if (this.#query.equal) {
build(this.#query.equal, equal)

View file

@ -22,7 +22,6 @@ export const getValidOperatorsForType = (
Op.Empty,
Op.NotEmpty,
Op.In,
Op.Contains,
]
const numOps = [
Op.Equals,
@ -55,13 +54,8 @@ export const getValidOperatorsForType = (
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
}
// Filter out "like" for internal tables
const externalTable = datasource?.tableId?.includes("datasource_plus")
if (datasource?.type === "table" && !externalTable) {
ops = ops.filter(x => x !== Op.Like)
}
// Only allow equal/not equal for _id in SQL tables
const externalTable = datasource?.tableId?.includes("datasource_plus")
if (field === "_id" && externalTable) {
ops = [Op.Equals, Op.NotEquals, Op.In]
}