Click here to Skip to main content
15,886,732 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
In my application iam having a search functionality , and i implemented it like below

C#
placelist = placelist.Where(i => i.category_name.Contains(postData)).Union(placelist.Where(i => i.category_address.Contains(postData))).Union(placelist.Where(i => i.category_tags.Contains(postData))).ToList();


C#
eventlist = eventlist.Where(i => i.event_name.Contains(searchconte)).Union(eventlist.Where(i=>i.event_location.Contains(searchconte))).ToList();


C#
indexlist = indexlist.Where(i => i.restaurant_location.Contains(searchtext)).Union(indexlist.Where(i => i.restaurant_name.Contains(searchtext))).Union(indexlist.Where(i=>i.cuisine_type.Contains(searchtext))).Union(indexlist.Where(i=>i.special_dishes.Contains(searchtext))).ToList();


when iam Entering the postData as "bamb", it is returning nothing , But when i enter the same thing like "Bamb", It is showing the results.

It is searching only Case-Sensitive, I want modify this statement in such a way that it should search and return the content whether it is Case-sensitive or not, and also it should for the content with coma(,) colon(:),Quotes("",'')

How can i modify the statement to get the above mentioned functionality.

What I have tried:

C#
placelist = placelist.Where(i => i.category_name.Contains(postData)).Union(placelist.Where(i => i.category_address.Contains(postData))).Union(placelist.Where(i => i.category_tags.Contains(postData))).ToList();


C#
eventlist = eventlist.Where(i => i.event_name.Contains(searchconte)).Union(eventlist.Where(i=>i.event_location.Contains(searchconte))).ToList();


C#
indexlist = indexlist.Where(i => i.restaurant_location.Contains(searchtext)).Union(indexlist.Where(i => i.restaurant_name.Contains(searchtext))).Union(indexlist.Where(i=>i.cuisine_type.Contains(searchtext))).Union(indexlist.Where(i=>i.special_dishes.Contains(searchtext))).ToList();
Posted
Updated 18-Jul-16 21:00pm

Quote:
when iam Entering the postData as "bamb", it is returning nothing , But when i enter the same thing like "Bamb", It is showing the results.

The problem is rather classical and easy to solve.
You have some data (whatever is the the organization).
For performance considerations, you have indexed the data with some couples (key, position).
The trick is to index on uppercase(key) and to do all searches on uppercase(searched key). It works also with lowercase() as long as the same is done on index and searches.
 
Share this answer
 
Comments
Mohan Rajesh Komatlapalli 18-Jul-16 0:28am    
Hello, @Mr.ppolymorphe ,
Can you please modify the above posted code snippets as you said, Iam trying that but it not worked for me.
I have modified the code as below referred from StackOverflow

C#
indexlist = (from item in indexlist
                          where ContainsIgnoreCase(item.restaurant_location,searchtext)
                              || ContainsIgnoreCase(item.restaurant_name, searchtext)
                              || ContainsIgnoreCase(item.cuisine_type, searchtext)
                              || ContainsIgnoreCase(item.special_dishes, searchtext)
                              select item).ToList();

C#
placelist = (from item in placelist
                                 where ContainsIgnoreCase(item.category_name, postData)
                                 || ContainsIgnoreCase(item.category_tags, postData)
                                 || ContainsIgnoreCase(item.category_address, postData)
                                 select item).ToList();


C#
eventlist = (from item in eventlist
                                 where ContainsIgnoreCase(item.event_name, searchconte)
                                 || ContainsIgnoreCase(item.event_location, searchconte)
                                 select item).ToList();


C#
othersList = (from item in othersList
                                  where ContainsIgnoreCase(item.category_name, PostData)
                                 || ContainsIgnoreCase(item.category_tags, PostData)
                                 || ContainsIgnoreCase(item.category_address, PostData)
                                 select item).ToList();

This modification worked for me,
Thank You for trying out my problem.
 
Share this answer
 

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