我想弄清楚如何进行搜索,将单词从我的搜索词映射到存储在单词集(段)中的单词数据库。搜索和拆分数据库值的搜索条件和查询使用Linq
这个工作几乎可以,除了它还返回包含在Contain中的字母的结果而不是完全匹配,这完全是我想要的。我尝试了一些变化,但理想地寻找某人在这方面阐明一些光。任何帮助是极大的赞赏!
所以,如果我传递 “中的” 将返回:
的房子有...
肛的 [R房子(这不应该返回)
string[] seperator = { " " };
string[] filteredSearchTerms = searchTerm.Split(seperator, StringSplitOptions.None);
var entities = new Entity();
List<dto> dto = (from t in entities.tbl
where
filteredSearchTerms.Any(v => t.Description.Contains(v))
select new dto
{
description = t.Description
}).Take(10).ToList();
问候,
Tez
只是看着你的答案,此刻我收到一个错误。 IsMatch不支持linq到实体布尔。 – 2015-02-10 21:57:50
@TezWingfield看看这些SO问题:http://stackoverflow.com/questions/5720987/how-to-simulate-regular-expressions-in-linq-to-sql和http://stackoverflow.com/questions/3493501/using-match-in-a-linq-statement – 2015-02-10 22:02:46
@TezWingfield查看编辑答案。 – 2015-02-10 22:19:35