2

I currently have the Search API module configured with an Apache Solr server instance, and have created an index which indexes a custom entity.

I'm looking to somehow retrieve the options displayed within a Facet I have created for a particular field, to as options for a select field on a custom form. So in other words, the function a particular Facet would use to query Apache Solr when it is populated.

Does anyone know how I can retrieve this data using the Search API?

I've tried playing around with the example given in this very useful post on querying using the Search API. So far I've had no such luck retrieving the indexed Facet values as the appear in their Facet blocks.

Any help would be appreciated thanks.

1 Answer 1

1

I seem to have found the answer after some major trial and error, and some digging through the FacetAPI source code. The issue is linked to the same issue explained in the post Display facets on non-search pages

I created a facet block in Views for each facet that I'm trying to access, and set them to "hidden" in the block settings within Views. Then by adding a block from my custom module directly below them in the same region, I was able to access the facet data using the following code:

$searcher = 'search_api@MY_CUSTOM_SEARCHAPI_INDEX';
$realm_name = 'block';

$build = facetapi_build_realm($searcher, $realm_name);
krumo($build);

The krumo output contains a render array for each facet you're trying to access, and all the facet options are available for you to access.

I hope this helps someone struggling with the same issue.

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.