View | Details | Raw Unified | Return to bug 12788
Collapse All | Expand All

(-)a/C4/Search.pm (-4 / +25 lines)
Lines 520-526 sub getRecords { Link Here
520
                            next;
520
                            next;
521
                        }
521
                        }
522
522
523
                        _get_facets_data_from_record( $marc_record, $facets, $facets_counter, $facets_info );
523
                        _get_facets_data_from_record( $marc_record, $facets, $facets_counter );
524
                        $facets_info = _get_facets_info( $facets );
524
                    }
525
                    }
525
                }
526
                }
526
527
Lines 656-662 sub getRecords { Link Here
656
    C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
657
    C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
657
658
658
Internal function that extracts facets information from a MARC::Record object
659
Internal function that extracts facets information from a MARC::Record object
659
and populates $facets_counter and $facets_info for using in getRecords.
660
and populates $facets_counter for using in getRecords.
660
661
661
$facets is expected to be filled with C4::Koha::getFacets output (i.e. the configured
662
$facets is expected to be filled with C4::Koha::getFacets output (i.e. the configured
662
facets for Zebra).
663
facets for Zebra).
Lines 665-671 facets for Zebra). Link Here
665
666
666
sub _get_facets_data_from_record {
667
sub _get_facets_data_from_record {
667
668
668
    my ( $marc_record, $facets, $facets_counter, $facets_info ) = @_;
669
    my ( $marc_record, $facets, $facets_counter ) = @_;
669
670
670
    for my $facet (@$facets) {
671
    for my $facet (@$facets) {
671
672
Lines 692-701 sub _get_facets_data_from_record { Link Here
692
                }
693
                }
693
            }
694
            }
694
        }
695
        }
695
        # update $facets_info so we know what facet categories need to be rendered
696
    }
697
}
698
699
=head2 _get_facets_info
700
701
    my $facets_info = C4::Search::_get_facets_info( $facets )
702
703
Internal function that extracts facets information and properly builds
704
the data structure needed to render facet labels.
705
706
=cut
707
708
sub _get_facets_info {
709
710
    my $facets = shift;
711
712
    my $facets_info = {};
713
714
    for my $facet ( @$facets ) {
696
        $facets_info->{ $facet->{ idx } }->{ label_value } = $facet->{ label };
715
        $facets_info->{ $facet->{ idx } }->{ label_value } = $facet->{ label };
697
        $facets_info->{ $facet->{ idx } }->{ expanded }    = $facet->{ expanded };
716
        $facets_info->{ $facet->{ idx } }->{ expanded }    = $facet->{ expanded };
698
    }
717
    }
718
719
    return $facets_info;
699
}
720
}
700
721
701
sub pazGetRecords {
722
sub pazGetRecords {
(-)a/t/db_dependent/Search.t (-8 / +53 lines)
Lines 129-134 $contextmodule->mock('preference', sub { Link Here
129
        return '--';
129
        return '--';
130
    } elsif ($pref eq 'DisplayLibraryFacets') {
130
    } elsif ($pref eq 'DisplayLibraryFacets') {
131
        return 'holding';
131
        return 'holding';
132
    } elsif ($pref eq 'UNIMARCAuthorsFacetsSeparator') {
133
        return '--';
132
    } else {
134
    } else {
133
        warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
135
        warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
134
            unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
136
            unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
Lines 859-865 if ( $indexing_mode eq 'dom' ) { Link Here
859
    
861
    
860
    # Test facet calculation
862
    # Test facet calculation
861
    my $facets_counter = {};
863
    my $facets_counter = {};
862
    my $facets_info    = {};
863
    my $facets         = C4::Koha::getFacets();
864
    my $facets         = C4::Koha::getFacets();
864
    # Create a record with a 100$z field
865
    # Create a record with a 100$z field
865
    my $marc_record    = MARC::Record->new;
866
    my $marc_record    = MARC::Record->new;
Lines 869-875 if ( $indexing_mode eq 'dom' ) { Link Here
869
        [ '100', 'z', ' ', a => 'Tomasito' ],
870
        [ '100', 'z', ' ', a => 'Tomasito' ],
870
        [ '245', ' ', ' ', a => 'First try' ]
871
        [ '245', ' ', ' ', a => 'First try' ]
871
    );
872
    );
872
    C4::Search::_get_facets_data_from_record($marc_record, $facets, $facets_counter,$facets_info);
873
    C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
873
    is_deeply( { au => { 'Cohen Arazi, Tomas' => 1 } },  $facets_counter,
874
    is_deeply( { au => { 'Cohen Arazi, Tomas' => 1 } },  $facets_counter,
874
        "_get_facets_data_from_record doesn't count 100\$z (Bug 12788)");
875
        "_get_facets_data_from_record doesn't count 100\$z (Bug 12788)");
875
    $marc_record    = MARC::Record->new;
876
    $marc_record    = MARC::Record->new;
Lines 879-888 if ( $indexing_mode eq 'dom' ) { Link Here
879
        [ '100', 'z', ' ', a => 'Tomasito' ],
880
        [ '100', 'z', ' ', a => 'Tomasito' ],
880
        [ '245', ' ', ' ', a => 'Second try' ]
881
        [ '245', ' ', ' ', a => 'Second try' ]
881
    );
882
    );
882
    C4::Search::_get_facets_data_from_record($marc_record, $facets, $facets_counter, $facets_info);
883
    C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
883
    is_deeply( { au => { 'Cohen Arazi, Tomas' => 2 } },  $facets_counter,
884
    is_deeply( { au => { 'Cohen Arazi, Tomas' => 2 } },  $facets_counter,
884
        "_get_facets_data_from_record correctly counts author facet twice");
885
        "_get_facets_data_from_record correctly counts author facet twice");
885
886
887
    # Test _get_facets_info
888
    my $facets_info = C4::Search::_get_facets_info( $facets );
889
    my $expected_facets_info_marc21 = {
890
                   'au' => { 'expanded'    => undef,
891
                             'label_value' => "Authors" },
892
        'holdingbranch' => { 'expanded'    => undef,
893
                             'label_value' => "HoldingLibrary" },
894
                'itype' => { 'expanded'    => undef,
895
                             'label_value' => "ItemTypes" },
896
             'location' => { 'expanded'    => undef,
897
                             'label_value' => "Location" },
898
                   'se' => { 'expanded'    => undef,
899
                             'label_value' => "Series" },
900
               'su-geo' => { 'expanded'    => undef,
901
                             'label_value' => "Places" },
902
                'su-to' => { 'expanded'    => undef,
903
                             'label_value' => "Topics" },
904
                'su-ut' => { 'expanded'    => undef,
905
                             'label_value' => "Titles" }
906
    };
907
    is_deeply( $facets_info, $expected_facets_info_marc21,
908
        "_get_facets_info returns the correct data");
909
886
    cleanup();
910
    cleanup();
887
}
911
}
888
912
Lines 954-979 sub run_unimarc_search_tests { Link Here
954
    );
978
    );
955
    is($count, 24, 'UNIMARC authorities: hits on any starts with "jean"');
979
    is($count, 24, 'UNIMARC authorities: hits on any starts with "jean"');
956
980
981
    # Test _get_facets_info
982
    my $facets      = C4::Koha::getFacets();
983
    my $facets_info = C4::Search::_get_facets_info( $facets );
984
    my $expected_facets_info_unimarc = {
985
                   'au' => { 'expanded'    => undef,
986
                             'label_value' => "Authors" },
987
        'holdingbranch' => { 'expanded'    => undef,
988
                             'label_value' => "HoldingLibrary" },
989
             'location' => { 'expanded'    => undef,
990
                             'label_value' => "Location" },
991
                   'se' => { 'expanded'    => undef,
992
                             'label_value' => "Series" },
993
               'su-geo' => { 'expanded'    => undef,
994
                             'label_value' => "Places" },
995
                'su-to' => { 'expanded'    => undef,
996
                             'label_value' => "Topics" },
997
                'su-ut' => { 'expanded'    => undef,
998
                             'label_value' => "Titles" }
999
    };
1000
    is_deeply( $facets_info, $expected_facets_info_unimarc,
1001
        "_get_facets_info returns the correct data");
1002
957
    cleanup();
1003
    cleanup();
958
}
1004
}
959
1005
960
subtest 'MARC21 + GRS-1' => sub {
1006
subtest 'MARC21 + GRS-1' => sub {
961
    plan tests => 108;
1007
    plan tests => 109;
962
    run_marc21_search_tests('grs1');
1008
    run_marc21_search_tests('grs1');
963
};
1009
};
964
1010
965
subtest 'MARC21 + DOM' => sub {
1011
subtest 'MARC21 + DOM' => sub {
966
    plan tests => 108;
1012
    plan tests => 109;
967
    run_marc21_search_tests('dom');
1013
    run_marc21_search_tests('dom');
968
};
1014
};
969
1015
970
subtest 'UNIMARC + GRS-1' => sub {
1016
subtest 'UNIMARC + GRS-1' => sub {
971
    plan tests => 13;
1017
    plan tests => 14;
972
    run_unimarc_search_tests('grs1');
1018
    run_unimarc_search_tests('grs1');
973
};
1019
};
974
1020
975
subtest 'UNIMARC + DOM' => sub {
1021
subtest 'UNIMARC + DOM' => sub {
976
    plan tests => 13;
1022
    plan tests => 14;
977
    run_unimarc_search_tests('dom');
1023
    run_unimarc_search_tests('dom');
978
};
1024
};
979
1025
980
- 

Return to bug 12788