fexon
fexon

Reputation: 41

Elasticsearch phrase suggester prefix phonetic differences

I was wondering if there is any way for the phrase suggester to correct prefix spelling mistakes on phonetic differences.

Elasticsearch 5.1.2

Testing in Kibana 5.1.2

For Example:

Instead of "circus" someone wrote "sircus", or instead of "coding" someone wrote "koding". Funny thing is, that instead of "phrase" you can write "frase" and get a suggestion.

Here is my setup.

Settings:

PUT text_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "suggests_analyzer": {
          "tokenizer": "standard",
          "filter": [
           "lowercase",
           "asciifolding",
           "shingle_filter"
          ],
          "type": "custom"
        },
        "reverse": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "reverse"]
          }
      },
      "filter": {
        "shingle_filter": {
          "min_shingle_size": 2,
          "max_shingle_size": 5,
          "type": "shingle"
        }
      }
    }
  },
  "mappings": {
    "testtype": {
      "properties": {
        "suggest_field": {
          "type": "text",
          "analyzer": "suggests_analyzer",
          "fields": {
            "reverse": {
              "type": "text",
              "analyzer": "reverse"
            }
          }
        }
      }
    }
  }
}

Some documents:

POST test_index/test_type/_bulk
{"index":{}}
{ "suggest_field": "phrase"}
{"index":{}}
{ "suggest_field": "Circus"}
{"index":{}}
{ "suggest_field": "Coding"}

Querying:

POST /so-index/_search
{
  "suggest" : {
    "text" : "sircus",
    "simple_phrase" : {
      "phrase" : {
        "field" :  "suggest_field",
        "max_errors": 0.9,
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        },
        "direct_generator" : [ {
          "field" : "suggest_field",
          "suggest_mode" : "always"
        }, {
          "field" : "suggest_field.reverse",
          "suggest_mode" : "always",
          "pre_filter" : "reverse",
          "post_filter" : "reverse"
        }]
      }
    }
  }
}

Also, I repeat following steps a few times (between 5 and 10) without changing anything:

Sometimes I get suggestions and sometimes I don't. Is there any explanation for it?

Upvotes: 0

Views: 246

Answers (1)

moy2010
moy2010

Reputation: 900

Try setting "prefix_length": 0 in the direct_generator.

Upvotes: 0

Related Questions