Search in HeroThemes products is powered by the WordPress search. The WordPress search functionality is straightforward, matching title and content of posts (including pages and articles).
This is performed against the database using the like operator, which offers simplicity in implementation and resources, but limited flexibility and effectiveness.
WordPress does have a concept of relevance, and this is how content is matched:
- Full sentence matches in post titles.
- All search terms in post titles.
- Any search terms in post titles.
- Full sentence matches in post content.
The biggest drawback of the inbuilt search is the expectation of the user. Search engines have set a new bar for user search experience, they are fast, contextual and intuitive.
Limitations of the WordPress search functionality
WordPress is great for simple search and with keyword searching, it works great for most circumstances. It doesn’t work well with Natural Language and Interrogation type searches.
The search is case insensitive, will strip certain words but not any punctuation (see later section).
WordPress does not include any settings to control how the search works, which helps ensure consistency of results, so other techniques must be considered for effective search.
Here are some of the things the in-built search does not do:
Search with alternative spellings or mis-spellings
The search term “cancelation” will not match an article titled “Flight Cancellation Information”, even though these are acceptable alternative spellings.
The workaround is to ensure the content contains alternative spellings or for simple words a spelling is used that also is contained in the shorter search term, eg an article titled “buttons” will match both “buttons” and “button” as a search term.
If someone searches for “Installing on Website” both those words need to be in the article and it will not match an article titled “Install on Website”.
WordPress has no notion that the user wants the Website Installation Guide and does not process the search query in the same way a search engine would.
Two things to note:-
- “install on website” as a search term would match an article titled “installing on website”, for the reasons discussed above.
- “on” is a stop word and would be ignored by WordPress for search, see below.
An article titled “How to install on website” would match a search for “install on website” but not “install on website?”. Punctuation is not ignored by WordPress.
Additional mechanisms for stripping punctuation, including full stops, apostrophes and question marks may be required.
Shortcodes, Attachments and other content
Because WordPress only searches post titles and content as it’s stored in the database it does not search any deeper than this – rendered content such as shortcodes, article attachments and linked documentation is not returned in search results.
This is also true of all post meta, including comments.
Taxonomies (Categories and Tags)
WordPress does not search taxonomies such as the inbuilt categories and tags.
As an exception to this, HeroTheme’s KnowAll theme and standalone Heroic Knowledge Base plugin include a search extension that will return articles tagged with the search term or are in an article category matching the search term. This works on literal words and phrases.
For most articles, the most straight forward way to ensure these are returned for a particular search term is to add the term as a tag to the article. Article tags are useful for organizing content.
WordPress does not apply any weighting other than the relevance criteria discussed at the top of this article.
Posts with titles that have exact search term(s) matches will be prioritized over posts that include the terms in the content.
These are words that are stripped out and removed by WordPress search, so are ignored. For example, an article titled “search in WordPress” would match a search for “search with WordPress”.
WordPress includes a couple of standard stopwords such as on, in, was etc. and can be altered with the wp_search_stopwords filter.
The default stopwords depend on the language of the site, here are the ones for English for WordPress 5.2:-
about, an, are, as, at, be, by, com, for, from, how, in, is, it, of, on, or, that, the, this, to, was, what, when, where, who, will, with, www
If you want to go beyond the inbuilt WordPress search functionality, it’s possible to do this with customizations.
SearchWP is the recommended plugin for advanced search control and augmentation. This plugin seeks to overcome all the limitations listed above.
SearchWP includes options for:
- Partial (Fuzzy) matching
- Search word replacement
- Did you mean? corrections