ElasticSearch 没有通过 UTF8 字符找到

ElasticSearch does not find by UTF8 characters

我将 ElasticSearch 与 Symfony2 和 FOSElasticaBundle 一起使用。然后我试着找到任何只有 ASCII 字符的东西,它就像一个魅力。此外,我使用 JSON 数组作为数据,并将 unicode 字符转换为类似 \u00f8C 的字符。这会影响我的问题吗?我的搜索代码:

function __construct(Request $request, TransformedFinder $artist_finder, TransformedFinder $picture_finder, Router $router)
{
    $this->request = $request;
    $this->a_finder = $artist_finder;
    $this->p_finder = $picture_finder;
    $this->router = $router;
}

/**
 * @param $query
 * @return array
 */
public function search($query)
{
    $locale = $this->request->getLocale();

    $artist_results = $this->a_finder->find($query.'*', self::SEARCH_LIMIT);
    $gallery_results = $this->p_finder->find($query.'*', self::SEARCH_LIMIT);

    $results = array(
        'artist' => array(),
        'gallery' => array()
    );

    foreach($artist_results as $a)
    {
        $results['artist'][] = array(
            'url' => $this->router->generate('artist_page', ['slug' => $a->getSlug()]),
            'name' => $a->getInfo()[$locale]['name']. ' ' .$a->getInfo()[$locale]['surname']
        );
    }

    foreach($gallery_results as $a)
    {
        $results['gallery'][] = array(
            'url' => $this->router->generate('picture_page', ['slug' => $a->getSlug()]),
            'name' => $a->getInfo()[$locale]['title']
        );
    }

    return $results;
}

此外,ES 是否能够区分立陶宛语字符,例如“Š”和 "S"、“Ė”和 "E" 等?我的意思是,我想通过“žąsis”和 "zasis".

等查询获得相同的结果

您必须配置 analyser section of your fos_elastica bundle configuration

可以根据需要应用不同的分析器。并且有特定的语言,查看相关的elasticsearch documentation

您需要 https://github.com/elasticsearch/elasticsearch-analysis-icu 插件和过滤器的一些配置(在我的例子中是捷克语)...例如

settings:
    analysis:
      analyzer:
        cs_collation:
          type: custom
          tokenizer: keyword
          filter: [trim,cs_icu_collation]
        cs_facets:
          type: custom
          tokenizer: keyword
          filter: [trim]
        custom_analyzer_cs:
          type     :    custom
          tokenizer:    nGram
          filter   :    [stopwords, lowercase, czech_stemmer, asciifolding, snowball, worddelimiter]


filter:
    czech_stemmer:
      type: stemmer
      name: czech
    cs_icu_collation:
      type: icu_collation
      stopwords: [_czech_]
      language: cs

我已经成功了。我不得不使用第二个 json_encode 参数 JSON_UNESCAPED_UNICODE 作为索引值,我认为 是有道理的。