0

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.

www.example-website.com/?f[0]=field_colour%3A2712.......etc

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 May 30 '13 at 16:55
  • I'm using apachesolr, search_api and facet_api - cheers – williamsowen May 31 '13 at 9:03
0

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.

0

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, privacy policy and cookie policy

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