【发布时间】:2015-07-12 15:10:06
【问题描述】:
我有一个图像列表,我想使用 BOTH 规则搜索多个关键字
例如,如果我搜索“dancing child”,我想显示包含关键字 dance 和 child 的项目列表
我实现了一个类似这样的查询:
List<string> target_keywords = //an array contains Keywords to Lookup
var RuleAny_results = (from imageItem in images
select new{ imageItem,
Rank =target_keywords.Any(x => imageItem.Title != null && imageItem.Title.ToLower().Contains(x)) ? 5 :
target_keywords.Any(x => imageItem.Name != null && imageItem.Name.ToLower().Contains(x)) ? 4 :
0
}).OrderByDescending(i => i.Rank);
//exclude results with no match (ie rank=0 ) and get a Distinct set of items
_searchResult = (from item in RuleAny_results
where item.Rank != 0
select item.imageItem).Distinct().ToList();
但这将返回包含target_keywords 中任何项目的结果,例如如果我在上面的代码中搜索“跳舞的孩子”,则返回带有任何关键字 dance 或 child 的项目列表。但我只想要包含跳舞和儿童关键字的列表
那么如何转换查询以获取包含 BOTH 关键字的所有记录?
【问题讨论】: