2016-08-09 118 views
0

Ich habe den folgenden Ausdruck: „noapte bună“ und ich versuche, das gleiche Ergebnis zu erhalten, wenn ich für „bună“ oder „Buna“ bin auf der Suche.Elasticsearch Abfrage mit diakritischen Zeichen/Akzenten in PHP

Ich habe gefolgt hier Tutorial: https://www.elastic.co/guide/en/elasticsearch/guide/current/asciifolding-token-filter.html aber zu keinem Ergebnis.

Dies ist mein Code:

$params = ['index' => 'asciiv3', 'body' => [ 
    "settings" => [ 
     "analysis" => [ 
      "analyzer" => [ 
       "folding" => [ 
        "tokenizer" => "standard", 
        "filter" => [ "lowercase", "asciifolding" ] 
       ] 
      ] 
     ] 
    ], 
    "mappings" => [ 
     "asciiv3" => [ 
      "properties" => [ 
       "saying" => [ 
        "type" =>   "string", 
        "analyzer" =>  "standard", 
        "fields" => [ 
         "folded" => [ 
          "type" =>  "string", 
          "analyzer" => "folding" 
         ] 
        ] 
       ] 
      ] 
     ] 
    ] 
]]; 
self::$instance->indices()->create($params); 

und dies ist die Abfrage-Array:

'multi_match' => 
    array(
     "type" =>  "most_fields", 
     "query" => "bună", 
     "fields" => [ "saying", "saying.folded" ] 
    ) 

Weiß jemand, was ich falsch mache?

+0

Dass man für mich funktioniert. –

Antwort

0

Es funktioniert für mich. Das ist mein Setup:

PUT asciiv3 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "folding": { 
      "tokenizer": "standard", 
      "filter": [ 
      "lowercase", 
      "asciifolding" 
      ] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "asciiv3": { 
     "properties": { 
     "saying": { 
      "type": "string", 
      "analyzer": "standard", 
      "fields": { 
      "folded": { 
       "type": "string", 
       "analyzer": "folding" 
      } 
      } 
     } 
     } 
    } 
    } 
} 
POST /asciiv3/asciiv3/1 
{ 
    "saying":"bună ziua" 
} 
POST /asciiv3/asciiv3/2 
{ 
    "saying":"buna ziua" 
} 

GET /asciiv3/_search 
{ 
    "query": { 
    "multi_match": { 
     "type": "most_fields", 
     "query": "bună", 
     "fields": [ 
     "saying", 
     "saying.folded" 
     ] 
    } 
    } 
} 

Mit diesen Ergebnissen:

"hits": { 
     "total": 2, 
     "max_score": 0.2712221, 
     "hits": [ 
     { 
      "_index": "asciiv3", 
      "_type": "asciiv3", 
      "_id": "1", 
      "_score": 0.2712221, 
      "_source": { 
       "saying": "bună ziua" 
      } 
     }, 
     { 
      "_index": "asciiv3", 
      "_type": "asciiv3", 
      "_id": "2", 
      "_score": 0.028130025, 
      "_source": { 
       "saying": "buna ziua" 
      } 
     } 
     ] 
    }