AAD Web Team Posted May 13, 2021 Posted May 13, 2021 I was trying to use the advanced text search (#=) operator in a selector, and I couldn’t work out why my search for the text: +cat dog wasn’t working properly (the plus sign was being ignored), while a search for: dog +cat works fine. Also, prefixing words with minus always worked fine. Phrase searching with double-quotes wasn’t working, but it was fine with parenthesis. After a while I realised this was due to the $sanitizer->selectorValue() function I was using on the query string before using it in the selector. The following things are true: $sanitizer->selectorValue('+cat dog') === 'cat dog'; // Discards the leading plus sign, search doesn't work as expected. $sanitizer->selectorValue('dog +cat') === '"dog +cat"'; // Keeps the plus sign and puts double-quotes around the string. $sanitizer->selectorValue('-cat dog') === '"-cat dog"'; // Keeps the minus sign and puts double-quotes around the string. $sanitizer->selectorValue('dog -cat') === 'dog -cat'; // Keeps the minus sign, no double-quotes. $sanitizer->selectorValue('"jet black cat"') === '"jet black cat"'; // Keeps double-quotes; phrase searching doesn't work. $sanitizer->selectorValue('jet "black cat"') === 'jet black cat'; // Discards double-quotes; phrase searching doesn't work. $sanitizer->selectorValue('jet (black cat)') === 'jet (black cat)'; // Phrase searching works. These effects seem confusing. Is it something that needs to be fixed in ProcessWire, or is there a different way I should be using to sanitise the query string? The documentation recommends surrounding the query text with double-quotes but this doesn’t help with these examples. We’re using ProcessWire 3.0.164.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now