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:
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 ⚠️
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; | |
} |
Which results in a notification that better matches the site design:
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.