From 66a573dcc9208f7d9a54142a89f92df37ee0240e Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 20 Apr 2023 18:14:41 +0100 Subject: [PATCH] Fix fuzzy search internal DB --- packages/backend-core/src/db/lucene.ts | 26 ++++++++++++++------------ packages/shared-core/src/filters.ts | 8 +------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/backend-core/src/db/lucene.ts b/packages/backend-core/src/db/lucene.ts index 63e31dd1eb..f8a9e196dc 100644 --- a/packages/backend-core/src/db/lucene.ts +++ b/packages/backend-core/src/db/lucene.ts @@ -309,7 +309,7 @@ export class QueryBuilder { 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 { 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 { }) } 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) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 85c4cd7f5c..20d79195f1 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -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] }