Lines 309-314
sub getRecords {
Link Here
|
309 |
my $facets_counter = (); |
309 |
my $facets_counter = (); |
310 |
my $facets_info = (); |
310 |
my $facets_info = (); |
311 |
my $facets = getFacets(); |
311 |
my $facets = getFacets(); |
|
|
312 |
my $facets_maxrecs = C4::Context->preference('maxRecordsForFacets')||20; |
312 |
|
313 |
|
313 |
my @facets_loop; # stores the ref to array of hashes for template facets loop |
314 |
my @facets_loop; # stores the ref to array of hashes for template facets loop |
314 |
|
315 |
|
Lines 418-424
sub getRecords {
Link Here
|
418 |
for ( my $j = $offset ; $j < $times ; $j++ ) { |
419 |
for ( my $j = $offset ; $j < $times ; $j++ ) { |
419 |
my $records_hash; |
420 |
my $records_hash; |
420 |
my $record; |
421 |
my $record; |
421 |
my $facet_record; |
|
|
422 |
|
422 |
|
423 |
## Check if it's an index scan |
423 |
## Check if it's an index scan |
424 |
if ($scan) { |
424 |
if ($scan) { |
Lines 451-483
sub getRecords {
Link Here
|
451 |
|
451 |
|
452 |
# warn "RECORD $j:".$record; |
452 |
# warn "RECORD $j:".$record; |
453 |
$results_hash->{'RECORDS'}[$j] = $record; |
453 |
$results_hash->{'RECORDS'}[$j] = $record; |
454 |
|
|
|
455 |
# Fill the facets while we're looping, but only for the biblioserver |
456 |
$facet_record = MARC::Record->new_from_usmarc($record) |
457 |
if $servers[ $i - 1 ] =~ /biblioserver/; |
458 |
|
459 |
#warn $servers[$i-1]."\n".$record; #.$facet_record->title(); |
460 |
if ($facet_record) { |
461 |
for ( my $k = 0 ; $k <= @$facets ; $k++ ) { |
462 |
($facets->[$k]) or next; |
463 |
my @fields = map {$facet_record->field($_)} @{$facets->[$k]->{'tags'}} ; |
464 |
for my $field (@fields) { |
465 |
my @subfields = $field->subfields(); |
466 |
for my $subfield (@subfields) { |
467 |
my ( $code, $data ) = @$subfield; |
468 |
($code eq $facets->[$k]->{'subfield'}) or next; |
469 |
$facets_counter->{ $facets->[$k]->{'link_value'} }->{$data}++; |
470 |
} |
471 |
} |
472 |
$facets_info->{ $facets->[$k]->{'link_value'} }->{'label_value'} = |
473 |
$facets->[$k]->{'label_value'}; |
474 |
$facets_info->{ $facets->[$k]->{'link_value'} }->{'expanded'} = |
475 |
$facets->[$k]->{'expanded'}; |
476 |
} |
477 |
} |
478 |
} |
454 |
} |
|
|
455 |
|
479 |
} |
456 |
} |
480 |
$results_hashref->{ $servers[ $i - 1 ] } = $results_hash; |
457 |
$results_hashref->{ $servers[ $i - 1 ] } = $results_hash; |
|
|
458 |
|
459 |
# Fill the facets while we're looping, but only for the biblioserver and not for a scan |
460 |
if ( !$scan && $servers[ $i - 1 ] =~ /biblioserver/ ) { |
461 |
|
462 |
my $jmax = $size>$facets_maxrecs? $facets_maxrecs: $size; |
463 |
|
464 |
for ( my $k = 0 ; $k <= @$facets ; $k++ ) { |
465 |
($facets->[$k]) or next; |
466 |
my @fcodes = @{$facets->[$k]->{'tags'}}; |
467 |
my $sfcode = $facets->[$k]->{'subfield'}; |
468 |
|
469 |
for ( my $j = 0 ; $j < $jmax ; $j++ ) { |
470 |
my $render_record = $results[ $i - 1 ]->record($j)->render(); |
471 |
my @used_datas = (); |
472 |
|
473 |
foreach my $fcode (@fcodes) { |
474 |
|
475 |
# avoid first line |
476 |
my $field_pattern = '\n'.$fcode.' ([^\n]+)'; |
477 |
my @field_tokens = ( $render_record =~ /$field_pattern/g ) ; |
478 |
|
479 |
foreach my $field_token (@field_tokens) { |
480 |
my $subfield_pattern = '\$'.$sfcode.' ([^\$]+)'; |
481 |
my @subfield_values = ( $field_token =~ /$subfield_pattern/g ); |
482 |
|
483 |
foreach my $subfield_value (@subfield_values) { |
484 |
|
485 |
my $data = $subfield_value; |
486 |
$data =~ s/^\s+//; # trim left |
487 |
$data =~ s/\s+$//; # trim right |
488 |
|
489 |
unless ( $data ~~ @used_datas ) { |
490 |
$facets_counter->{ $facets->[$k]->{'link_value'} }->{$data}++; |
491 |
push @used_datas, $data; |
492 |
} |
493 |
} # subfields |
494 |
} # fields |
495 |
} # field codes |
496 |
} # records |
497 |
|
498 |
$facets_info->{ $facets->[$k]->{'link_value'} }->{'label_value'} = $facets->[$k]->{'label_value'}; |
499 |
$facets_info->{ $facets->[$k]->{'link_value'} }->{'expanded'} = $facets->[$k]->{'expanded'}; |
500 |
} # facets |
501 |
} |
502 |
# End PROGILONE |
481 |
} |
503 |
} |
482 |
|
504 |
|
483 |
# warn "connection ", $i-1, ": $size hits"; |
505 |
# warn "connection ", $i-1, ": $size hits"; |