Hi,

I find this module really great ! For a project I'm currently working on, I had to provide several links to "filter" the results for each content type on the search-results page. I was wondering if you'd be interested in adding it to the module.

My code is the following :

function custom_search_preprocess_search_results(&$variables) {
  // Get search words (minus type:node_type)
  $keys = search_get_keys();
  if (strpos($keys, 'type:') !== FALSE) {
    $keys = substr($keys, 0, strpos($keys, 'type:')-1);
  }
  // Get Custom Search authorised types
  $searchable_node_types = variable_get('custom_search_node_types', array());
  $searchable_node_types = array_keys(array_filter($searchable_node_types, 'custom_search_filter_array'));
  $node_types = db_query("SELECT type, name FROM {node_type} WHERE type IN (". db_placeholders($searchable_node_types, 'varchar') .")", $searchable_node_types);
  // Build menu
  $items = array();
  $items[] = l(variable_get('custom_search_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT), 'search/node/'.$keys);
  while ($node_type = db_fetch_array($node_types)) {
    // FIXME : add active class when needed...
    $items[] = l($node_type['name'], 'search/node/'. $keys .' type:'.$node_type['type']);
  }
  $variables['custom_search_menu'] = theme('item_list', $items);
}

The filter_array method is :

/**
 * Function used to filter node_type array to only filter those that are configured in Custom Search Form
 */
function custom_search_filter_array($value = FALSE) {
  return $value !== 0;
}

The only thing left to do is adding

<?php print $custom_search_menu; ?>

to the search-results.tpl.php

I'm sure can integrate it better in your module, I just wanted to share what I have done. If you're interested and I make it better during the project, I'll come back and provide a patch.

Best regards

Comments

Simon Georges’s picture

Status: Active » Needs review

Changing the status to have the opinion of the maintainer about the idea (and eventually the code).

jdanthinne’s picture

I'll have a look at this within the next days, and I'll keep you informed.
Thanks.

jdanthinne’s picture

Status: Needs review » Needs work
jdanthinne’s picture

Status: Needs work » Fixed

Ok, I've added this function in the latest release, thanks.
But instead of dealing with templates files, I've added an option to display the filters above or below the results.

Simon Georges’s picture

I hadn't thought of that at all, but I like the approach, it's easier to use for non-developper people. Nice job !

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

interestingaftermath’s picture

Status: Closed (fixed) » Needs review

I appreciate this feature but for some reason the filters do not show on every results page. They seem to only appear when more than one content type is represented on a page. Has anyone else had this problem?

In short, the "filter results" only filters that page's results and not ALL the results.

jdanthinne’s picture

Fixed that in the DEV version.
Please review.

interestingaftermath’s picture

The issue of the filters only showing on certain pages seems to be resolved. The next question is, if the results only feature 1 content type, should it show the filter at all?

jdanthinne’s picture

Status: Needs review » Closed (fixed)

Fixed in DEV version. Filter is hidden when there's only one content type.