Search code examples
solrsolarium

Solr Json Facet API using Solarium


I'm Working on a PHP project where I'm using Solarium as my Primary Library for Interfacing with Apache Solr.

I'm using Json Facet API of Solr as follows:-

json.facet={"unique_docs":"unique(doc_id)","hll_docs":"hll(doc_id)"}

How can I use Similar Query with Solarium.

I've Found an Resolved Issue on the solarium Github Page that is of my concern.

JSON Facet API #378

But, the page doesn't explain the way to use it. There is nothing pertaining to this in the Solarium docs either.


Solution

  • I got it working with customizerequest:

    $facet_json = '{my_key:{type:terms,field:my_solr_field_name,domain:{blockChildren:"my_parent_filter:1"}}}';
    
    $customizer = $this->client->getPlugin('customizerequest');
    $customizer->createCustomization('json.facet')
        ->setType('param')
        ->setName('json.facet')
        ->setValue($facet_json);
    

    There was a release that should support the API with something like $facetset->createJsonFacetTerms($options) but I never managed to get it working like it should and couldn't find any doc.

    To get the json facet after the request is executed I have something like this:

    $facet_result = $this->result_set->getFacetSet()->getFacet('my_key');
    
    foreach($facet_result as $facet) {
        $value = $facet->getValue();
        $count = $facet->getCount();
    }