简体   繁体   中英

LINQ - Comparing a search term with multiple entries against another string with multiple entries

I have a column called Title in the DB.

and i have a search term coming from the app.

What i have done so far is this:

var valsSearch = value.searchTerm.ToLower().Split(" ");
var results = ctx.Links.Select(x =>x.Title).Where(x => valsSearch.Contains(x)).ToList();

For example the Title in the DB might be "Ronaldo scores a hattrick" and the searchTerm may be "scores ronaldo"

How do i filter the results when comparing the Title in DB to the searchTerm?

The result should be that the searchTerm when separated are used to filter the values in the Title DB and if there's a match return the result.

Try this,

var valsSearch = value.searchTerm.ToLower().Split(" ");
var results = ctx.Links.AsEnumerable().Where(x => valsSearch.Any(y => x.Title.ToLower().Contains(y))).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM