From 165c8dd12962cfc23e695d9f055cf1d549c8e1d2 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 12 Sep 2022 09:07:25 +0100 Subject: [PATCH] Copy backend implementation for removing key numbering to ensure consistent behaviour --- packages/frontend-core/src/utils/lucene.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/utils/lucene.js b/packages/frontend-core/src/utils/lucene.js index 21f00e4942..a1b9594684 100644 --- a/packages/frontend-core/src/utils/lucene.js +++ b/packages/frontend-core/src/utils/lucene.js @@ -83,11 +83,13 @@ const cleanupQuery = query => { /** * Removes a numeric prefix on field names designed to give fields uniqueness */ -const removeFieldPrefix = field => { - if (field && typeof field === "string" && field.includes(":")) { - return field.split(":")[1] +const removeKeyNumbering = key => { + if (typeof key === "string" && key.match(/\d[0-9]*:/g) != null) { + const parts = key.split(":") + parts.shift() + return parts.join(":") } else { - return field + return key } } @@ -205,7 +207,7 @@ export const runLuceneQuery = (docs, query) => { const filters = Object.entries(query[type] || {}) for (let i = 0; i < filters.length; i++) { const [key, testValue] = filters[i] - const docValue = Helpers.deepGet(doc, removeFieldPrefix(key)) + const docValue = Helpers.deepGet(doc, removeKeyNumbering(key)) if (failFn(docValue, testValue)) { return false }