搜索查询以查找可能位于多个属性中的单词

时间:2018-07-05 09:13:24

标签: c# linq episerver episerver-find

我有三个属性

First name
Last name
Username

用户可以搜索所有三个属性中的单词。我有这两个查询以达到预期的结果

searchTermFilters = searchTermFilters
.For(term)
.InFields(x => x.Firstname, x => x.Surname, x => x.Username);


searchTermFilters = searchTermFilters
            .OrFilter(x => x.Firstname.AnyWordBeginsWith(term))
            .OrFilter(x => x.Surname.AnyWordBeginsWith(term))
            .OrFilter(x => x.Username.AnyWordBeginsWith(term));

问题是,对于它们两者而言,它完全匹配。我想要类似Linq中的.Contains之类的东西。有见识吗?

2 个答案:

答案 0 :(得分:1)

条件下使用这种方式

searchTermFilters.Filter(x => x.Firstname.Contains(term) | 
                         x => x.Lastname.Contains(term) |
                         x => x.Username.Contains(term))

答案 1 :(得分:-1)

对于单个过滤器=>

searchTermFilters = searchTermFilters.Where(w=>w.FirstName.Contains(term)).ToList();

对于多过滤器=>

searchTermFilters = searchTermFilters.Where(w=>w.FirstName.Contains(term) || w.Surname.Contains(term)).ToList();

希望获得帮助。