当前位置:   article > 正文

ES(elasticsearch)搜索标题精准匹配度调节_es 标题 精准匹配

es 标题 精准匹配
/**
 * 搜索专辑
 * @param string $keywords     搜索词
 * @param int    $offset       偏移量
 * @param int    $limit        每页数量
 * @param array  $sort         排序条件, 默认按相关性排序, 支持多组(见self::$sort_*)
 * @param int    $content_type 专辑类型 -1:所有 0:音频 1:视频
 * @param array  $showTypes
 * @return array ['total' => 总数, 'data' => [故事ID, ...]]
 */
public static function searchAlbumByTitle($keywords, $offset = 0, $limit = 10, $sort = [], $content_type = -1, $showTypes = [ShowType::SHOW_TYPE_NORMAL])
{
    $query = [
        "query" => [
            "bool" => [
                "must" => [
                    [
                        "match" => [
                            'title' => [
                                "query" => $keywords,
                                "operator"=>"or",
                                "minimum_should_match"=>"75%",
                            ]
                        ]
                    ],
                    [
                        "term" => [
                            'status' => 1,
                        ]
                    ],
                ]
            ]
        ],
        "sort" => [],
        "_source" => "_id",
        "from" => $offset,
        "size" => $limit
    ];
    if ($content_type >= 0) {
        $query['query']['bool']['must'][] = [
            "term" => [
                'albumcontenttype' => $content_type,
            ]
        ];
    }
    if (count($showTypes) > 0) {
        $query['query']['bool']['must'][] = [
            "terms" => [
                'showtype' => $showTypes
            ]
        ];
    }

    $query["sort"] = self::getSort($sort);
    $ret = self::query($query);

    $ids = [];
    $total = empty($ret['hits']['total']) ? 0 : $ret['hits']['total'];
    if ($ret !== false) {
        foreach ($ret['hits']['hits'] as $v) {
            $ids[$v['_id']] = $v['_id'];
        }
    }

    return ['total' => $total, 'data' => $ids];
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66

最主要的是这段代码
“query” => $keywords,
“operator”=>“or”,
“minimum_should_match”=>“75%”,

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/750700
推荐阅读
相关标签
  

闽ICP备14008679号