首先来看看需求
用户输入 “北京市小饭锅餐厅电话”
如果数据库中存在着这样的全部匹配的数据时,当然可以查寻的到,但是数据库中是记的“北京小饭锅餐厅电话” 用一般的 Like '%{用户输入}%' 就不能办到了
这样怎么办,简单说下LZ思路,,就是把用户输入项拆分成小单位的关键字再去搜索,任何匹配的数据就都出来了,忘了一点可以根据需要先过滤掉一些没用的词
1 using System.Linq; 2 using Core.Common; 3 using System.Web; 4 using System.Text.RegularExpressions; Core.Helper 7 { KeySearch 9 { _keyCode = 2;//关键字最小组合字数 [] ReplaceKey =, , , , , , }; 搜索关键字组合方法 KeySearchSpan(string keyword) 32 { 33 string reStr = ""; 34 string copyStr = keyword; 35 if (copyStr.Length < _keyCode) 36 { ; 38 } { 41 var query = from data in ReplaceKey 42 select data; 43 foreach(var s in query) 44 { 45 copyStr = Regex.Replace(copyStr, s, "", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline); 46 } 47 int count = copyStr.Length - _keyCode + 1; 48 for (int i = 0; i < count; i++) 49 { ; 51 } 52 } 53 return reStr; 54 } 55 } 56 }