ninjanye / SearchExtensions

Library of IQueryable extension methods to perform searching
MIT License
331 stars 52 forks source link

Searching multiple column with different criteria. #44

Closed charlondelacruz closed 3 years ago

charlondelacruz commented 3 years ago

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();

ninjanye commented 3 years ago

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.