Merge pull request #821 from payloadcms/fix/#806

fix: #806, allow partial word matches using 'like' operator
This commit is contained in:
James Mikrut
2022-07-25 14:07:39 -07:00
committed by GitHub
2 changed files with 18 additions and 2 deletions

View File

@@ -98,7 +98,7 @@ export const sanitizeQueryValue = (schemaType: SchemaType, path: string, operato
if (operator === 'like' && typeof formattedValue === 'string') {
const words = formattedValue.split(' ');
const regex = words.reduce((pattern, word, i) => {
return `${pattern}(?=.*\\b${word}\\b)${i + 1 === words.length ? '.+' : ''}`;
return `${pattern}(?=.*\\b${word}.*\\b)${i + 1 === words.length ? '.+' : ''}`;
}, '');
formattedValue = { $regex: new RegExp(regex), $options: 'i' };