在我的程序中,用户可以在前端“禁用”模糊搜索,这会将后端请求更改为:
$query['query']['bool']['must'][] = [
'bool' => [
'should' => [
['match_phrase' => ['name' => $param]],
['match_phrase' => ['description' => $param]],
],
'minimum_should_match' => 1,
],
];
$param
是搜索查询。我要查找的文档是Evo-Singularity
。
以下是我对这一点的看法:evo
=〉工程evo-
=〉工程evo-sing
=〉无结果
=〉工作
考虑到这一点,我尝试改用wildcard
方法:
$param = '*'.$param.'*';
//No Fuzzy Search - Do a literal match
$query['query']['bool']['must'][] = [
'wildcard' => [
'name' => $param
],
'wildcard' => [
'description' => $param
],
];
=〉工作evo-
=〉无结果evo-sing
=〉无结果singularity
=〉无结果
然后我走到控制台,看看能不能找到它:
这是可行的:
{
"query": {
"match": {
"name": "evo-singularity"
}
}
}
以下通配符搜索均无效:
{
"query": {
"wildcard": {
"name": {
"value": "*evo\\-singularity*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
或
{
"query": {
"wildcard": {
"name": {
"value": "*evo*singularity*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
但这确实有效:
{
"query": {
"wildcard": {
"name": {
"value": "*singularity*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
下面是elasticsearch中的实际文档,我已经删除了所有不必要的信息:
"_source": {
"type": "Trap Card",
"description": "Target 1 \"Evoltile\" monster and 1 \"Evolsaur\" monster in your Graveyard; Special Summon 1 \"Evolzar\" Xyz Monster from your Extra Deck, and if you do, attach those monsters to it as Xyz Materials.",
"name": "Evo-Singularity",
},
在这个阶段,我没有主意了。带有空格连字符空格的文档似乎可以正常工作:
vanquish soul - kaiser
但连字符周围没有空格的文档存在问题:
evo-singularity
我的分析仪设置:
{
"card_database": {
"settings": {
"index": {
"provided_name": "card_database",
"number_of_replicas": "1",
"max_result_window": "15000",
"uuid": "Jfgh8F_FQQO21qSkQDngFw",
"number_of_shards": "1",
"analysis": {
"filter": {
"my_stopwords_filter": {
"stopwords": [
"a",
"an",
"the"
],
"type": "stop"
}
},
"analyzer": {
"my_analyzer": {
"filter": [
"lowercase",
"my_stopwords_filter"
],
"tokenizer": "standard"
}
}
},
"creation_date": "1676906459467",
"version": {
"created": "8060199"
},
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"blocks": {
"read_only_allow_delete": "false"
}
}
}
}
}
下面是我的Map的链接:
https://justpaste.it/471fi
1条答案
按热度按时间xdnvmnnf1#
如果字段作为关键字编入索引,请尝试将查询更改为术语查询