I have seen use_zebra_facets=1 cause no facets rendered when GRS-1 configuration files are kept during upgrades up to where GRS-1 got deprecated (3.20?). Is it the case? What does the About > System information page says about your config?
The slowliness is not in zebra per se, but in the way we retrieve the facets from it (so Koha/Perl side). We retrieve each facet at a time instead of fetching them all in one call. And they come in XML format, so need to be parsed. So, if anyone is willing to improve it, just need to optimize this function (read the TODO):
sub _get_facet_from_result_set {
my $facet_idx = shift;
my $rs = shift;
my $sep = shift;
my $internal_sep = '<*>';
my $facetMaxCount = C4::Context->preference('FacetMaxCount') // 20;
return if ( ! defined $facet_idx || ! defined $rs );
# zebra's facet element, untokenized index
my $facet_element = 'zebra::facet::' . $facet_idx . ':0:' . $facetMaxCount;
# configure zebra results for retrieving the desired facet
$rs->option( elementSetName => $facet_element );
# get the facet record from result set
my $facet = $rs->record( 0 )->raw;
# if the facet has no restuls...
return if !defined $facet;
# TODO: benchmark DOM vs. SAX performance
my $facet_dom = XML::LibXML->load_xml(
string => ($facet)
);
my @terms = $facet_dom->getElementsByTagName('term');
return if ! @terms;
my $facets = {};
foreach my $term ( @terms ) {
my $facet_value = $term->textContent;
$facet_value =~ s/\Q$internal_sep\E/$sep/ if defined $sep;
$facets->{ $facet_value } = $term->getAttribute( 'occur' );
}
return $facets;
}
Another option would be to make _get_facets_from_zebra build the element set containing all facets so they are read in one call (comma-separate all elements). The problem is that Zebra returns zero if one of the elements is empty. Jared proposed to create a ghost record with all facet fields. I didn't manage to make it work. Another option is to patch Zebra. I started that, but abandoned once the ES code got pushed.
So, if use_zebra_facets=0 is good enough, maybe it should be recommended. Problem is it is not a real facet, but the sole extraction of the fields from the first x records.
As I said, it could be good enough anyway.
Regards