Merge pull request #10366 from Budibase/budi-5186-dynamic-filter-contains-option

Dynamic filter contains option
This commit is contained in:
Martin McKeaveney 2023-04-24 09:32:58 +01:00 committed by GitHub
commit 86dc082f57
2 changed files with 15 additions and 18 deletions

View File

@ -243,7 +243,7 @@ export class QueryBuilder<T> {
}
// Escape characters
if (!this.#noEscaping && escape && originalType === "string") {
value = `${value}`.replace(/[ #+\-&|!(){}\]^"~*?:\\]/g, "\\$&")
value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&")
}
// Wrap in quotes
@ -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

@ -54,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]
}