Click here to Skip to main content
15,995,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

You can try something like below, for all the examples you given in your question below expression giving correct results

C#
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. :-)
 
Share this answer
 
v3
Comments
souvikcode 3-Jun-14 12:32pm    
but if i write "chest pain" it is also returning "leg pain".that's wrong.
you have mentioned SQL in your question but you have not tagged SQL in it.. :)

But using sql you can do it with like clause.. :)

SQL
select * from  test.A  where symptoms like '%'+@symptoms+'%'


you have to pass @symptoms from code behind. :)
it rerurns all symptoms which contains passed word in it
 
Share this answer
 
Comments
souvikcode 3-Jun-14 12:40pm    
this is totally wrong.If I type only "i" in searchbox it returns "thalasemia"
"thyroid" also as this contain "i".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900