Copy backend implementation for removing key numbering to ensure consistent behaviour

This commit is contained in:
Andrew Kingston 2022-09-12 09:07:25 +01:00
parent cc3f4c1221
commit 899aea9d00
1 changed files with 7 additions and 5 deletions

View File

@ -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
}