Indexing
...
Entities
Categories

Exclude Categories from Search Results

6min

By default, all categories indexed to Klevu have a visibility of search. There are 2 possible approaches to change this depending on your needs. The first is to exclude the category from the sync altogether using an isIndexableDeterminer. The second is to change the visibility sent in the data.

Is Indexable Determiner

Excluding the category this way would result in no products showing for this category on the frontend of your store for Category Navigation.

To do this we inject an isIndexableDeterminer into the isIndexableDeterminers array for the virtual type Klevu\IndexingCategories\Service\Determiner\IsIndexableDeterminer

Vendor/Module/etc/di.xml


Create that class, which must implement the IsIndexableDeterminerInterface

Vendor/Module/Service/Determiner/CategoryIdIsIndexableDeterminer.php


See Entities Is Indexable Determiner for more information.

Change Visibility in the Synced Data

To change the data synced we must override the pipeline YAML for categories.

Create the override YAML file

Vendor/Module/etc/pipeline/add_update.yml


Create the imported visibility YAML file. It is possible to do this all in one YAML file, but separating it into multiple files makes it easier to read. To remove all categories from search.

Vendor/Module/etc/pipeline/category/attributes/visibility.yml


To remove some categories from search. Take the current category and pass it into a transformer. This transformer should return an array of strings containing with or search.

Vendor/Module/etc/pipeline/category/attributes/visibility.yml


Create the transformer to handle the visibility

Vendor/Module/Pipeline/Transformer/ToVisibility.php


If you create a transformer in a custom module it must be registered with the pipelines before it can be used. See Registering Transformers for more information.

Alternatively we could add an attribute to the category for visibility and use that instead of a transformer. e.g.

Vendor/Module/etc/pipeline/category/attributes/visibility.yml


Assumes getVisibility would return either or search. If it returned an integer then we'd have to map that. see the visibility YAML for products module-m2-indexing-products/etc/pipeline/product/attributes/visibility.yml

See Pipeline Customisation for more information on how to customise pipelines.