Lines 340-347
sub getRecords {
Link Here
|
340 |
my $results_hashref = (); |
340 |
my $results_hashref = (); |
341 |
|
341 |
|
342 |
# Initialize variables for the faceted results objects |
342 |
# Initialize variables for the faceted results objects |
343 |
my $facets_counter = (); |
343 |
my $facets_counter = {}; |
344 |
my $facets_info = (); |
344 |
my $facets_info = {}; |
345 |
my $facets = getFacets(); |
345 |
my $facets = getFacets(); |
346 |
my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20; |
346 |
my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20; |
347 |
|
347 |
|
Lines 499-549
sub getRecords {
Link Here
|
499 |
} |
499 |
} |
500 |
$results_hashref->{ $servers[ $i - 1 ] } = $results_hash; |
500 |
$results_hashref->{ $servers[ $i - 1 ] } = $results_hash; |
501 |
|
501 |
|
502 |
# Fill the facets while we're looping, but only for the biblioserver and not for a scan |
502 |
# Fill the facets while we're looping, but only for the |
|
|
503 |
# biblioserver and not for a scan |
503 |
if ( !$scan && $servers[ $i - 1 ] =~ /biblioserver/ ) { |
504 |
if ( !$scan && $servers[ $i - 1 ] =~ /biblioserver/ ) { |
504 |
|
505 |
|
505 |
my $jmax = |
506 |
my $jmax = $size > $facets_maxrecs |
506 |
$size > $facets_maxrecs ? $facets_maxrecs : $size; |
507 |
? $facets_maxrecs |
507 |
for my $facet (@$facets) { |
508 |
: $size; |
508 |
for ( my $j = 0 ; $j < $jmax ; $j++ ) { |
|
|
509 |
|
509 |
|
510 |
my $marc_record = new_record_from_zebra ( |
510 |
for ( my $j = 0 ; $j < $jmax ; $j++ ) { |
511 |
'biblioserver', |
|
|
512 |
$results[ $i - 1 ]->record($j)->raw() |
513 |
); |
514 |
|
515 |
if ( ! defined $marc_record ) { |
516 |
warn "ERROR DECODING RECORD - $@: " . |
517 |
$results[ $i - 1 ]->record($j)->raw(); |
518 |
next; |
519 |
} |
520 |
|
521 |
my @used_datas = (); |
522 |
|
511 |
|
523 |
foreach my $tag ( @{ $facet->{tags} } ) { |
512 |
my $marc_record = new_record_from_zebra ( |
|
|
513 |
'biblioserver', |
514 |
$results[ $i - 1 ]->record($j)->raw() |
515 |
); |
524 |
|
516 |
|
525 |
# avoid first line |
517 |
if ( ! defined $marc_record ) { |
526 |
my $tag_num = substr( $tag, 0, 3 ); |
518 |
warn "ERROR DECODING RECORD - $@: " . |
527 |
my $subfield_letters = substr( $tag, 3 ); |
519 |
$results[ $i - 1 ]->record($j)->raw(); |
528 |
# Removed when as_string fixed |
520 |
next; |
529 |
my @subfields = $subfield_letters =~ /./sg; |
521 |
} |
530 |
|
|
|
531 |
my @fields = $marc_record->field($tag_num); |
532 |
foreach my $field (@fields) { |
533 |
my $data = $field->as_string( $subfield_letters, $facet->{sep} ); |
534 |
|
522 |
|
535 |
unless ( grep { /^\Q$data\E$/ } @used_datas ) { |
523 |
_get_facets_data_from_record( $marc_record, $facets, $facets_counter, $facets_info ); |
536 |
push @used_datas, $data; |
524 |
} |
537 |
$facets_counter->{ $facet->{idx} }->{$data}++; |
|
|
538 |
} |
539 |
} # fields |
540 |
} # field codes |
541 |
} # records |
542 |
$facets_info->{ $facet->{idx} }->{label_value} = |
543 |
$facet->{label}; |
544 |
$facets_info->{ $facet->{idx} }->{expanded} = |
545 |
$facet->{expanded}; |
546 |
} # facets |
547 |
} |
525 |
} |
548 |
|
526 |
|
549 |
# warn "connection ", $i-1, ": $size hits"; |
527 |
# warn "connection ", $i-1, ": $size hits"; |
Lines 673-678
sub getRecords {
Link Here
|
673 |
return ( undef, $results_hashref, \@facets_loop ); |
651 |
return ( undef, $results_hashref, \@facets_loop ); |
674 |
} |
652 |
} |
675 |
|
653 |
|
|
|
654 |
=head2 _get_facets_data_from_record |
655 |
|
656 |
C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter ); |
657 |
|
658 |
Internal function that extracts facets information from a MARC::Record object |
659 |
and populates $facets_counter for using in getRecords. |
660 |
|
661 |
$facets is expected to be filled with C4::Koha::getFacets output (i.e. the configured |
662 |
facets for Zebra). |
663 |
|
664 |
=cut |
665 |
|
666 |
sub _get_facets_data_from_record { |
667 |
|
668 |
my ( $marc_record, $facets, $facets_counter, $facets_info ) = @_; |
669 |
|
670 |
for my $facet (@$facets) { |
671 |
|
672 |
my @used_datas = (); |
673 |
|
674 |
foreach my $tag ( @{ $facet->{ tags } } ) { |
675 |
|
676 |
# avoid first line |
677 |
my $tag_num = substr( $tag, 0, 3 ); |
678 |
my $subfield_letters = substr( $tag, 3 ); |
679 |
# Removed when as_string fixed |
680 |
my @subfields = $subfield_letters =~ /./sg; |
681 |
|
682 |
my @fields = $marc_record->field( $tag_num ); |
683 |
foreach my $field (@fields) { |
684 |
my $data = $field->as_string( $subfield_letters, $facet->{ sep } ); |
685 |
|
686 |
unless ( grep { /^\Q$data\E$/ } @used_datas ) { |
687 |
push @used_datas, $data; |
688 |
$facets_counter->{ $facet->{ idx } }->{ $data }++; |
689 |
} |
690 |
} |
691 |
} |
692 |
# update $facets_info so we know what facet categories need to be rendered |
693 |
$facets_info->{ $facet->{ idx } }->{ label_value } = $facet->{ label }; |
694 |
$facets_info->{ $facet->{ idx } }->{ expanded } = $facet->{ expanded }; |
695 |
} |
696 |
} |
697 |
|
676 |
sub pazGetRecords { |
698 |
sub pazGetRecords { |
677 |
my ( |
699 |
my ( |
678 |
$koha_query, $simple_query, $sort_by_ref, $servers_ref, |
700 |
$koha_query, $simple_query, $sort_by_ref, $servers_ref, |