When a user's current listing is only showing 1 item, it doesn't seem to make sense to allow the user to attempt to further refine their search with terms attached to that item, because it will only ever show that item until the first term is removed.

For example, if taxonomy filter is in AND mode, and if a node is the only node tagged C, but node is also tagged with A and B, if C is selected in the current search, terms A and B show in 'refine search' as A[1] B[1], which can look a bit strange especially if the node is tagged with many other terms. It would seem better that in this case, and C is selected, the user should be advised to instead remove that term from their search before they can continue refining it.

The issue would also occur if taxonomy filter were set to only show terms with, for example, 2 nodes. If term C has two nodes and it is selected, the user would be able to continue refining to terms tagged in both those nodes, but get nowhere. A bit like being at the end of the road, but the taxonomy filter interface suggests you can still progress further.

Can anybody think of a solution to stop this happening?

Comments

Ela’s picture

subscribing... would also like to know a solution for this.

lightsurge’s picture

Edit: function _taxonomy_filter_tids_upto might be a useful function to alter if we're using the basic 2 term refining, but not if we're using tf_multi

lightsurge’s picture

Is there a function better than 'taxonomy_select_nodes' that I could use to count the number of nodes with an array of attached terms?

I figure if we count the number of nodes attached to an array of terms, and if this equates to taxonomy filter's variable from 'display terms only if attached to X nodes' setting, then we can return NULL in above IF statement?

Therefore, if we've set this to 1, term C has 1 node but is also tagged with A and B, term C is selected, no refine links are displayed.

lightsurge’s picture

Managed to bend this to my will with a very rough hack. I'm using tf_multi/tf_count, so it turned out that the above wasn't relevant after all. I wanted to remove irrelevant refine links where 1) we're already at the minimum display of nodes 2) even if we're not at the minimum display of nodes, remove the refine links if they point to the same nodes. Below code is really unlikely to work for everyone, and obviously definitely not if they're not using tf_multi. I'm also only using the Cloud template so that might impact. Needs a lot of work if it's to become added if it even should be, obviously.

I added this function to get a count of nodes associated with an array of tids:

function taxonomy_filter_taxonomy_count_url ($tids) {
$joins = '';
$wheres = ' WHERE';
$ttotal = count($tids);
foreach ($tids as $key => $tid) {
        $joins .= ' INNER JOIN term_node term_node_value_'. $key .' ON node.vid = term_node_value_'. $key .'.vid AND term_node_value_'. $key .'.tid = '. $tid;
if ($key == $ttotal-1) {$wheres .= ' (term_node_value_'. $key .'.tid = '. $tid .')';}
else {$wheres .= ' (term_node_value_'. $key .'.tid = '. $tid .') AND';}
      }
$wheres .= ' AND node.status = 1 AND node.moderate = 0';
$sql='SELECT COUNT(DISTINCT(node.nid)) AS nid FROM node node '. $joins . $wheres;
return db_fetch_object(db_query($sql))->nid;
}

Called it just after the $block variable being established in taxonomy_filter_block_refine (taxonomy_filter.module), saving the result in $block['info']['urlcount']:

  $block['info'] = array(
    'url_tids' => $url_tids,
    'url_depth' => $url_depth,
  );
$tids = $block['info']['url_tids']; 
$block['info']['urlcount'] = taxonomy_filter_taxonomy_count_url($tids);
 $sections_info = taxonomy_filter_sections_refine($block['info']);

Then messed about with the sections of IFs in the tf_multi_tf_item_alter hook of tf_multi.module:

// Move here from tf_multi_tf_section_alter.
$tids = $block_info['url_tids'];
$minimum_node_count = $section_info['section_settings']['tf_count']['minimum_node_count'];
// If we're already displaying the minimum number of nodes possible with the current refinement...
if ($block_info['urlcount'] == $minimum_node_count) {
if (in_array($item['info']['item_tid'], $tids)) {
// but the item we're looking at is in the url then establish a link to remove it
    $link_tids = array_diff($tids, array($item['info']['item_tid']));
}
// if item not in the url then don't create a link at all
else {$link_tids = array_diff(array($item['info']['item_tid']), array($item['info']['item_tid']));}
// but give both selected status - this might not work for all uses
    $item['info']['tf_multi']['selected'] = TRUE;
}
// if terms are in url don't have min node count create link and mark selected
else if (in_array($item['info']['item_tid'], $tids)) {
    // Item is selected.
    $link_tids = array_diff($tids, array($item['info']['item_tid']));
    $item['info']['tf_multi']['selected'] = TRUE;
  }
// otherwise create link and mark unselected
  else {
    $link_tids = array_merge($tids, array($item['info']['item_tid']));
    $item['info']['tf_multi']['selected'] = FALSE;
  }
// finally we don't want to make links clickable that only have the same nodes attached as the terms in the url even if it can be further refined by others
if (!in_array($item['info']['item_tid'], $tids)) { 
if ($item['info']['tf_count'] >= $block_info['urlcount'])
 {
// but if only 1 term is in the url and all terms in taxonomy filter relate to the same nodes, we want to allow the user to 'switch' to a different term, abandoning the currently selected term
if (count($tids)==1) {
$link_tids = array($item['info']['item_tid']);
$item['info']['tf_multi']['selected'] = FALSE;
}
else {
$link_tids = array_diff(array($item['info']['item_tid']), array($item['info']['item_tid']));
$item['info']['tf_multi']['selected'] = TRUE; }
}
}


if ($settings['sort_terms_in_url']) {
    // Sort tids in link for SEO purposes.
    // @todo Add a hook to allow for custom sort routines?
    sort($link_tids);
  }
lightsurge’s picture

Category: support » feature

Is there any interest in adding something like this to the module in order to remove not-needed links from the filter?