无论是在 jquery 还是 c# 中,我都需要一个准确的搜索功能。如果可能的话,我希望搜索像谷歌一样出色:-)
所以这里是c#代码:
简要说明:
这将搜索数据库中具有完整信息的所有用户。它搜索除当前登录用户之外的所有用户。
string[] ck = keyword.Split(new string[] { " ", ",", "." },
StringSplitOptions.RemoveEmptyEntries);
using (dbasecore db = ConfigAndResourceComponent.BaseCampContext())
{
var results = (from u in db.users
join uinfo in db.userinfoes
on u.UserID equals uinfo.UserID
where u.UserID != userid &&
(ck.Contains(u.LastName) || ck.Contains(u.FirstName) ||
ck.Contains(u.MiddleName) || ck.Contains(u.LoginID))
orderby u.LastName, u.FirstName, u.MiddleName ascending
select uinfo).Skip(skip).Take(take).ToList();
return (from i in results select new UserInfo(i)).ToList();
}
结果:
包围的名称必须位于搜索项的顶部,因为它与更多关键字匹配。
任何的想法?