mixailshaulsky/elasticsearch-bundle

Symfony 的 Elasticsearch 套件。

安装: 2

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 189

公开问题: 0

类型:symfony-bundle

v6.1.0-beta 2019-10-24 06:08 UTC

README

这是 ONGR Elasticsearch Bundle 的分支,具有自定义 索引相似度 的功能。

步骤 1:配置套件

# config/packages/ongr_elasticsearch.yaml
ongr_elasticsearch:
    analysis:
        filter:
            edge_ngram_filter: #-> your custom filter name to use in the analyzer below
                type: edge_ngram 
                min_gram: 1
                max_gram: 20
        analyzer:
            eNgramAnalyzer: #-> analyzer name to use in the document field
                type: custom
                tokenizer: standard
                filter:
                    - lowercase
                    - edge_ngram_filter #that's the filter defined earlier
        similarity:
            scripted_tfidf:
              type: scripted
              script:
                source: "double tf = Math.sqrt(doc.freq); double idf = 1.0; double norm = 1/Math.sqrt(doc.length); return query.boost * tf * idf * norm;"
    indexes:
        App\Document\Product:
            hosts: [elasticsearch:9200] # optional, the default is 127.0.0.1:9200

步骤 2:配置 Document 字段的自定义相似度

// src/Document/Product.php

namespace App\Document;

use ONGR\ElasticsearchBundle\Annotation as ES;

/**
 * //alias and default parameters in the annotation are optional. 
 * @ES\Index(alias="products", default=true)
 */
class Product
{
    /**
     * @ES\Id()
     */
    public $id;

    /**
     * @ES\Property(type="text", similarity="scripted_tfidf")
     */
    public $title;

    /**
     * @ES\Property(type="float")
     */
    public $price;
}