/**
* 搜索专辑
* @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];
}
最主要的是这段代码
“query” => $keywords,
“operator”=>“or”,
“minimum_should_match”=>“75%”,