in reply to How to retrieve WebService::Solr facet value properly?

According to the fine documentation the WebService::Solr::Response object has a facet_counts method. Have you tried that?


🦛

Replies are listed 'Best First'.
Re^2: How to retrieve WebService::Solr facet value properly?
by swiftlet (Acolyte) on Aug 07, 2020 at 07:06 UTC
    Thanks for your information, I have just tried it. Seem like that's the official way to get facet count, but I don't like they put facet field and facet count in one array, maybe my "Dumper +Regex" is safer.

    my $facet_counts = $response->facet_counts; my $autId = $facet_counts->{facet_fields}{author_id}; print Dumper(\$autId), "<br>"; for(my $i=0; $i < int(@{$autId}); $i++){ print @{$autId}[$i], ": ", @{$autId}[++$i], "<br>\n"; };
    Output:

    $VAR1 = \[ '9291', 131, '3389', 88, '622', 85, '123715', 81, '5091', 6 +3 ]; 9291: 131 3389: 88 622: 85 123715: 81 5091: 63
      I don't like they put facet field and facet count in one array,

      So, just hashify it yourself (although you'll lose the sorting, of course):

      my $autId = $facet_counts->{facet_fields}{author_id}; my %easy_hash = @$autId;
      maybe my "Dumper +Regex" is safer.

      Almost certainly not. Take the robust approach and then post-process the data as desired.


      🦛