问题描述
我有一个名为test的表。名为症状的列有这些数据。
头疼
thalasemia
甲状腺
癌症
胸痛
腿部疼痛
药物症状1
现在,如果我输入搜索框腿部疼痛它显示正确的一个。输入疼痛它显示所有疼痛相关。
但如果我输入症状药物1 或legpain,它没有返回结果。
我在string.contains()方法上创建了搜索选项。但这还不足以满足我的要求。如果用户输入单词依次像症状,它显示结果,但用户可以键入任何组合,如症状医药1或症状医学1等。是否有可能像谷歌搜索?虽然我知道谷歌搜索关键字但有什么方法吗?
I have a table named test.A column named symptoms has these data.
headache
thalasemia
thyroid
cancer
chest pain
leg pain
symptoms for medicine1
now if I type in searchbox "leg pain" it shows right one.for typing "pain" it shows all pain related.
But if I type "symptoms medicine1" or "legpain" ,its not returning result.
I have created search option on string.contains() method.But that is not sufficient for my requirement.If user type words sequentially like "symptoms for",it shows result,but user can type any combination like "symptoms medicine1" or "symptomsmedicine1",etc.Is it possible to do the search like google?Though I know google search through keywords but is there any way?
推荐答案
string input ="symptomsmedicine1";
string fromDb ="symptoms for medicine1";
if(fromDb.Split().Any(y=>input.Contains(y)))
{
// matching item
}
您可以在转换为小写或大写后比较字符串。那么它将是一个不区分大小写的搜索。 : - )
you can compare strings after convert to lowercase or uppercase. then it will be a case insensitive search. :-)
select * from test.A where symptoms like '%'+@symptoms+'%'
您必须从代码后面传递 @symptoms
。 :)
它会重现所有包含传递的单词的症状
you have to pass @symptoms
from code behind. :)
it rerurns all symptoms which contains passed word in it
这篇关于如何在c#sql中创建类似单词的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!