我的目標是在按符號或 html 編碼版本搜索時回傳相同的結果。
示例查詢:
# searching with symbol
GET my-test-index/_search
{
"query": {
"bool": {
"must": {
"simple_query_string": {
"query": "Hello?",
"analyzer": "english_syn",
"fields": [
"AllContent"
]
}
}
}
}
}
# html symbol
GET my-test-index/_search
{
"query": {
"bool": {
"must": {
"simple_query_string": {
"query": "Hello®",
"analyzer": "english_syn",
"fields": [
"AllContent"
]
}
}
}
}
}
我嘗試了幾種不同的方法。
添加同義詞,但它們仍然產生不同的結果。
#######################################
# Synonyms
# Symbols
#######################################
?, ™
?, ®
創建了一個 char_filter 來替換特殊字符,這樣他們至少會搜索“Hello”。但這會帶來一系列問題,這些問題超出了我想要實作的范圍。
char_filter": {
"specialCharactersFilter": {
"type": "pattern_replace",
"pattern": "[^A-Za-z0-9]",
"replacement": " "
}
我感謝任何關于實作這一目標的新替代方案的反饋。理想的解決方案涵蓋的不僅僅是 ? 和 ?。
uj5u.com熱心網友回復:
您正在尋找的是html strip char filter,它不僅適用于兩個符號,而且適用于廣泛的 html 字符。
作業示例
使用 html strip char 過濾器進行索引映射
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"html_strip"
]
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
在該檔案中僅使用 (?) 索引示例檔案。
PUT 71622637/_doc/1
{
"title" : "?"
}
搜索其 html 編碼版本
{
"query" :{
"match" : {
"title" : "&trade"
}
}
}
And search result
"hits": [
{
"_index": "71622637",
"_id": "1",
"_score": 0.89701396,
"_source": {
"title": "?"
}
}
]
與此類似,搜索商標符號
{
"query" :{
"match" : {
"title" : "?"
}
}
}
And search result
"hits": [
{
"_index": "71622637",
"_id": "1",
"_score": 0.89701396,
"_source": {
"title": "?"
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/452258.html
