代码:
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“不应该出现在这个搜索结果中,但是我得到了这个结果。如何重新定义上面的代码,以便我只需要获得精确匹配的单词?
发布于 2013-07-18 15:54:09
如果"bas“是名字,那么term.Contains(x.FirstName)就是真的。这似乎是一件奇怪的事情。
https://stackoverflow.com/questions/17716423
复制相似问题