1

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.

2 Answers2

1

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();
}
1

To add a Solr-JSON-facet for to a Solarium query API you need to create a Solarium facet set object. To use stat facet functions (aka aggregate functions) Solarium provides methods to create and setup the query.

So this should do what you want:

$query = new \Solarium\QueryType\Select\Query\Query();
$query->getFacetSet()
    ->createJsonFacetAggregation('unique_docs') // the JSON key
    ->setFunction('unique(doc_id)'); // the aggregate function (JSON value)
    ->createJsonFacetAggregation('hll_docs')
    ->setFunction('hll(doc_id)');
Masi
  • 9
  • 2
  • Hi @Masi. I see you are brand new to Stack Overflow. Thanks for answering the question. I was wondering, if you could explain this more... It might be self explanatory and this question is out of my area of expertise, so if this is the case please ignore my question. Many times we want to answer a question and say what the answer does which helps other new people understand the answer. None the less, great job in joining and answering a question on SO (Stack Overflow). Next, we'll see if the person who asked the question likes this and will accept this as an answer. – PatS Oct 10 '19 at 18:12