GET FREE VERSION GET THE PRO VERSION

How To Set Maximal Number Of Words For Search Query

Learn why it is important to set the maximum allowed number of words for a search query and how to do that.

In this article

Why do I need to set the max search words number?

Advanced Woo Search plugin gives you advanced search features like searching via any product fields ( content, taxonomies, attributes, custom fields, etc ), order search results by relevance score, search and display taxonomies, attributes, users.

These all are great features. And in most cases search is very optimized and performed very fast. But there are cases when the search may require significant server resources. First of all, that can happen when a user is using very long search queries ( more than 10 words ), if you enable too many product fields to search in. Or if you have too many products ( it is only one of the criteria, plugin can work fine even with 1 millions of products ).

Some points related to search performance optimization we cover in this article: Performance Options.

Here we will cover only one of it - search query length. As has been said - too many search words for one query can negatively affect the search speed and increase the load on the server.

Also unscrupulous people can deliberately create a lot of long search queries in order to create additional load on your server.

The solution is simple - prohibit search queries from using more than X words. Below we will cover this in detail.

Default behavior for long search queries

By default the plugin already has this feature to limit the number of words for search queries. Default value is set to 6 words for the search query.

If a search query contains more than 6 words - plugin will use only the first 6 and strip all others.

So, for example, user type following search query:

Some very long search query that someone trying to use

So it contains 10 words. With a default of 6 words, the plugin will use only the following words:

Some very long search query that

It's as if the rest of the query wasn't written by the user at all.

How to change max search words number?

But what if you want to change that default number to the maximum number of words allowed? No problem, this can be done right from the plugin settings page.

Open your WordPress admin dashboard, go to Adv. Woo Search -> Performance tab and find Search words number option.

'Search words number' option

'Search words number' option

Just set any other value for this option and save changes. The changes will take effect immediately. The value cannot be less than 1.