Feature: Did you mean....?
Everyone knows the "did you mean ...?" functionality big search engines offer.
Adding such a feature into ElasticPress that would index successful search queries and the amount of results they return (in a safe and performant way) and compare current search queries against this list of known successful queries and suggest alternative searches would be a great feature that can help visitors find relevant content.
This sounds great
For future reference:
- https://www.elastic.co/guide/en/elasticsearch/guide/current/fuzzy-matching.html
- https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-suggesters.html
We already have code that works; we are now deciding on how to display it. Burhan will send the response from the API to Vasken.
Sample:
{
"took": 61,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 26,
"relation": "eq"
},
"max_score": 156.51617,
"hits": []
},
"aggregations": {
"terms": {}
},
"suggest": {
"search": [
{
"text": "pagee",
"offset": 0,
"length": 5,
"options": [
{
"text": "page",
"score": 0.064528644
},
{
"text": "pages",
"score": 0.053616848
}
]
}
]
}
}
@burhandodhy For this issue, search suggesters should be added to the Elasticsearch query generated by ElasticPress. This could be optionally added to queries by checking for an ep_suggestions, or similar, argument on the WP_Query instance. Whether or not that is automatically added to the main query should be behind a filter for now.
Then a method for retrieving the suggestions from the query should be added (similar to how aggregations are retrieved) and a template function should be added for displaying the suggestion in a template. The suggestion should be a link to perform a search with the search query changed to the suggestion (perhaps separate functions for the search URL and suggested term might be appropriate).
Once this is implemented support can be added to Instant Results for #3409.
Give the admin user 2 options:
- Redirect the end user to the top result if no result was returned
- Present no results but list all alternatives
Determine if ES returns results when the searched term is already correct (Does searching for page return pages and/or pagee?)
@burhandodhy let's go with this for the summary text: "Recommend alternative search terms for misspelled queries or terms with no results"