Search based on a set of keywords

前端 未结 7 1081
慢半拍i
慢半拍i 2020-12-31 08:52

I need to make a search based on a set of keywords, that return all the Ads related with those keywords. Then the result is a list of Categories with the Ads Count for each

7条回答
  •  甜味超标
    2020-12-31 09:35

    I haven't compile-checked this or anything, so it may require some tweaking, but you're looking for something along these lines.

    var matchingKac = keywordIds.Distinct().ToList()
        .Aggregate(
            keywordAdCategoryQuery.AsQueryable(),
            (q, id) => q.Where(kac => kac.Keyword_Id == id));
    

    You're effectively saying, "Start with keywordAdCategoryQuery, and for each keyword add a .Where() condition saying that it must have that keyword in it. You could do the same thing with a for loop if you find Aggregate difficult to read.

提交回复
热议问题