FireWire Posted August 18, 2021 Share Posted August 18, 2021 Hey all. I have a search feature built into our website but it won't match a whole word containing a character, in my situation the % character. When I look for "50%" it brings up results with 50 in it, but does not match pages with 50%. I've tried with several selectors including *=, **=, ~=, and attempted an advanced search with #=+50%, but no dice. I've also tried with and without sanitizers including $sanitizer->selectorValue(); Any insights? Thanks! Link to comment Share on other sites More sharing options...
Robin S Posted August 18, 2021 Share Posted August 18, 2021 If the search phrase is coming from user input you'll need to sanitise it through $sanitizer->selectorValue or else there are a range of search phrases that will break your search and cause an error. But "%" is filtered out by $sanitizer->selectorValue by default, because it is a character that is used in a selector operators, e.g. "%=", "%$=", etc. So if it's important that "%" be allowed you'll need to add it in the whitelist option, but bear in mind that this will possibly allow some search phrases that could break the search or return incorrect results. Not sure how likely that is in practice. The basic operators that appear to work with % in the search phrase are *= and %=. The %= operator allows partial word matches so it depends what you want. If you want to match multiple words in any order you'll probably want use an approach where you explode to individual words then build up a selector string. 2 Link to comment Share on other sites More sharing options...
FireWire Posted August 19, 2021 Author Share Posted August 19, 2021 @Robin S Appreciate the help! I was also thinking about a possible conflict between the selector and the value. Will work with your ideas. Cheers! 1 Link to comment Share on other sites More sharing options...
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