代码:
public List<SearchResult> GetRecordsByTerm(string term)
{
return
_dataReadService.GetRecords()
.Where(x => x.FirstName.Contains(term) || term.Contains(x.FirstName)
|| x.LastName.Contains(term) || term.Contains(x.LastName)
|| x.EmailAddress.Contains(term) || term.Contains(x.EmailAddress))
.Select(x => new SearchResult()
{
DetailedName = (x.FirstName ?? String.Empty) + " " + (x.LastName ?? String.Empty) + (x.Title != null && x.Title != String.Empty ? ", " : String.Empty) + (x.Title ?? String.Empty) + " (" + (x.Office ?? String.Empty) + ")",
Email = x.EmailAddress
})
.OrderBy(x => x.DetailedName)
.ToList();
}
在上面的代码中,如果我将该术语作为“baske
”传递,我会得到两个搜索结果,如下所示:
1, "bas ge"
2, "basket"
“bas ge
”不应该进入此搜索结果,但我得到的结果。如何重新定义上面的代码,以便我只需要获得完全匹配的单词?
答案 0 :(得分:0)
如果“bas”是名字,那么term.Contains(x.FirstName)将为true。这似乎很奇怪。