HS indirectly responsible for changing a vocabulary's "hierarchy" value -> faceted search stops showing a hierarchy of terms
| Project: | Hierarchical Select |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | minor |
| Assigned: | Wim Leers |
| Status: | closed |
I have a hierarchical vocabulary as follows:
term 1
- sub-term 1
- sub-term 2
term 2
- sub-term 3
I use faceted search to drill down to the sub terms, this search will first display the top level of the vocabulary - term 1 and term 2, and then if one of those terms is selected, it will display that term's sub terms (e.g. sub-term 3).
When I enable hierarchical select for the vocabulary ('Use the Hierarchical Select form element for this vocabulary') all the terms in the vocabulary are now displayed as a flat list in faceted search (i.e. term 1, sub-term 1, sub-term 2, term 2, sub-term 3) and drill down no longer works.
I notice that the act of enabling hierarchical select changes the value of 'hierarchy' in the vocabulary SQL table from 1 to 0. Changing this back to 1 restores the desired drill down behaviour for faceted search without appearing to affect the behaviour of hierarchical select for vocabulary selection when creating new content.

#1
I created a simple module with the code as follows which appears to solve the problem I was having and allows faceted search to operate properly on hierarchical vocabularies when hierarchical select is enabled for a vocabulary:
<?php
// $Id$
/**
* @file
* Preserve the type of hierarchy
*/
/**
* Implementation of hook_form_FORM_ID_alter
* find the original value of 'hierarchy' in the vocabulary table for
* this vocabulary before admin/content/taxonomy/edit/vocabulary/VOCABULARY_ID
* saves
*/
function preserve_hierarchy_form_taxonomy_form_vocabulary_alter($form, $form_state){
//get the current value for hierarchy in the taxonomy table
$vocabulary_name = $form_state['post']['name'];
if (($unaltered_vocabulary_hierarchy = db_result(db_query("SELECT hierarchy FROM {vocabulary} WHERE name='%s'",$vocabulary_name))) !== FALSE){
variable_set('preserve_hierarchy_unaltered_vocabulary_hierarchy',$unaltered_vocabulary_hierarchy);
}
else {
variable_set('preserve_hierarchy_unaltered_vocabulary_hierarchy',1);
}
}
/**
* Implementation of hook_taxonomy:
* re-instate the original value of 'hierarchy' in the vocabulary table
* after it has been modified
*/
function preserve_hierarchy_taxonomy($op, $type, $array = NULL) {
if ($op == 'insert'||'update' && $type == 'vocabulary'){
$unaltered_vocabulary_hierarchy = variable_get('preserve_hierarchy_unaltered_vocabulary_hierarchy',1);
db_query("UPDATE {vocabulary} SET hierarchy=%d WHERE name='%s'", $unaltered_vocabulary_hierarchy, $array['name']);
}
}
#2
Weird. That doesn't happen here. All I'm doing is:
<?php
/**
* Additional validate callback for the taxonomy_form_vocabulary form.
*/
function hierarchical_select_taxonomy_form_vocabulary_validate($form, &$form_state) {
// The "multiple select" setting doesn't exist for the forum vocabulary!
if (isset($form['multiple'])) {
// Enable Taxonomy's "multiple select" setting when:
// - Hierarchical Select's "multiple select" setting is enabled, or:
// - Hierarchical Select's "save term lineage" setting is enabled
$multiple_select_enabled = ($form_state['values']['hierarchical_select']['dropbox']['status'] || $form_state['values']['hierarchical_select']['save_lineage']);
form_set_value($form['multiple'], (int) $multiple_select_enabled, $form_state);
}
// If Hierarchical Select is enabled, disable freetagging.
if ($form_state['values']['hierarchical_select']['status']) {
form_set_value($form['tags'], 0, $form_state);
}
}
/**
* Additional submit callback for the taxonomy_form_vocabulary form.
*/
function hierarchical_select_taxonomy_form_vocabulary_submit($form, &$form_state) {
$vid = $form_state['values']['vid'];
variable_set("taxonomy_hierarchical_select_$vid", $form_state['values']['hierarchical_select_status'], $form_state);
}
?>
So if the hierarchy property is being changed of the vocabulary, this must trigger some incorrect behavior of the Taxonomy module.
#3
Closing due to lack of response. Feel free to reopen.
#4
Thank you for this - and sorry for raising it as on further investigation I now realise that the problem is being created somewhere else - not quite sure where yet though.
#5
This is indeed a problem. For a while I couldn't understand why on one site the parent terms show correctly with drill down and other sites all the children show with no drill down.
I have a live site with only Faceted search and no HS installed and parent terms show with drill down.
On the dev version of the site, it was also working properly until I now installed HS. After that, all the children show. See images (site is not English).
Disabled HS did not make a difference.
Deleted HS from server made no difference.
Removed variables starting with hs_ still no difference.
Cleared cache, no difference.
Something else must have changed.
Next week I'm restoring the dev site db with a backup from the live site, will see if that helps. But before then, if you want me to check/test something, let me know.
I realise this could be a Faceted search problem, but let's see before we pass it on.
#6
HS doesn't change anything about the way terms are stored. All HS settings affect only HS itself, not Taxonomy settings (except for the "multiple" and "required" settings, which may be changed by HS to allow for the HS settings to work).
Weird problem … I hope you can narrow it down :)
#7
I am/was having the same problem as you mentioned and changing the value in the DB fixed it for me.
I was unsure how to use the code you provided so I was unable to implement that.
Do you know what module settings (if any) will change the 'hierarchy' value in the vocabulary table from 1 back to 0? I want to make sure that I always check that if I update my settings.
Thanks,
Eric
#8
I've just looked into Taxonomy's code and apparently the hierarchy setting (0 = flat, 1 = single hierarchy, 2 = multiple parents) can be changed at multiple locations:
1) in taxonomy_form_term_submit(), through taxonomy_check_vocabulary_hierarchy()
2) in taxonomy_term_confirm_delete_submit(), through taxonomy_check_vocabulary_hierarchy()
3) in taxonomy_overview_terms_submit() (which is called when you rearrange terms through the term reordering form ('list terms') and click submit) — this one is special because it assumes you can only have hierarchy = 0 or 1, not 2, because the interface itself doesn't allow for multiple parents
I'm assuming you did neither of the first 2, the third seems most likely. The final detective work is up to you.
#9
Closing due to lack of response. Feel free to reopen.
#10
Hi. I'm very bad in changing the code into the modules.
Can you please tell me how to solve the problem, concretly ? By adding some lines in taxonomy.module file ?
Thank you.