I'm using Apache Solr Search, Search API and Facet API.

Is there a way to retrieve the current search filters being used when using Apache Solr on Drupal?

For example: I have a website using facets which reference a taxonomy called colours. In this facet, there's a list of colours - if I select Green, this generates an Apache Solr search - using green as the filter.


When the Solr search is created - I guess, I could grab the term id 2712 from the URL using GET - but there must be a cleaner way.

Any ideas?

  • Which SOLR module are you using (apache_solr or search_api_solr)?
    – Clive
    Commented May 30, 2013 at 16:55
  • I'm using apachesolr, search_api and facet_api - cheers Commented May 31, 2013 at 9:03

2 Answers 2


I did it using FacetApiAdapter (see facetapi_adapter_load):

// Get an instance of FacetApiAdapter
$searcher = 'apachesolr@solr' // your apachesolr server id
$facetApiAdapter = facetapi_adapter_load($searcher);

Then if you need to work on active filters:

$activeItems = $facetApiAdapter->getAllActiveItems();
foreach ($activeItems as $item_key => $item) {
  $facet = facetapi_facet_load($item['field alias'], $searcher);

Or you can use other FacetApiAdapter methods.


Sounds like you're writing a module to do this?

If so, if you're implementing something like the apachesolr_query_alter(&$query) hook or something like that, which gives you access to the search query, you can use

function [getFilters][1]($name = NULL)

Note that the name parameter is optional: Returns all filters matching $name, if set; otherwise, returns all filters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.