代码:
string keyword =RemoveHTML(GetString("Keyword")); StringBuilder strWhere=new StringBuilder("isaudit=1 "+(typeId==0?"": "and TypeID=" + typeId)); if (!string.IsNullOrWhiteSpace(keyword)) { if (keyword.Length > 2) { /*中文分词功能*/ JiebaSegmenter jieba = new JiebaSegmenter(); var segments = jieba.CutForSearch(keyword); strWhere.Append(" and ("); foreach (string key in segments) { strWhere.AppendFormat(" title like '%{0}%' or", key); } strWhere.Append(")"); keyword = string.Join(",", segments); } else { strWhere.AppendFormat(" and title like '%{0}%' or",keyword); } }
注意:使用时请将 Resources文件夹拷贝到网站目录下
另外需要在web.config 文件加入如下配置
<appSettings> <add key="JiebaConfigFileDir" value="F:\site\xx\Resources" />
以上配置用于配置Resources的绝对路径