From 3490996c5afb710f61b680ec27880a78897d1840 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 4 Oct 2022 16:28:29 +0100 Subject: [PATCH] Add unit test and fix --- .../src/api/controllers/row/internalSearch.js | 6 ++++-- .../api/routes/tests/internalSearch.spec.js | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/row/internalSearch.js b/packages/server/src/api/controllers/row/internalSearch.js index 7345ec3965..051a55aa9f 100644 --- a/packages/server/src/api/controllers/row/internalSearch.js +++ b/packages/server/src/api/controllers/row/internalSearch.js @@ -145,7 +145,7 @@ class QueryBuilder { * @param options The preprocess options * @returns {string|*} */ - preprocess(value, { escape, lowercase, wrap } = {}) { + preprocess(value, { escape, lowercase, wrap, type } = {}) { const hasVersion = !!this.version // Determine if type needs wrapped const originalType = typeof value @@ -159,7 +159,7 @@ class QueryBuilder { } // Wrap in quotes - if (originalType === "string" && !isNaN(value) && !escape) { + if (originalType === "string" && !isNaN(value) && !type) { value = `"${value}"` } else if (hasVersion && wrap) { value = originalType === "number" ? value : `"${value}"` @@ -256,6 +256,7 @@ class QueryBuilder { value = builder.preprocess(value, { escape: true, lowercase: true, + type: "string", }) return `${key}:${value}*` }) @@ -284,6 +285,7 @@ class QueryBuilder { value = builder.preprocess(value, { escape: true, lowercase: true, + type: "fuzzy", }) return `${key}:${value}~` }) diff --git a/packages/server/src/api/routes/tests/internalSearch.spec.js b/packages/server/src/api/routes/tests/internalSearch.spec.js index 3b478eda17..8b821ce741 100644 --- a/packages/server/src/api/routes/tests/internalSearch.spec.js +++ b/packages/server/src/api/routes/tests/internalSearch.spec.js @@ -173,4 +173,24 @@ describe("internal search", () => { }, PARAMS) checkLucene(response, `*:* AND NOT column:(a AND b AND c)`, PARAMS) }) + + it("test equal without version query", async () => { + PARAMS.version = null + const response = await search.paginatedSearch({ + equal: { + "column": "1", + } + }, PARAMS) + + const query = response.rows[0].query + const json = JSON.parse(query) + if (PARAMS.sort) { + expect(json.sort).toBe(`${PARAMS.sort}<${PARAMS.sortType}>`) + } + if (PARAMS.bookmark) { + expect(json.bookmark).toBe(PARAMS.bookmark) + } + expect(json.include_docs).toBe(true) + expect(json.q).toBe(`(*:* AND column:"1") AND tableId:${PARAMS.tableId}`) + }) }) \ No newline at end of file