Try our conversational search powered by Generative AI!

Exclude category from search results

Vote:
 

Hello,

I'm trying to figure out how to perform a Find query that excludes results that have a certain category.  This is proving much more difficult than I initially thought.  From what I can see, the filters are all for the inclusion of results.

I have a block that finds article content.  I'd like to apply a property to say Exclude Category, and exclude all content that has that particluar category from the search results.  For instance "Exclude From Home Page".

Can anyone point me in the right direction for this please?

Cheers,

Mark

#257257
Jun 28, 2021 15:40
Vote:
 

Maybe this off the top of my head if doing a non match on multiple categories

public static ITypeSearch<T> DoesNotMatchCategories<T>(this ITypeSearch<T> search,  CategoryList categoryList) where T : ICategorizable
        {
            var requiredFilter = new FilterBuilder<T>(search.Client);

            foreach (var category in categoryList)
            {
                requiredFilter = requiredFilter.And(x => !x.Category.Match(category));
            }

            return search.Filter(requiredFilter);
        }
#257261
Edited, Jun 28, 2021 16:25
Vote:
 

Scott  Thank you.. I'll try that now.  I thought because Match returned a DelegateFilterBuilder I couldn't negate it.  

Cheers, 

Mark

#257262
Jun 28, 2021 16:43
Vote:
 

Unfortunately that doesn't seem to be working.  Is there a way to output the search query being sent to Find?  I wonder if sorting through that would help.

Cheers,

Mark

#257263
Jun 28, 2021 17:27
Vote:
 

Sorry, this is a steady stream of conciousness.  You logic works.  I stripped out most of the existing logic on the block and excludes the article as hoped.  It seems there is a conflict with other logic on the page and I'm trying to troubleshoot what it's colliding with.

Cheers,

Mark

#257265
Jun 28, 2021 18:15
Vote:
 

Scott,

You helped me a ton, I think I just needed to walk away and drink  a coffee.  I didn't chain the call properly when I tried to implement it, but I did when I stripped everything away.  Phew, mission accopmlished.  Thank you again.

Mark

#257266
Jun 28, 2021 18:32
Scott Reed - Jun 29, 2021 7:34
no worries, it happens to us all :-)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.