How do you check if all the search terms exist in a specific field.
如何检查所有搜索词是否存在于特定字段中。
search terms option 1: green white,
搜索条件选项1:绿色白色,
search terms option 2: test query,
搜索词选项2:测试查询,
search terms option 3: green query.
搜索词选项3:绿色查询。
var search_result = (from s in dbContext.databasetable.Where
(i => 1.city == "NYC"
&&(search_text.Any(x => i.name.Contains(x))
|| search_text.Any(x => i.surname.Contains(x))))
select s).OrderByDescending(i => i.Date);
search_text is an string array
search_text是一个字符串数组。
record in database:
记录在数据库:
name: green white red
名字:绿色白色红色
surname: search test query
姓:搜索查询测试
option 1 and two must return the record while option 3 must return "null".
选项1和选项2必须返回记录,而选项3必须返回“null”。
The word must all exist in the name or must all exist in the surname.
这个词必须在名字中存在,或者必须在姓氏中存在。
2 个解决方案
#1
0
Did you think about the casing?
你想过套管吗?
It's not your problem in this current example but I guessed that maybe you didn't show us your real data. It's case sensitive, so "GREEN" won't match "green".
在这个例子中,这不是你的问题,但是我猜也许你没有给我们展示你的真实数据。它是区分大小写的,所以“绿色”与“绿色”不匹配。
#2
0
Stupid me.
愚蠢的我。
This was just some test data for the question. in my case it was subject and content. I used the subjectdata also in the contentdata. in other words the query is working fine with .All
这只是一些测试数据。在我看来,这是主题和内容。我还在contentdata中使用了subject数据。换句话说,查询在.All上运行良好
The testdata was incorrect. Thanks for your replies.
testdata是不正确的。谢谢你的回复。
#1
0
Did you think about the casing?
你想过套管吗?
It's not your problem in this current example but I guessed that maybe you didn't show us your real data. It's case sensitive, so "GREEN" won't match "green".
在这个例子中,这不是你的问题,但是我猜也许你没有给我们展示你的真实数据。它是区分大小写的,所以“绿色”与“绿色”不匹配。
#2
0
Stupid me.
愚蠢的我。
This was just some test data for the question. in my case it was subject and content. I used the subjectdata also in the contentdata. in other words the query is working fine with .All
这只是一些测试数据。在我看来,这是主题和内容。我还在contentdata中使用了subject数据。换句话说,查询在.All上运行良好
The testdata was incorrect. Thanks for your replies.
testdata是不正确的。谢谢你的回复。