关于elasticsearch支持搜索中文和拼音的索引如何构建构建
环境一台 centos6.5 192.168.1.82 es-node2 一台 centos6.6 192。168.1.136 es-node1
{ "status": 200, "name": "es-node1", "cluster_name": "elasticsearch-cluster-centos", "version": { "number": "1.4.4", "build_hash": "c88f77ffc81301dfa9dfd81ca2232f09588bd512", "build_timestamp": "2015-02-19T13:05:36Z", "build_snapshot": false, "lucene_version": "4.10.3" }, "tagline": "You Know, for Search" }
问题:关键字"苍穹的法芙娜:逝者的权利” 拼音首字母 CQDFFNSZDQL
条件: 逝者的权利,DQL
目的:关键词命中
以目前的索引结构
[body] => Array | |
( | |
[name] => 非诚勿扰 | |
[letter] => FCWR |
搜索中文测试代码:
$json = '{
"query" : {
"match" : {
"name" : "'. $q. '"
}
}
}';
$params['body'] = $json;
$params['size'] = 100;
$query = $es->search($params);
测试结果:正确返回
搜索拼音测试代码:
$json = '{
"query" : {
"match" : {
"letter" : "'. $q. '"
}
}
}';
$params['body'] = $json;
$params['size'] = 100;
$query = $es->search($params);
测试结果为空
于是我有了第二种方案:索引结构[body] => Array | |
( | |
[name] => 苍穹的法芙娜:逝者的权利 | |
[alias] => 蒼穹のファフナー Right of Left/苍穹之战神:逝者的权利/苍穹之巨龙:逝者的权利 | |
[letter] => CQDFFNSZDQL | |
[kewords] => Array | |
( | |
[0] => C | |
[1] => CQ | |
[2] => CQD | |
[3] => CQDF | |
[4] => CQDFF | |
[5] => CQDFFN | |
[6] => CQDFFNS | |
[7] => CQDFFNSZ | |
[8] => CQDFFNSZD | |
[9] => CQDFFNSZDQ | |
[10] => CQDFFNSZDQL | |
[11] => Q | |
[12] => QD | |
[13] => QDF | |
[14] => QDFF | |
[15] => QDFFN | |
[16] => QDFFNS | |
[17] => QDFFNSZ | |
[18] => QDFFNSZD | |
[19] => QDFFNSZDQ | |
[20] => QDFFNSZDQL | |
[21] => D | |
[22] => DF | |
[23] => DFF | |
[24] => DFFN | |
[25] => DFFNS | |
[26] => DFFNSZ | |
[27] => DFFNSZD | |
[28] => DFFNSZDQ | |
[29] => DFFNSZDQL | |
[30] => F | |
[31] => FF | |
[32] => FFN | |
[33] => FFNS | |
[34] => FFNSZ | |
[35] => FFNSZD | |
[36] => FFNSZDQ | |
[37] => FFNSZDQL | |
[38] => F | |
[39] => FN | |
[40] => FNS | |
[41] => FNSZ | |
[42] => FNSZD | |
[43] => FNSZDQ | |
[44] => FNSZDQL | |
[45] => N | |
[46] => NS | |
[47] => NSZ | |
[48] => NSZD | |
[49] => NSZDQ | |
[50] => NSZDQL | |
[51] => S | |
[52] => SZ | |
[53] => SZD | |
[54] => SZDQ | |
[55] => SZDQL | |
[56] => Z | |
[57] => ZD | |
[58] => ZDQ | |
[59] => ZDQL | |
[60] => D | |
[61] => DQ | |
[62] => DQL | |
[63] => Q | |
[64] => QL | |
[65] => L | |
[66] => 苍 | |
[67] => 苍穹 | |
[68] => 苍穹的 | |
[69] => 苍穹的法 | |
[70] => 苍穹的法芙 | |
[71] => 苍穹的法芙娜 | |
[72] => 苍穹的法芙娜逝 | |
[73] => 苍穹的法芙娜逝者 | |
[74] => 苍穹的法芙娜逝者的 | |
[75] => 苍穹的法芙娜逝者的权 | |
[76] => 苍穹的法芙娜逝者的权利 | |
[77] => 穹 | |
[78] => 穹的 | |
[79] => 穹的法 | |
[80] => 穹的法芙 | |
[81] => 穹的法芙娜 | |
[82] => 穹的法芙娜逝 | |
[83] => 穹的法芙娜逝者 | |
[84] => 穹的法芙娜逝者的 | |
[85] => 穹的法芙娜逝者的权 | |
[86] => 穹的法芙娜逝者的权利 | |
[87] => 的 | |
[88] => 的法 | |
[89] => 的法芙 | |
[90] => 的法芙娜 | |
[91] => 的法芙娜逝 | |
[92] => 的法芙娜逝者 | |
[93] => 的法芙娜逝者的 | |
[94] => 的法芙娜逝者的权 | |
[95] => 的法芙娜逝者的权利 | |
[96] => 法 | |
[97] => 法芙 | |
[98] => 法芙娜 | |
[99] => 法芙娜逝 | |
[100] => 法芙娜逝者 | |
[101] => 法芙娜逝者的 | |
[102] => 法芙娜逝者的权 | |
[103] => 法芙娜逝者的权利 | |
[104] => 芙 | |
[105] => 芙娜 | |
[106] => 芙娜逝 | |
[107] => 芙娜逝者 | |
[108] => 芙娜逝者的 | |
[109] => 芙娜逝者的权 | |
[110] => 芙娜逝者的权利 | |
[111] => 娜 | |
[112] => 娜逝 | |
[113] => 娜逝者 | |
[114] => 娜逝者的 | |
[115] => 娜逝者的权 | |
[116] => 娜逝者的权利 | |
[117] => 逝 | |
[118] => 逝者 | |
[119] => 逝者的 | |
[120] => 逝者的权 | |
[121] => 逝者的权利 | |
[122] => 者 | |
[123] => 者的 | |
[124] => 者的权 | |
[125] => 者的权利 | |
[126] => 的 | |
[127] => 的权 | |
[128] => 的权利 | |
[129] => 权 | |
[130] => 权利 | |
[131] => 利 | |
) |
测试代码:
$json = '{
"query" : {
"match" : {
"kewords" : "'. $q. '"
}
}
}';
$params['body'] = $json;
$params['size'] = 100;
$query = $es->search($params);
结果全部命中。
缺点,每条信息需要耗费时间拼凑关键词
有没有其他的好办法
有人会使用
Pinyin Analysis for ElasticSearch插件的么?
请联系我:iposou@163.com,526161488
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有个好用点的拼音分词http://git.oschina.net/music_code_m/elasticsearch-analysis-lc-pinyin
拼音信息不需要放在索引中吧。。可以做个拼音词库。。