November Happy Hour will be moved to Thursday December 5th.

How to disable Find indexing on specific products

Vote:
 

Hi guys, 

I would like to find a way to exclude some products(VariationContent) in the Find search result, the products which are located in a not active category (set as NOT available in commerce)

In CMS I can add a bool DisableIndexing in a page type, do I need to do silmiar thing and build a job to set disableIndexing = true to the products?

Please provide me some suggestions.

Thanks 

#197092
Sep 21, 2018 10:15
Vote:
 

You can do like this - just change the code inside ShouldIndex to what you would like 

ContentIndexer.Instance.Conventions
     .ForInstancesOf<VariationContent>()
     .ShouldIndex(x => ShouldIndex(x));
bool ShouldIndex(IContent content)
 {
     var ancestors = _contentLoader.GetAncestors(contentLink).OfType<FashionNode>();
     if (ancestors.Any(c => c.Name == "Mens"))
     {
         return false;
     }
     return true;
 }
#197094
Sep 21, 2018 11:28
Vote:
 

Thank you Quan! 

I will try this solution. :) 

I have other scenario, how shall I do to hide the customer specificed products in search result?

When a customer login, he has customer specified products and he should be able to search it but not anonymous user.

#197095
Sep 21, 2018 11:47
Vote:
 

The new question should be in a separate thread. To you can always filter the search result by adding a property - for example ForRegisteredUserOnly, and use that to filter with Find 

#197096
Sep 21, 2018 11:48
Vote:
 

Sorry, I will open a new thread next time. 

Thanks for the tips!  

#197097
Sep 21, 2018 12:07
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.