ElasticPress icon indicating copy to clipboard operation
ElasticPress copied to clipboard

Feature: Did you mean....?

Open tott opened this issue 5 years ago • 2 comments

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.

tott avatar Feb 16 '21 14:02 tott

This sounds great

Jamiewarb avatar Mar 05 '21 14:03 Jamiewarb

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

Rahmon avatar May 08 '21 13:05 Rahmon

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.

anjulahettige avatar Feb 14 '23 15:02 anjulahettige

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
                    }
                ]
            }
        ]
    }
}

brandwaffle avatar Feb 21 '23 15:02 brandwaffle

@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.

JakePT avatar Mar 28 '23 15:03 JakePT

Give the admin user 2 options:

  1. Redirect the end user to the top result if no result was returned
  2. 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?)

felipeelia avatar May 23 '23 14:05 felipeelia

@burhandodhy let's go with this for the summary text: "Recommend alternative search terms for misspelled queries or terms with no results"

brandwaffle avatar Jun 06 '23 15:06 brandwaffle