Closed (fixed)
Project:
Custom Search
Version:
6.x-1.1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Mar 2010 at 16:38 UTC
Updated:
26 Oct 2010 at 08:11 UTC
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
Comment #1
simon georges commentedChanging the status to have the opinion of the maintainer about the idea (and eventually the code).
Comment #2
jdanthinne commentedI'll have a look at this within the next days, and I'll keep you informed.
Thanks.
Comment #3
jdanthinne commentedComment #4
jdanthinne commentedOk, 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.
Comment #5
simon georges commentedI hadn't thought of that at all, but I like the approach, it's easier to use for non-developper people. Nice job !
Comment #7
interestingaftermath commentedI 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.
Comment #8
jdanthinne commentedFixed that in the DEV version.
Please review.
Comment #9
interestingaftermath commentedThe 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?
Comment #10
jdanthinne commentedFixed in DEV version. Filter is hidden when there's only one content type.