出于某种原因,当我们执行ElasticSearch时,首先生成的搜索结果显示搜索项本身是孤立的,而不是在一个句子中。例如,如果我们搜索“奇妙”一词,我们会得到以下结果:
{
"id": 1697670,
"start": 614.68,
"end": 619.03,
"text": "fantastic",
"created_at": null,
"updated_at": null,
"video_id": 14784,
"index": 127,
"highlight": "<span class=\"highlight\">fantastic<\/span>"
},
我们没有得到任何结果与完整的句子与'奇妙'在这句话。
我猜这要么是我们的Map,要么是实际的搜索。
以下是我们的设置:
static public function getSettings(){
return [
'number_of_shards' => 1,
'number_of_replicas' => 1,
'analysis' => [
'filter' => [
'filter_stemmer' => [
'type' => 'stemmer',
'language' => 'english'
]
],
'analyzer' => [
'text_analyzer' => [
'type' => 'custom',
"stopwords" => [],
'filter' => ['lowercase', 'filter_stemmer'],
'tokenizer' => 'standard'
],
'g_analyzer' => [
'type' => 'custom',
'filter' => ['lowercase', 'stemmer'],
'tokenizer' => 'standard'
],
"no_stopwords" => [
"type" => "standard",
"stopwords" => []
],
]
]
];
}
这是我们的Map:
static public function getMappings(){
return [
'_source' => [
'enabled' => true
],
'properties' => [
'id' => [
'type' => 'integer'
],
'title' => [
'type' => 'text',
"analyzer" => "text_analyzer",
],
'description' => [
'type' => 'text',
"analyzer" => "text_analyzer",
],
'jobStatus' => [
'type' => 'text'
],
'youtubeId' => [
'type' => 'text',
],
'thumbnail' => [
'type' => 'text'
],
'playlistId' => [
'type' => 'text'
],
'channelId' => [
'type' => 'text'
],
'category' => [
'type' => 'text'
],
'globifyChannelId' => [
'type' => 'integer'
],
'publishedDate' => [
"type" => "date",
],
'created_at' => [ //date video was updated
"type" => "date",
],
'updated_at' => [ //date video was updated
"type" => "date",
],
'url' => [
'type' => 'text'
],
'subtitles' => [
'type' => 'nested',
'properties' => [
'id' => [
'type' => 'integer'
],
'start_time' => [
'type' => 'float'
],
'end_time' => [
'type' => 'float'
],
'text' => [
'type' => 'text',
"analyzer" => "text_analyzer",
],
'langcode' => [
'type' => 'text'
],
]
]
]
];
}
这是我们的搜索
$body = [
'query' => [
'nested' => [
'inner_hits' => [
'size' => 3,
"highlight" => [
"pre_tags" => ['<span class="highlight">'],
"post_tags" => ["</span>"],
'fields' => [
'subtitles.text' => new \stdClass()
]
]
],
'path' => 'subtitles',
'query' => [
'bool' => [
'must' => [
[
'match' => ['subtitles.text' => $searchTerm]
]
]
]
],
]
],
"from"=> $from,
"size"=>$pageSize,
];
你知道为什么我们会得到这些奇怪的结果吗?
我使用了错误的分析器/标记器/过滤器吗?
任何帮助/建议或指导都将不胜感激
暂无答案!
目前还没有任何答案,快来回答吧!