fix: implement the same word boundary search as the like query (#1038)

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Wesley
2022-09-01 19:03:21 +02:00
committed by GitHub
parent 32a4e8e9b9
commit c3a0bd8625
7 changed files with 76 additions and 14 deletions

View File

@@ -0,0 +1,7 @@
export default (input: string): RegExp => {
const words = input.split(' ');
const regex = words.reduce((pattern, word, i) => {
return `${pattern}(?=.*\\b${word}.*\\b)${i + 1 === words.length ? '.+' : ''}`;
}, '');
return new RegExp(regex, 'i');
};