What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Good morning πŸ‘‹ To introduce *autocompletion* for *Elasticsearch* queries, we: β€’ use `Completion

UK5GL0DEF
UK5GL0DEF Posts: 10 πŸ§‘πŸ»β€πŸš€ - Cadet
edited May 2021 in Help

Good morning πŸ‘‹
To introduce autocompletion for Elasticsearch queries, we:
β€’ use CompletionQueryExpanderPlugin and CompletionResultFormatterPlugin in the CatalogDependencyProviderΒ 
β€’ use edge-ngram as filter in page.json to provide the starting tokens of our words from the index β€”> this works fine πŸŽ‰
β€’ Spryker docs say that the completion words will be picked from the completion_terms field in page.json: but we don’t have such a field, instead the completion terms are being picked from the index as expected (because we have edge-ngram) βœ…
To introduce spelling suggestion, we:
β€’ use SpellingSuggestionQueryExpanderPlugin and SpellingSuggestionResultFormatterPlugin in the CatalogDependencyProvider
β€’ Spryker docs say that all suggestions will be picked from the suggestion_terms field in page.json -> can we avoid this and pick from the index instead?
β€’ can we not specify sth (e.g. fuzzy) in page.json to get spelling suggestions from the index ❓ πŸ™‡

Comments

  • U01T075RRHD
    U01T075RRHD Posts: 118 πŸ§‘πŸ»β€πŸš€ - Cadet

    I'm not sure what you mean by from the index but I guess you are referring to the full_text and full_text_boosted fields.
    You should be careful with completions though. The idea is that these are extremely fast to provide almost instant feedback to the user. This is why Elasticsearch provides a special strategy for this:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.12/search-suggesters.html#completion-suggester
    Spryker is making use of that by providing the completion_terms field (as far as I know)

    The approach is very similar for providing spelling suggestions:
    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html

  • UK5GL0DEF
    UK5GL0DEF Posts: 10 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited May 2021

    I’m also not sure what i mean with from the index πŸ˜„
    (i think it’s the magic Elasticsearch index that maps words from documents to the related document-id (and the word’s frequency)).
    I thought there was a possibility to get spelling suggestions directly from the index and not from a field in the page.json because maybe the suggestion_terms are not complete while the index is complete.
    The Elasticsearch docs refer to it here https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#fuzzy, but I think I understand now: for fuzzy queries, they don’t suggest corrected terms but just return corrected results.
    So, I guess I have to add the suggestion_terms list if I want to have spelling suggestions.

  • UK5GL0DEF
    UK5GL0DEF Posts: 10 πŸ§‘πŸ»β€πŸš€ - Cadet

    I guess, suggestion_terms should be added like this in page.json ?

    "mappings": {
        "page": {
          "properties": {
            "full-text": {
              (...)
            },
            "full-text-boosted": {
              (...)
            },
            "search_data": {
              "suggestion_terms": {
                "type": "string",
                "index_analyzer": "term_suggestion_analyzer",
                "search_analyzer": "lowercase_analyzer"
              }
            }
          }
        }
    

    I don’t need to provide the actual spelling suggestions, right?

    "suggestion_terms": {
       "type": "string",
       "suggestion_terms": ["hammer", "radio", "sofa"]
    
  • U01T075RRHD
    U01T075RRHD Posts: 118 πŸ§‘πŸ»β€πŸš€ - Cadet

    Correct, you don't. Albeit the results can sometimes be a bit weird since Elasticsearch determines the suggestions from the terms it knows and they are not always suitable.
    I think Spryker provides all the necessary plugins out of the box so you don't need to manually add a new field to your page document.

  • UK5GL0DEF
    UK5GL0DEF Posts: 10 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited May 2021

    Yes, I see that now, it’s all there πŸŽ‰
    The query already returns suggestions in case of a typo: I’ll just call CatalogController again in this case now, so the results for the suggested term are being displayed immediately.

  • U01T075RRHD
    U01T075RRHD Posts: 118 πŸ§‘πŸ»β€πŸš€ - Cadet

    Nice, I'm happy you got it to work