Support Views Exposed Filters with Faceted Search
| Project: | Faceted Search |
| Version: | 6.x-1.x-dev |
| Component: | Views integration |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Jump to:
I really like this module and have been playing around with it quite a bit now. Trying to create a perfect search setup for my current project, I've also been using views_fastsearch and views_filterblock to create some other cool search functionality, and now I was wondering if there was a straight-forward way of combining the functionality of the two things?
I.e. creating a view with exposed filters and using that view as output for a particular facet search environment, and then being able to use the exposed filters (as a block) like any other elements of the faceted search.
I suppose this must be possible by writing a view_filter_facet.module, but not entirely sure how to go about this. If there is more general interest in such a feature (and not a more obvious solution around already), I'd be happy to sit down and write this module -- some help / pointers as to how to go about this would always be appreciated, though.
kmh

#1
I guess one way to implement this would be to theme the guided search block so that it consists of fieldsets for each of the facets.
I have just been looking at this today, it appears we are looking at overriding theme_faceted_search_ui_categories($facet, $categories, $stage) - Im totally in the dark about where to go forward from here, but ill keep plugging away....
#2
Ultimately, what is really needed is #256958: Guided search based on a view. But other than that ideal solution, perhaps Faceted Search's views integration could be strengthened to support exposed filters. However, I have not investigated this issue at all, so at the moment I have no idea what it entails.
#3
#4
Hi,
I was disappointed to see the exposed filters doesn't filter the output of faceted search. Later I found that the problem can be solved by modifying the attribute 'action' of the filters' form. Just copy the below code to your theme's template.php and then change VIEWNAME to the name of your view.
<?phpfunction phptemplate_views_display_filters_VIEWNAME($view) {
$form = drupal_retrieve_form('views_filters', $view);
$form['#action'] = request_uri();
drupal_process_form('views_filters', $form);
return drupal_render_form('views_filters', $form);
}
?>
Tim
#5
.
#6
You can get views exposed filters to work.
<?phpfunction YourCustomModuleName_form_alter(&$form, $form_state, $form_id){
if($form['#id'] == 'views-exposed-form-searchfview-default'){
$form['#action'] = request_uri();
}
}
?>
put the above snippet in any module (note that it should NOT go into template.php in your theme folder). Substitute
views-exposed-form-searchfview-defaultwith the id of your exposed filter and you will be able to run a run a views filter with faceted search. Checked with drupal 6.10 and faceted search with views integration.Also see http://drupal.org/node/236162
#7
Awsome if this works! Havn't tried it yet. Exactly where can i put this snippet? my themes template?
#8
This snippet should be placed in a custom module that you can create -- that will take hardly 5 mins to create. It should not go in phptemplate. The snippet will not work there.
#9
It would not be too hard to implement a generic equivalent to this snippet in faceted_search_views.module...
The only thing I'd worry about is altering the form even when the view is used outside of Faceted Search. This is probably something we'd want to prevent, perhaps by checking the current path?
#10
Here's a hint on how to support exposed filters properly in an embedded view.
The Signup module has used this to solve a similar issue.
#11
exactly how should my module look? I have no experience on making custom modules and i really need my exposed filter view to work with faceted search.
I have an exposed taxonomy filter (id: tid)
any help much appreciated.
#12
Where do you place the code in these hints? (i.e. $view->override_path = 'some path')
#13
subscribing
#14
OK I got it working using the method described in #6 I did have to make a couple of other changes by hooking in template.php
theme_faceted_search_ui_remover_link_current_search() and
theme_faceted_search_ui_category()
function carnal_faceted_search_ui_remover_link_current_search($path) {// TODO: nice default icon instead of 'x'
$options = array(
'html' => TRUE,
'attributes' => array('title' => t('Remove this term')),
);
if (!empty($_GET['date_filter'])) {
$options['query'] = array('date_filter[value][date]' => $_GET['date_filter']['value']['date']);
}
return l('[×]', $path , $options);
}
and a similar fix in the other one (not so clean because it also includes some code to handle realnames)
function carnal_faceted_search_ui_category($category, $path) {
// Note: get_label() is responsible for filtering its returned string.
if ($path) {
$options = array('html' => TRUE);
if (!empty($_GET['date_filter'])) {
$options['query'] = array('date_filter[value][date]' => $_GET['date_filter']['value']['date']);
}
if ($category->_uid) { // author_facet
$user = user_load(array('uid' => $category->_uid));
$target->_name = strip_tags(theme('username',$user));
$label = l(strip_tags(theme('username',$user)), $path, $options);
} else {
$label = l($category->get_label(TRUE), $path, $options);
}
}
else {
$label = $category->get_label(TRUE);
}
// Note: Tooltips rely on class 'faceted-search-category'.
return '<span class="faceted-search-category">'. $label .'<span class="faceted-search-count"> ('. $category->get_count() .')</span></span>';
}
Basically I had to carry the argument from the exposed view over to the link created so that it wasn't lost every time you clicked a new facet or removed an old one.
See http://sf.carnalnation.com/events/results for the working system (it's also been patched to allow multi selects from the same vocabulary but that's another issue entirely).
#15
jpp, this is very specific to your environment i guess, with user facets and date filter.
Is it possible to translate this code to a more generic version?
#16
Sorry, Yes it's specific however I don't have time to do a generic patch, however I wanted to give the pointer so that anybody implementing this has an idea of where to go.
A more generic version would find all the views variables in use and make sure they get carried over into the urls to add/remove facets. It's probably a couple of hours of work but it's a couple of hours I don't have right now.
#17
I understand completely. However, the ability to filter (exposed) faceted search results with the help of your embedded view would be a great feature. Is this possible with only a custom module or do we need to complement the theme?