Given a set of values for different facets, is there any sort of API to create a link to that search result for placing elsewhere in the site?

For instance, suppose I wanted to render taxonomy term links with the link going to the search result on that facet.

Comments

cpliakas’s picture

The FacetapiAdapter::getQueryString() and FacetapiAdapter::getQueryString() methods are probably what you are looking for. There could probably be an API function that wraps the code to output a link similar to the (untested) snippet below:


function facetapi_get_facet_link($text, $searcher, $facet_name, array $values) {
  $adapter = facetapi_adapter_load($searcher);
  $facet = facetapi_facet_load($facet_name, $searcher);
  $path = $adapter->getFacetPath($facet, $values, 0);
  $options = array('query' => $adapter->getQueryString($facet, $values, 0));
  return l($text, $path, $options);
}

If you want to test it out, add docs, and implement some defensive coding, I would definitely be more than happy to commit an API function to Facet API.

Hope this helps,
Chris

cpliakas’s picture

One thought, though, is that if you want to enter search keys then you will have to implement something specific to the backed to append the keys to the querystring or path. AFAIK Facet API doesn't have any abstraction on this level since the implementations are fairly different per backend, and under normal circumstances the module doesn't need to understand how the keys are passed.

joachim’s picture

Thanks for the pointers!

I'm right up against a deadline right now so I hacked something, but I'll come back to this and make a patch.

cpliakas’s picture

Status: Active » Fixed

Not a problem. Thanks for posting back. Marking as fixed, feel free to open a feature request if you do have some time for a patch.

Thanks,
Chris

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.