Better site search and filters
Last updated
WordPress’s own search is basic. It does not understand plurals, cannot fix typos, and ranks a page that mentions a word once the same as a page all about it.
The Search module builds its own index (a list of every page’s words, kept ready for fast searching) on the site’s own database. It gives visitors live results as they type, corrects misspellings, searches WooCommerce products by SKU, and adds filters for archives and the shop. It also logs what visitors search for, including searches that found nothing.
Switching Search on
Open the site page in MaintainHQ and choose Content, then Search. Press "Install and switch on Search" (or "Switch on Search"). The index starts building straight away.
Until the first index is built, or if the index cannot be read, WordPress’s own search keeps answering, so search never stops working.
The screen has four tabs: Overview, Searches, Settings and Filters. In WordPress, the same screens are under Tools, Search.
How the search works
- It indexes titles, excerpts, content, categories and tags, the custom fields you choose, and WooCommerce products with their SKUs, including variations.
- Partial words and plurals match, so "shoe" finds "shoes". SKUs match exactly or by their start.
- Misspelt searches are corrected from the site’s own words, and visitors see "Showing results for ...".
- If no page has every word, pages with some of them are shown.
- Live results appear under every search box as visitors type. It is one small script with no other dependencies, and it works with the keyboard.
Only the search results page on the front of the site is changed. The WordPress admin, other queries and the REST API are left alone.
The index and rebuilding
The Overview tab shows how many published pages, posts (and products) are in the index. The index stays up to date by itself as pages, products, categories and custom fields change.
Press "Rebuild the index" after changing settings, or when the screen says settings or terms have changed since the index was built. A rebuild runs in small batches that carry on by themselves, so it never times out on big sites. You can leave the page; searches keep working from the old index meanwhile. A progress bar shows how far it has got.
Use "Try a search" to see what a visitor would get. It shows corrections, whether it fell back to pages with some of the words, and the number of results.
Settings
| Switch | What it does |
|---|---|
| Use this search on the search results page | Turns the new search on for visitors. |
| Show live results under search boxes as visitors type | The as-you-type results. |
| Correct misspelt searches | Spelling correction. |
| Include WooCommerce SKUs and prices | Only shown on shops. |
| Log what visitors search for (no names or IP addresses) | Feeds the Searches tab. |
| Leave search engine bots and monitors out of the log | Keeps the log to real visitors. |
- Search these: tick the content types to search. Tick none to search every public type.
- Custom fields to search: field names, separated by commas.
- Custom fields visitors can filter by: only these can be used in filters. Names starting with _ are private and never allowed.
- Never show these: post or page ids to keep out of results.
- Weighting: how much a match counts in Title, Categories and tags, Excerpt, Custom fields, Content and SKU, from 0 (ignored) to 100.
- Live results to show (1 to 20), Keep the log for (1 to 365 days), and Pages per rebuild batch (10 to 500).
After saving, MaintainHQ tells you if you need to rebuild the index to apply the change to every page.
Adding filters
Filters let visitors narrow a list of posts or products, for example by category, price or date. Add the Filters block to a sidebar, an archive template or the shop, or paste the shortcode [mhq_filters] into a widget.
- Filters can use categories, tags, product categories, custom fields, price and date.
- Each option shows how many results it would give.
- The address changes with the filters, so a filtered page can be bookmarked or shared.
- Custom fields must be listed under Settings, "Custom fields visitors can filter by".
Learning from what visitors search for
The Searches tab shows Top searches and Searches with no results, each with how many times it was searched, the results last time and when it was last searched.
Searches with no results are the most useful list on the screen. Each is something a visitor wanted and did not find: a good candidate for new content, different wording on an existing page, or a redirect.
No names, IP addresses or sessions are kept, bots are left out, and the log keeps at most 5,000 searches for 90 days by default. Press "Clear the log" to empty it.
Switching Search off
Switching Search off gives searching back to WordPress. Removing the data, after typing REMOVE, deletes the search index and search log on the site.
The search log is kept on production when you deploy from staging. The index is not copied: it is rebuilt from the pages it describes.