A cool feature would be to automatically split up a hierarchical vocabulary so every level gets its own facet block and custom label. I see this module already has an option to rewrite a single facet. So we're already half way there. How hard would it be to generate a facet block for each level?

This option would be especially handy for product categories where terms can have multiple parents like "size" or "color". If displayed in seperate blocks it's much more clear to the user how to navigate through the facets instead of navigating through a huge tree facet where terms are displayed multiple times...

I'm willing to help out on coding if someone has an idea on where to start :)

CommentFileSizeAuthor
#5 1493326-4.jpg71.68 KBcpliakas

Comments

danielnolde’s picture

Sounds definitely interesting, and like a good addition to facet_api_bonus!
Personally i have no experience on hierarchical taxonomy facets, so i'm not of great help in coding this.
Perhaps Chris Pliakas from facet_api has a hint for you where to begin?

merilainen’s picture

Also interested to implement this.

Or another approach to at least give some option add markup to the massive "ul li" structure, which is difficult to theme at the moment, because the ul and li-elements don't have anything to grab with css selectors. If each level gets its own block, some massive categories will flood your blocks list.

ygerasimov’s picture

Project: Facet API Bonus » Facet API

I don't think this issue is addressed to Facet API Bonus module as it only implements filters, dependencies etc. Here you ask to build custom taxonomy facet. I think this should be either separate contrib module or be considered by facet_api module itself.

Chris please advise what do you think about this?

cpliakas’s picture

This is a pretty cool feature. I would say, thinking off the top of my head, that the current architecture isn't geared towards this type of thing. It is more focused on gathering data from a Solr field and faceting on that.

With that being said, I think we can probably hack our way around this using hook_facetapi_facet_info_alter() and filters. The short explanation is that we could clone the taxonomy facet 1 per level. So if we want to have three blocks for a three level hierarchy, we could do the following:


/**
 * Implements hook_facetapi_facet_info_alter().
 */
function mymodule_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
  if ('apachesolr' == $searcher_info['adapter']) {
    // Clone the taxonomy facet.
    $facet_info['im_field_tags_1'] = $facet_info['im_field_tags'];
    $facet_info['im_field_tags_2'] = $facet_info['im_field_tags'];

    // Change the label so we know which level we are working with.
    $facet_info['im_field_tags']['label'] .= ' (Top level)';
    $facet_info['im_field_tags_1']['label'] .= ' (Second level)';
    $facet_info['im_field_tags_2']['label'] .= ' (Third level)';

    // Change the name so that each facet is seen as unique.
    $facet_info['im_field_tags_1']['name'] = 'im_field_tags_1';
    $facet_info['im_field_tags_2']['name'] = 'im_field_tags_2';
  }
}

The code is specific to Apache Solr Search Integration but could probably be generalized and made available to other backends. Regarding the filters, we already have a filter in core Facet API that only displays the current level of the hierarchy. I don't see why we couldn't implement a filter with a condition that provides an option to "Only filter results in the Nth level of the hierarchy.". Then we would be done.

Would love to get someone to prototype this, and it could be a cool add-on module.

Chris

cpliakas’s picture

StatusFileSize
new71.68 KB

Attached is a screenshot of the "clones" taxonomy facets. Via the UI you could configure the hierarchy level filter for each facet.

1493326-4.jpg

androidado’s picture

Hello, How Can I achieve that? Itś done in the UI?

Looking in the screenshot, it is showing the same options in the 3 levels,
> droswowra 26
> uiv 19

Are you sure it is working?

cpliakas’s picture

Hi androidado.

As mentioned in #1493326-4: Split hierarchical taxonomy in multiple facets.:

I don't see why we couldn't implement a filter with a condition that provides an option to "Only filter results in the Nth level of the hierarchy.". Then we would be done.

So that is the missing piece. Someone is going to have to do a little leg work to push this through, but at the end of it will have a nice little module to maintain and contribute back.

Chris

sebas5384’s picture

This is great! also needed something like this in my project, so probably I'm going to do some hacking and try to send a nice patch to make this happen.

In my case, I need something like the menu_block in a form of a facet widget, where can be set the parent term or level to start showing the terms.

But first, i would like to ask you guys some orientations about things like AND/OR between the generated blocks, query being build, UI or performance issues.

Cheers!

drclaw’s picture

Hello all,

The code snippet from comment #4 was very helpful! Thanks @cpliakas!

I wrote a filter plugin for facetapi_bonus to take care of the depth issue. The patch is here: #2056099: Add a filter plugin to only show items from a specific depth

Hope this helps someone!

drclaw

mokargas’s picture

Was this ever completed? Currently looking for a way to make a system identical to cpliakas 's screenshot from one taxonomy with nested parents.

jordiserra’s picture

any news on this issue?

marcoka’s picture

Issue summary: View changes

a cloning feature for all facets would be verry useful. not only to split up taxonomy.

lets say for example you have a page where you filter and the facets are dependent on each other. on another page you want to show them all without dependecies or differend widgets.

thats not possible because if you set a block to use widget select you can not change that on another page.

29axe’s picture

Could be a good feature

pyxio’s picture

does this solution only work for apachesolr module? is there a similar solution for search_api_solr?

maxplus’s picture

Yes,
it would be great to have a similar feature like menu block to split up a taxonomy vocabulary into multiple facets, like described in #8