diff --git a/packages/runtime-common/query.ts b/packages/runtime-common/query.ts index 4b70dca997..e0d0b9087a 100644 --- a/packages/runtime-common/query.ts +++ b/packages/runtime-common/query.ts @@ -420,10 +420,12 @@ function assertRangeFilter( }); } +// This is a helper function to remove brackets from keys in a query object returned by qs.parse. +// For example, qs.parse consumes stringified search query and returns a query object with key '[author.firstName]; we should get 'author.firstName' instead +// Our search index doesn't account for path segments which are wrapped in brackets so we need to remove them. const removeBrackets = (obj: any): any => { if (!obj || typeof obj !== 'object') return obj; - // Handle arrays if (Array.isArray(obj)) { return obj.map((item) => removeBrackets(item)); } @@ -432,14 +434,11 @@ const removeBrackets = (obj: any): any => { // Remove surrounding brackets if they exist const newKey = key.replace(/^\[(.*)\]$/, '$1'); - // Handle arrays in values if (Array.isArray(value)) { acc[newKey] = value.map((item) => removeBrackets(item)); } else if (typeof value === 'object' && value !== null) { - // Recursively removeBrackets nested objects acc[newKey] = removeBrackets(value); } else { - // Handle primitive values acc[newKey] = value; }