新建模板,便於後續建立索引,直接使用模板,省事方便
put _template/goods
, "******_pinyin_filter": ,
"full_pinyin_filter":
},"char_filter":
},"tokenizer":
},"analyzer": ,
"ngramsearchanalyzer": ,
"ikindexanalyzer": ,
"iksearchanalyzer": ,
"******pinyinindexanalyzer": ,
"******pinyinsearchanalyzer": ,
"fullpinyinindexanalyzer": ,
"fullpinyinsearchanalyzer": }}
}}
新建char_filter_text.txt
存於es_home/config
目錄下。可以把相關部分刪除。
goods_v1
將使用上述模板(goods*
),可直接使用模板中定義的analyzer
delete goods_v1
put /goods_v1
, "name" : ,
"spy": ,
"fpy": }},
"update_time" : ,
"deleted" : }}
}}put /goods_v1/_alias/goods
本搜尋只做簡單過濾,並且按id倒序返回,不需要計算相似度
get goods/_search}},
}},}},
}},}},
}}
],"adjust_pure_negative": true,
"boost": 1}}
],"adjust_pure_negative": true,
"boost": 1}},
"boost": 1}},
"sort": [
}]}
多個query結果,取相似度score
最大的返回
get goods/_search}},
}},}},
}},}}
],"boost": 1}}
],"filter": [}}
],"adjust_pure_negative": true,
"boost": 1
}}}
public
class
searchrequest
public
class
goodsrequest
extends
searchrequest
private boolquerybuilder addfilter
(querybuilder basequerybuilder, goodsrequest request)
return boolquerybuilder;
}private boolquerybuilder getbasefilterquerybuilder()
private boolquerybuilder getkeywordquerybuilder
(string keyword)
boolquerybuilder keywordquerybuilder = querybuilders.
boolquery()
; querybuilder ngramsearchbuilder = querybuilders
.matchquery
("name.ngram"
, keyword)
.analyzer
("ngramsearchanalyzer").
boost(5f
);keywordquerybuilder.
should
(ngramsearchbuilder);
termquerybuilder ******pinyinquerybuilder = querybuilders.
termquery
("name.spy"
, keyword)
; keywordquerybuilder.
should
(******pinyinquerybuilder)
;
querybuilder ******pinyincontainquerybuilder = querybuilders
.wildcardquery
("name.spy"
,"*"
+ keyword +
"*")
.boost
(0.8f);
keywordquerybuilder.
should
(******pinyincontainquerybuilder)
;
querybuilder fullpingyinquerybuilder = querybuilders
.matchphrasequery
("name.fpy"
, keyword)
.analyzer
("fullpinyinsearchanalyzer");
keywordquerybuilder.
should
(fullpingyinquerybuilder)
;
querybuilder containsearchbuilder = querybuilders
.matchquery
("name"
, keyword)
.analyzer
("iksearchanalyzer").
minimumshouldmatch
("100%");
keywordquerybuilder.
should
(containsearchbuilder)
;return keywordquerybuilder;
}// 返回滿足搜尋條件的結果,按id倒序
private searchsourcebuilder getsearchbuilder
(goodsrequest request)
searchsourcebuilder searchsourcebuilder =
newsearchsourcebuilder()
; searchsourcebuilder.
query
(querybuilders.
constantscorequery
(boolquerybuilder));
searchsourcebuilder.
sort
(sortbuilders.
fieldsort
("id").
order
(sortorder.desc));
return searchsourcebuilder;
}// 按相關度返回結果
private searchsourcebuilder getsearchbuilderwithscore()
—未完待續— php獲取中文拼音(含生僻字)支援首字母,全拼
高階篇支援多音字,音標 php獲取中文拼音 含生僻字,多音字,音標 支援首字母,全拼 中文轉拼音 utf8版,gbk轉utf8也可用 param string str utf8字串 param string ret format 返回格式 all 全拼音 first 首字母 one 僅第一字元首字母...
中文轉拼音首字母
使用者商品名稱簡拼搜尋 namespace common business 1.5.66 漢字轉拼音類 class pinyin 中文字串轉拼音首字母 strchangepin 漢字轉拼音的首字母 get first letter 漢字轉拼音 str2py 獲取拼音對應ascll碼 pinyin p...
SELECT2支援中文全拼和拼音首字母檢索
一 修改select2.js匹配方法 function matcher params,data check if the text contains the term if original 1 if it doesn t contain the term,don t return anything...