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
Comment #2
borisson_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.
Comment #3
borisson_Closing this as fixed.
Comment #5
mpp CreditAttribution: mpp at AmeXio for District09 commentedPerhaps you could create a custom field (addFieldValues) or alter the existing bundle property (alterIndexedItems).
Comment #6
Steven Buteneers CreditAttribution: Steven Buteneers commentedI 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
Comment #7
borisson_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.
Comment #8
jennypanighetti CreditAttribution: jennypanighetti commentedI 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?
Comment #9
keboca CreditAttribution: keboca commentedGuys, perhaps it can help you somehow: https://www.drupal.org/project/facets/issues/3133309
Comment #10
cristian100One 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.