I have an apachesolr module index and I want to get a list of all the possible items for a facet.
Is there a way I can do that programmatically without actually generating a whole facet block?
I will investigate myself but someone here will probably know the best way to go about this.
There is this option but it seems like overkill:
<?php
apachesolr_search_run_empty('apachesolr');
$block_build = facetapi_build_realm('apachesolr@my_instance', 'block');
$items = $block_build['my_facet']['my_facet']['#items'];
?>
And this, which is more complex code but seems to be closer to doing what I need without doing what I don't need:
<?php
$searcher = 'apachesolr@my_instance';
$facet_name = 'my_facet';
apachesolr_search_run_empty('apachesolr');
$adapter = facetapi_adapter_load($searcher);
$facet = facetapi_facet_load($facet_name, $searcher);
$realm = facetapi_realm_load('block');
$adapter->processFacets();
$processor = $adapter->getProcessor($facet_name);
$facet_build = $adapter->getFacet($facet)->build($realm, $processor);
$items = $facet_build[$facet_name][$facet_name]['#items'];
?>
However this will only give me facet link markup but I actually only want the facet items from the index themselves, not a link or anything else.
I'll keep digging in but is there a simpler way?
Am I on the right track or is there a better way?
Comments
Comment #1
cpliakas CreditAttribution: cpliakas commentedMoving to the Apache Solr Search module since it is likely an API call to Solr that will give you tis information. Facet API is not intended to provide that level of abstraction and is really geared towards displaying facets on a SERP, so it is unfortunately not likely to help you here.
Comment #2
rooby CreditAttribution: rooby commentedWhat i ended up doing was creating a new FacetapiWidget that returns plain text facets and then used this widget where I need this functionality.
It's still a little cluncky but works ok.
If anyone on the apachesolr side of things still has a better solution I'd lovbe to hear it, otherwise happy to close this.
Comment #3
yakoub CreditAttribution: yakoub commentedi believe this question really should belong to facetapi and not some other random module !
this is how it is done :