ninjanye / SearchExtensions

Library of IQueryable extension methods to perform searching

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Searching multiple column with different criteria.

charlondelacruz opened this issue · comments

First, of all I would like to thank you for this awesome library. I've been using this library just recently and it works great on my end.

I just want to ask if this kind of search is supported. I tried the chain search but no luck maybe because I'm missing the OR clause.

var total = context.Products.Where(x => keywords.All(k => x.Name.Contains(k)) || keywords.Any(k => x.SkuId.Contains(k))).Count();

Hi @charlondelacruz

Thanks for getting in touch... unfortunately there is currently no easy way to perform the search above in one line of code in SearchExtensions... the best I think you can do is as follows:

    var named = context.Products.Search(x => x.Name).ContainingAll(keywords);
    var skuMatch = context.Products.Search(x => x.SkuId).Containing(keywords);

From here you could merge the two collections, deduplicate based on SkuId and grab your count, however it does result in an extra call to the db so would likely lose you some efficiencies.