Fix fuzzy search internal DB
This commit is contained in:
parent
68ba2402a0
commit
66a573dcc9
|
@ -309,7 +309,7 @@ export class QueryBuilder<T> {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
return `${key}:/.*${value?.toLowerCase()}.*/`
|
return `${key}:${value}`
|
||||||
}
|
}
|
||||||
let statement = `${builder.preprocess(value[0], { escape: true })}`
|
let statement = `${builder.preprocess(value[0], { escape: true })}`
|
||||||
for (let i = 1; i < value.length; i++) {
|
for (let i = 1; i < value.length; i++) {
|
||||||
|
@ -320,6 +320,18 @@ export class QueryBuilder<T> {
|
||||||
return `${key}:(${statement})`
|
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 notContains = (key: string, value: any) => {
|
||||||
const allPrefix = allOr ? "*:* AND " : ""
|
const allPrefix = allOr ? "*:* AND " : ""
|
||||||
const mode = allOr ? "AND" : undefined
|
const mode = allOr ? "AND" : undefined
|
||||||
|
@ -408,17 +420,7 @@ export class QueryBuilder<T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (this.#query.fuzzy) {
|
if (this.#query.fuzzy) {
|
||||||
build(this.#query.fuzzy, (key: string, value: any) => {
|
build(this.#query.fuzzy, fuzzy)
|
||||||
if (!value) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
value = builder.preprocess(value, {
|
|
||||||
escape: true,
|
|
||||||
lowercase: true,
|
|
||||||
type: "fuzzy",
|
|
||||||
})
|
|
||||||
return `${key}:${value}~`
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (this.#query.equal) {
|
if (this.#query.equal) {
|
||||||
build(this.#query.equal, equal)
|
build(this.#query.equal, equal)
|
||||||
|
|
|
@ -22,7 +22,6 @@ export const getValidOperatorsForType = (
|
||||||
Op.Empty,
|
Op.Empty,
|
||||||
Op.NotEmpty,
|
Op.NotEmpty,
|
||||||
Op.In,
|
Op.In,
|
||||||
Op.Contains,
|
|
||||||
]
|
]
|
||||||
const numOps = [
|
const numOps = [
|
||||||
Op.Equals,
|
Op.Equals,
|
||||||
|
@ -55,13 +54,8 @@ export const getValidOperatorsForType = (
|
||||||
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
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
|
// Only allow equal/not equal for _id in SQL tables
|
||||||
|
const externalTable = datasource?.tableId?.includes("datasource_plus")
|
||||||
if (field === "_id" && externalTable) {
|
if (field === "_id" && externalTable) {
|
||||||
ops = [Op.Equals, Op.NotEquals, Op.In]
|
ops = [Op.Equals, Op.NotEquals, Op.In]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue