Is it possible/easy to get all the current search / facet information from the Facet API module at the moment. I have a need to create custom informational blocks once a search has been performed. The idea is that some searches wont show anything in the block but more popular searches will have extra information shown with the search results.

So if a user searches for "France" an extra block needs to appear at the top of the page which has a description of France.

To do this I'm thinking if Facet API can easily tell me if a search has been performed and which keywords and facet values have been used I can then build a custom block using that information to retrieve the information.

This is also a way forward for me to do an advanced current search block. I see you've started making that more configurable.

Comments

cpliakas’s picture

Hi a_lawry.

The adapter has a few methods that could help you out. In your custom block you can get the adapter by calling facetapi_adapter_load($searcher) (where $searcher will be the machine readable name of the searcher being executed), and the $adapter->searchExecuted() and $adapter->getSearchKeys() methods should accomplish what you are looking to do. In addition, the $adapter->getAllActiveItems() method will return the active filters in an associative array. If you are confused about what to pass as the $searcher, check out your search module's hook_facetapi_searcher_info() implementation. For example, apachesolr_facetapi_searcher_info() will define its searchers as apachesolr@$id, where $id is the name of the environment such as "solr".

a_lawry’s picture

Thanks Chris. I'll look into that further. That is where I started playing with it. But I found I had to make some edits to the adapter because I couldn't find a way to get all the info I required. I'll have another look at it starting with those methods and see where that takes me.

Thanks for your help.

cpliakas’s picture

What info are you looking for that is not available?

a_lawry’s picture

I've just tried implementing up the blocks again.

The problem I was having was getting the information out to rebuild the search URL based on removing an active facet when building a custom search block. I couldn't get access to the processors for the facets. But it seems like I probably don't need to looking at it again.

I see a URLProcessor plugin has been added. How does that fit into the structure? What is the correct method to build a search URL based on the current facets? At the moment I'm just calling $adapter->getAllActiveItems() and then looping over the array and building the query string for the URL myself. I have a feeling I should be using the adapter or the URLProcessor to build a query string but I'm not sure which?

cpliakas’s picture

The URL processor is a plugin that allows for customized structuring of the query string. Specifically, it is designed for people to be able to swap it out if they want to do something like Pretty Facet Paths. The default one builds the query string in the way that you see out of the box.

In your case, you probably want to use the FacetapiAdapter::getQueryString() method. It invokes the active URL plugin and takes care of the query building for you. The docblocs explain the parameters, but it is important to note that the $facet param is the return of the facetapi_facet_load() function. Each facet item you are building will build it's query string through this method.

cpliakas’s picture

Component: Code » Code (functionality)
Status: Active » Closed (fixed)

Closing as fixed after weeks of inactivity.

kenorb’s picture

Component: Code (functionality) » Code

You can create custom block by using Current Search sub-module.

BTW. Pretty Facet Paths is now called Facet API Pretty Paths