feat: cyrillic like query support (#1078)
This commit is contained in:
@@ -97,7 +97,7 @@ export const sanitizeQueryValue = (schemaType: SchemaType, path: string, operato
|
||||
}
|
||||
|
||||
if (operator === 'like' && typeof formattedValue === 'string') {
|
||||
const $regex = wordBoundariesRegex(formattedValue)
|
||||
const $regex = wordBoundariesRegex(formattedValue);
|
||||
formattedValue = { $regex };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
export default (input: string): RegExp => {
|
||||
const words = input.split(' ');
|
||||
|
||||
// Regex word boundaries that work for cyrillic characters - https://stackoverflow.com/a/47062016/1717697
|
||||
const wordBoundaryBefore = '(?:(?<=[^\\p{L}\\p{N}])|^)';
|
||||
const wordBoundaryAfter = '(?=[^\\p{L}\\p{N}]|$)';
|
||||
|
||||
const regex = words.reduce((pattern, word, i) => {
|
||||
return `${pattern}(?=.*\\b${word}.*\\b)${i + 1 === words.length ? '.+' : ''}`;
|
||||
return `${pattern}(?=.*${wordBoundaryBefore}${word}.*${wordBoundaryAfter})${i + 1 === words.length ? '.+' : ''}`;
|
||||
}, '');
|
||||
return new RegExp(regex, 'i');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user