SearchWP

Version 4 Documentation

Automatic “Did you mean” (search query corrections)

Note: This documentation is for SearchWP 4
SearchWP 3.x: Automatic “Did you mean” (search query corrections)

A popular feature of some search engines is their ability to automatically apply corrections to search queries when no results are found for the original query.

To enable this functionality in SearchWP, enable the Closest Match option on the General Settings page:

Screnshot of SearchWP General settings

Alternatively this can be enabled with the searchwp\query\output_suggested_search hook.

When this feature is enabled, SearchWP will automatically attempt to correct any searches that provide zero results in addition to outputting a notice above The Loop of your search results:

⚠️ Style (CSS) customization is likely required ⚠️

Screenshot of SearchWP's "Did you mean?" automatic output

The above screenshot outlines the automatic output in Twenty Nineteen, a default WordPress theme. The following CSS can be added to improve its appearance:

Note: (You can add Custom CSS to your site by navigating to Appearance > Customize > Additional CSS in your WordPress Dashboard)

.searchwp-revised-search-notice {
margin: 0 calc(10% + 60px) 1em;
padding: 0.6em;
background: #f7f7f7;
border: 1px solid #e7e7e7;
border-radius: 2px;
}
.searchwp-suggested-revision-query {
font-style: italic;
font-weight: bold;
}
view raw style.css hosted with ❤ by GitHub

Which results in a notification that better matches the site design:

Screenshot of customized styling of SearchWP's "Did you mean?" automatic output

Interoperability with partial matches

When “Did you mean?” functionality is enabled and partial matching is enabled, SearchWP will first attempt to find exact partial matches and utilize partial match functionality.

If no partial matches are found, SearchWP will then utilize its “Did you mean?” functionality, determining the best search correction it can. If no search correction can be determined, SearchWP will show zero results.