From bf4e73674c43be987b4b780da832ceaf1aecbd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Arribas?= Date: Sun, 3 Jul 2022 22:34:11 +0200 Subject: [PATCH] Do AND of filter words for string find --- src/utils/convert-filter.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/convert-filter.ts b/src/utils/convert-filter.ts index 5d52269..51a03d8 100644 --- a/src/utils/convert-filter.ts +++ b/src/utils/convert-filter.ts @@ -16,7 +16,12 @@ export const convertFilter = (filter) => { switch (property.type()) { case 'string': return { - [property.name()]: { $regex: escape(value), $options: 'i' }, + [property.name()]: { $regex: new RegExp( + value + .split(' ') + .map((word) => '(?=.*\\b' + escape(word) + '\\b)') + .join('') + '.+' + ), $options: 'i' }, ...memo, } case 'date':