From d019fb8555b759838f4c1c9ad823e000bcc2b6cc Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Fri, 24 Jun 2022 21:15:41 +0100 Subject: [PATCH] Internal table support for oneOf --- .../src/api/controllers/row/internalSearch.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/server/src/api/controllers/row/internalSearch.js b/packages/server/src/api/controllers/row/internalSearch.js index 5f1dc25faa..23cbdb4bec 100644 --- a/packages/server/src/api/controllers/row/internalSearch.js +++ b/packages/server/src/api/controllers/row/internalSearch.js @@ -17,6 +17,7 @@ class QueryBuilder { notEqual: {}, empty: {}, notEmpty: {}, + oneOf: {}, ...base, } this.limit = 50 @@ -112,6 +113,11 @@ class QueryBuilder { return this } + addOneOf(key, value) { + this.query.oneOf[key] = value + return this + } + /** * Preprocesses a value before going into a lucene search. * Transforms strings to lowercase and wraps strings and bools in quotes. @@ -220,6 +226,28 @@ class QueryBuilder { if (this.query.notEmpty) { build(this.query.notEmpty, key => `${key}:["" TO *]`) } + if (this.query.oneOf) { + build(this.query.oneOf, (key, value) => { + if (!Array.isArray(value)) { + if (typeof value === "string") { + value = value.replace(/(\s)*,(\s)*/g, ",").split(",") + } else { + return "" + } + } + const preprocess = item => { + return builder.preprocess(item, { + escape: true, + lowercase: true, + }) + } + let orStatement = `"${preprocess(value[0])}"` + for (let i = 1; i < value.length; i++) { + orStatement += ` OR "${preprocess(value[i])}"` + } + return `${key}:(${orStatement})` + }) + } return query }