Jump to content

Searching for text that includes characters.


FireWire
 Share

Recommended Posts

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

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.

2021-08-19_101118.png.57a73ca08282c696f55b92b2220c7fb5.png

2021-08-19_101409.png.2b9190623036451af738a3559c2f99ec.png

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.

2021-08-19_103844.png.37786dd8b163a961a9a2b5b6c5e10a5e.png

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...