Sanitise search input on instant search
-
How do I prevent searches being carried out on Algolia for non-coherent terms such as “cfi</a><li><a class=page-numbers href=”
It’s costing me a fortune as I have a commercial subscription with Algolia and searches like this are about 60% of the searches. I suspect there is an issue with the theme however no errors are thrown so really difficult to stop the cause and thought I would explore an alternative solution.
I asked AI and they suggested I use the following code:
const whitelist = /^[a-zA-Z0-9\s]+$/; const search = instantsearch({ ... searchFunction(helper) { helper.setQueryHook((query, search) => { if (!whitelist.test(query)) { return 'Invalid search terms'; } return search(query); }); helper.search(); } });
I’m not great with javascript so don’t know if this would work or where to put it.
Thanks,
Renners.
The page I need help with: [log in to see the link]
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Sanitise search input on instant search’ is closed to new replies.