I'm trying to run an apachesolr powered view programmatically and set a filter in this way

  $item = $view->get_item('default', 'filter', $filter_name);
  $item['value'] = $string;
  $view->set_item('default', 'filter', $filter_name, $item);

Unfortunately the view gets not filtered and no sign of the value in the solr query.

Anyone has done this before with apachesolr views?

Comments

toemaz’s picture

Instead of $view->set_item, the right function is to use $view->set_item_option

  $view->set_item_option($display_id, 'filter', $filter_name, 'value', $value);

While this seems nicely injecting the value in the view, the problem is that apachesolr_views still overrides the injected value by looking at the exposed param using $_GET[$filter_name]. If that param is not available, the value is set on NULL.

So the only way to trick the module without patching it, is to use:

  $_GET[$filter_name] = $value;
drewish’s picture

Title: How programmatically set filter with apachesolr views » Cannot programmatically set filter with apachesolr views
Category: support » bug
Priority: Normal » Minor

Seems like it's a bug to pull directly from $_GET rather than the item option...

kenorb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Version 6.x is no longer supported due to Drupal 6 End of Life. For Drupal 8.x, use Search API Solr Searchinstead.