Bur*_*urt 3 c# linq asp.net-mvc
I have a requirement to search an IQueryable list for the words in a search term.
Currently I have this working but it is for an exact match.
list.Where(x => x.MyList.Any(y => y.ToSearch.ToLower().Contains(searchTerm.ToLower())));
Run Code Online (Sandbox Code Playgroud)
What I need is if someone searched for "search term" results should be:
"terms of search" "another search term"
I am not sure the best way to go about this in linq can anyone help please?
//split the search terms by space
var searchWords = searchTerm.ToLower().Split( " ".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
//check if any of those search terms is present
list.Where(x => x.MyList.Any(y =>
searchWords.All(sw=>y.ToSearch.ToLower().Contains(sw))));
Run Code Online (Sandbox Code Playgroud)