Let's say I have Search API set up and connected to an AWS hosted Elasticsearch cluster and am using the elasticsearch_connector module along with Facets. Everything is good in regards to that, so far.

I have a facet created based upon content type, and this is working great. I need to merge a few content types, however, into a single facet. For example, right now I see the following facets when on my search results page:
-PDFs
-TXT files
-Spreadsheets
-News

I want to be able to link the first three of the ones listed above, or more than 3 (any number) into a single facet (plus the news one should still stay there) simply like this instead:
-Documents [pdfs, txt files, and spreadsheets all become one facet]
-News

If anyone could assist with this, it would be greatly appreciated. I've done this in the past using hooks from Drupal 7, but not having much luck so far with what I'm doing trying to make a new facet processor.

Can anyone point me in the right direction?

Comments

brettboylen created an issue. See original summary.

borisson_’s picture

Using a Search API aggregated field is what you're going to want to do here. Looks like we have a documentation gap there that I can't seem to find on drupal.org. However, that is the way forward for you.

You should be able to add a new field in search api that aggregates all the fields that you want to have combined and create a new facet on that field.

It is probably a good idea to add this in the FAQ-section of the readme of this module as well as on the drupal.org documentation of Search API.

borisson_’s picture

Status: Active » Fixed

Closing this as fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mpp’s picture

Perhaps you could create a custom field (addFieldValues) or alter the existing bundle property (alterIndexedItems).

Steven Buteneers’s picture

I don't really see how an aggregated field is going to help here, as we are dealing with a single field (Content Type)
The goal is to merge different content types into a single facet (checkbox) and that's not possible with the proposed solution

borisson_’s picture

Facets just reads the indexed values, so if you want to have multiple things combined into one item, they should be combined in the database. So altering the index process so that we have a field with the right data is the way to go.

jennypanighetti’s picture

I have a similar issue, where I want to combine several node types into a single "Other" option in the facet. Were you able to come up with a solution?

keboca’s picture

Guys, perhaps it can help you somehow: https://www.drupal.org/project/facets/issues/3133309

cristian100’s picture

One way to solve this, is by creating a custom field.. lets name it "Content Type" [field_content_type].

Then, using the hook_update, we track and hardcode groups of content types and save it into the field_content_type, example:

Content Types:
* page => pages
* article => articles
* event => articles
* landing_page => pages

This way, we have two possible group of Content Types, which are "Pages" and "Articles".

After this, we create a Facet based in field_content_type, and finally we have merged content types.