今天遇到一个新需求 需要在easyui的组件combox中输入一段文字,然后根据文字自动匹配选项
先获取combox的输入文字
function getGoodSeries(){
var value = "";
//console.log($(".combo-text"));
$.each($(".combo-text"),function(i,o){
//console.log($(o).parent().prev().attr('comboname'));
if($(o).parent().prev().attr('comboname') == 'tgdw'){
//console.log($(o).val());
value = $(o).val();
}
});
return value;
}
然后根据文字去后台通过分词进行模糊匹配,返回匹配的选项id,然后赋值
$('#tgdw').combobox('textbox').bind('blur', function(e) {
var url = "${basePath}/cms/splitWord";
$.post(url, {
words : getGoodSeries()
}, function(data) {
if (data.msg == "OK") {
$("#tgdw").combobox('setValues',data.tgdws.split(","));
} else {
alert(data.msg);
}
}, 'json');
})
以下是分词相关的,采用的网上的帖子
- package com.lxw1234.wordsplit;
- import java.io.StringReader;
- import org.apache.lucene.analysis.Analyzer;
- import org.apache.lucene.analysis.TokenStream;
- import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
- import org.wltea.analyzer.lucene.IKAnalyzer;
- /**
- *
- * @author lxw的大数据田地 -- lxw1234.com
- *
- */
- public class Test {
- public static void main(String[] args) throws Exception {
- String text = "lxw的大数据田地 -- lxw1234.com 专注Hadoop、Spark、Hive等大数据技术博客。 北京优衣库";
- Analyzer analyzer = new IKAnalyzer(false);
- StringReader reader = new StringReader(text);
- TokenStream ts = analyzer.tokenStream("", reader);
- CharTermAttribute term=ts.getAttribute(CharTermAttribute.class);
- while(ts.incrementToken()){
- System.out.print(term.toString()+"|");
- }
- analyzer.close();
- reader.close();
- }
- }