Facet process to merge node types

Created on 4 May 2020, almost 5 years ago
Updated 21 June 2023, almost 2 years ago

I would like to propose a new processor to merge facets together. While I was working in a case where I had to do it, I walked throught different places however I didn't see a generic solution provided out-of-the-box from Facets module per se.

Then I came with my solution and I would like to share here. The code I wrote I have some details here: https://www.keboca.com/drupal-8-merge-facets-together

Plus it is possible it would help as well on the following closed tickets:
How can I merge combine facets in drupal 8 Search API and Facets β†’
Trying to merge multiple content types into a single facet via a facet processor plugin β†’
How can I merge or combine facets?

I'm leaving here a path which allows to create facet groups based on current content types.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡·Costa Rica keboca

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States jiong_ye

    Ran into this issue https://www.drupal.org/project/facets/issues/3368327 πŸ› Facets Pretty Paths module and Merge node types processor error Active
    Updated the patch slightly.

  • πŸ‡ΊπŸ‡ΈUnited States jiong_ye

    renamed the patch

  • πŸ‡ΊπŸ‡ΈUnited States mgaskey

    Re-rolled the patch in #14 to improve the language used in comments and the UI. The functionality works great in the original patch.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.1 & MySQL 5.5
    last update over 1 year ago
    Composer require failure
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • πŸ‡ΊπŸ‡ΈUnited States thomps9012

    For context we're using version 2.0.6 of facets, solr / solr cloud, and json:api search index.

    Here's what we're seeing for the url of our merged node facet (in the metadata section of our json:api response):

    https://base_url.com/jsonapi/index/solr_node_index?filter[facet_group]=facet_item&filter[0]=facet_group:facet_item&filter[1]=facet_group:facet_item
    

    Which is not a clickable link.

    Our patch corrects the generated url to the below:

    https://base_url.com/jsonapi/index/solr_node_index?filter[facet_merged_name][condition][path]=facet_group&filter[facet_merged_name][condition][value][0]=facet_item_1&filter[facet_merged_name][condition][value][1]=facet_item_2&filter[facet_merged_name][condition][value][2]=facet_item_3
    

    Which is a clickable link

    Hopefully this patch helps resolve this issue for some others, if not

  • πŸ‡ΊπŸ‡ΈUnited States thomps9012

    FYI the interdiff is in the previous comment and file 3133309-18.patch attached to this comment is the actual patch

  • πŸ‡ΊπŸ‡ΈUnited States thomps9012

    Resolution to patch 19 which was attempting to pass the translate object as a query parameter

  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ

    We already have a combine facets processor in 3.0.x. doesn't it solve the requirements here?

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @mkalkbrenner the use case here is a common requirement by clients to group content types (and other fields) together in the same value for filtering, for example to produce a checkbox widget like so:

    [ ] Latest
    [ ] Articles
    [ ] Documents

    Where Latest are from content types blog and news, Articles are from content type article and page, and Documents are from document and file content type (just a quick example).

    This can be done either at index time with a computed field or something, or at search time, with the work on this patch, I don't think it's the same as combining facets.

  • πŸ‡΅πŸ‡­Philippines _renify_ cebu

    This works on my end.
    Use the query params which compatible to $filter_key & $filter_name.

    Facets selected:
    article -> Page
    page -> Page
    news -> News

    It should look like this:
    /search?f[0]=type:article&f[1]=type:page&f[3]=type:news

  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    @_renify_: Mind summarizing your changes?
    Here's the interdiff between patches #20 & #23.
    We've been using the patch in #20 successfully for a year now.

  • In patch #23, you cannot uncheck the merged items once you select them. #20 works as expected

  • πŸ‡ΊπŸ‡ΈUnited States cscottjames

    Similar to @dxvargas 's comment above: I need a similar solution, but for media bundles (not node types). Were this feature merged into the Facets module, it would be nice to incorporate other bundle types into this.

  • πŸ‡ΊπŸ‡ΈUnited States micnap

    I couldn't get #23 to work. Once the combined node type filter was checked, I couldn't uncheck it. So I went back to #20. That didn't work but it was because the query parameter didn't work. Revised the query parameter. Here's what's working for me. We're using the checkbox filter and combining 4 different node types into a single type called "Page". Here's the patch and interdiff.

  • πŸ‡²πŸ‡ΎMalaysia ckng

    Same observation as #27 and patch #27 is working for us.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    This is very cool, and works great actually!

    However, a few observations:
    - This should be a MR so it's much easier to review/work on.
    - In the latest patch, there are quite a few unused variables (e.g $facet_string and $updated,...)
    - I'm not convinced of the config UI. It's tedious if you want to remove the first item in a long merge list since you can only remove the last one.
    - Sorting is an issue, I would have expected to have the filters in the same order as they are entered in the config form when no sorting is being applied to the facet, or when you select "order by display weight". This also brings me to previous point that you can't change the weight/order in the current UI.

  • Pipeline finished with Canceled
    4 months ago
    Total: 579s
    #366806
  • Pipeline finished with Canceled
    4 months ago
    Total: 400s
    #366816
  • Pipeline finished with Canceled
    4 months ago
    Total: 195s
    #366823
  • Pipeline finished with Failed
    4 months ago
    Total: 695s
    #366830
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Tackled the following:

    -
    Created a branch MR combo for 2.0.x and 3.0.x

    -

    Removed unused variables and injections.

    - I'm not convinced of the config UI. It's tedious if you want to remove the first item in a long merge list since you can only remove the last one.
    -

    Since the config is loaded in the order it's entered, I'm that in a basic way. For 2.0.x I'm just misusing the termWeight property which is not used for none taxonomy facets. For 3.0.x it's properly using the set() function to do dynamic stuff. After which I can sort the facets array on set value.

    -

    Added an ID field which is used to set the setRawValue. Added a public method for this as it was a protected variable. I think it's ok to do that in this instance since we're creating a "new" facet based of an existing one. Made all fields required, I can't see a use case where you would not want to change any of the 3 form values. Not changing the ID can also result in conflicting grouped filters where the same first content type is selected as the ID which is solved by forcing an ID. You can of course still mess that up by entering the same ID multiple times. I did not invest time into looking for a machine_name field.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    And probably could use a test :)

  • Pipeline finished with Failed
    4 months ago
    Total: 721s
    #366848
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ
  • Pipeline finished with Failed
    4 months ago
    Total: 790s
    #366868
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Just came to the conclusion that setting the raw value does not work like I expected it to.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    This also doesn't play nicely with other facets or an exposed fulltext search. It's overriding the complete query with only that of this facet.

  • Pipeline finished with Canceled
    4 months ago
    Total: 73s
    #370155
  • Pipeline finished with Canceled
    4 months ago
    Total: 135s
    #370157
  • Pipeline finished with Failed
    4 months ago
    Total: 225s
    #370159
  • Pipeline finished with Failed
    4 months ago
    Total: 711s
    #370161
  • Pipeline finished with Failed
    4 months ago
    Total: 901s
    #370216
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    #35 and #36 are addressed. Maybe not in the ideal but this is working for my use case.

    That just leaves :

    I'm not convinced of the config UI. It's tedious if you want to remove the first item in a long merge list since you can only remove the last one.

    And perhaps the changes from a textfield to machine name field or at least adding a warning a ID should not be the same as an existing facet value and not the same between groups.

  • Pipeline finished with Failed
    4 months ago
    Total: 653s
    #370260
  • Pipeline finished with Failed
    4 months ago
    Total: 734s
    #373816
  • Pipeline finished with Failed
    4 months ago
    Total: 729s
    #373819
  • Pipeline finished with Failed
    8 days ago
    Total: 986s
    #463115
  • Pipeline finished with Failed
    8 days ago
    Total: 797s
    #463117
  • Pipeline finished with Failed
    7 days ago
    Total: 303s
    #463206
  • Pipeline finished with Canceled
    7 days ago
    Total: 292s
    #463208
  • Pipeline finished with Canceled
    7 days ago
    #463212
  • Pipeline finished with Failed
    7 days ago
    Total: 639s
    #463211
  • Pipeline finished with Failed
    7 days ago
    #463219
  • Pipeline finished with Failed
    7 days ago
    Total: 871s
    #463218
  • Pipeline finished with Success
    7 days ago
    Total: 820s
    #463297
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    fixed a few things.

Production build 0.71.5 2024