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

(-)a/C4/Search.pm (-90 / +71 lines)
Lines 312-333 sub SimpleSearch { Link Here
312
( undef, $results_hashref, \@facets_loop ) = getRecords (
312
( undef, $results_hashref, \@facets_loop ) = getRecords (
313
313
314
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
314
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
315
        $results_per_page, $offset,       $expanded_facet, $branches,$itemtypes,
315
        $results_per_page, $offset,       $branches,       $itemtypes,
316
        $query_type,       $scan
316
        $query_type,       $scan,         $opac
317
    );
317
    );
318
318
319
The all singing, all dancing, multi-server, asynchronous, scanning,
319
The all singing, all dancing, multi-server, asynchronous, scanning,
320
searching, record nabbing, facet-building
320
searching, record nabbing, facet-building
321
321
322
See verbse embedded documentation.
322
See verbose embedded documentation.
323
323
324
=cut
324
=cut
325
325
326
sub getRecords {
326
sub getRecords {
327
    my (
327
    my (
328
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
328
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
329
        $results_per_page, $offset,       $expanded_facet, $branches,
329
        $results_per_page, $offset,       $branches,         $itemtypes,
330
        $itemtypes,        $query_type,   $scan,           $opac
330
        $query_type,       $scan,         $opac
331
    ) = @_;
331
    ) = @_;
332
332
333
    my @servers = @$servers_ref;
333
    my @servers = @$servers_ref;
Lines 516-523 sub getRecords { Link Here
516
                        keys %$facets_counter
516
                        keys %$facets_counter
517
                      )
517
                      )
518
                    {
518
                    {
519
                        my $expandable;
520
                        my $number_of_facets;
521
                        my @this_facets_array;
519
                        my @this_facets_array;
522
                        for my $one_facet (
520
                        for my $one_facet (
523
                            sort {
521
                            sort {
Lines 527-620 sub getRecords { Link Here
527
                            } keys %{ $facets_counter->{$link_value} }
525
                            } keys %{ $facets_counter->{$link_value} }
528
                          )
526
                          )
529
                        {
527
                        {
530
                            $number_of_facets++;
531
                            if (   ( $number_of_facets <= 5 )
532
                                || ( $expanded_facet eq $link_value )
533
                                || ( $facets_info->{$link_value}->{'expanded'} )
534
                              )
535
                            {
536
537
# Sanitize the link value : parenthesis, question and exclamation mark will cause errors with CCL
528
# Sanitize the link value : parenthesis, question and exclamation mark will cause errors with CCL
538
                                my $facet_link_value = $one_facet;
529
                            my $facet_link_value = $one_facet;
539
                                $facet_link_value =~ s/[()!?¡¿؟]/ /g;
530
                            $facet_link_value =~ s/[()!?¡¿؟]/ /g;
540
531
541
                                # fix the length that will display in the label,
532
                            # fix the length that will display in the label,
542
                                my $facet_label_value = $one_facet;
533
                            my $facet_label_value = $one_facet;
543
                                my $facet_max_length  = C4::Context->preference(
534
                            my $facet_max_length  = C4::Context->preference(
544
                                    'FacetLabelTruncationLength')
535
                                'FacetLabelTruncationLength')
545
                                  || 20;
536
                              || 20;
546
                                $facet_label_value =
537
                            $facet_label_value =
547
                                  substr( $one_facet, 0, $facet_max_length )
538
                              substr( $one_facet, 0, $facet_max_length )
548
                                  . "..."
539
                              . "..."
549
                                  if length($facet_label_value) >
540
                              if length($facet_label_value) >
550
                                      $facet_max_length;
541
                                  $facet_max_length;
551
542
552
                            # if it's a branch, label by the name, not the code,
543
                        # if it's a branch, label by the name, not the code,
553
                                if ( $link_value =~ /branch/ ) {
544
                            if ( $link_value =~ /branch/ ) {
554
                                    if (   defined $branches
545
                                if (   defined $branches
555
                                        && ref($branches) eq "HASH"
546
                                    && ref($branches) eq "HASH"
556
                                        && defined $branches->{$one_facet}
547
                                    && defined $branches->{$one_facet}
557
                                        && ref( $branches->{$one_facet} ) eq
548
                                    && ref( $branches->{$one_facet} ) eq
558
                                        "HASH" )
549
                                    "HASH" )
559
                                    {
550
                                {
560
                                        $facet_label_value =
551
                                    $facet_label_value =
561
                                          $branches->{$one_facet}
552
                                      $branches->{$one_facet}
562
                                          ->{'branchname'};
553
                                      ->{'branchname'};
563
                                    }
564
                                    else {
565
                                        $facet_label_value = "*";
566
                                    }
567
                                }
554
                                }
568
555
                                else {
569
                          # if it's a itemtype, label by the name, not the code,
556
                                    $facet_label_value = "*";
570
                                if ( $link_value =~ /itype/ ) {
571
                                    if (   defined $itemtypes
572
                                        && ref($itemtypes) eq "HASH"
573
                                        && defined $itemtypes->{$one_facet}
574
                                        && ref( $itemtypes->{$one_facet} ) eq
575
                                        "HASH" )
576
                                    {
577
                                        $facet_label_value =
578
                                          $itemtypes->{$one_facet}
579
                                          ->{translated_description};
580
                                    }
581
                                }
557
                                }
558
                            }
582
559
583
               # also, if it's a location code, use the name instead of the code
560
                      # if it's a itemtype, label by the name, not the code,
584
                                if ( $link_value =~ /location/ ) {
561
                            if ( $link_value =~ /itype/ ) {
585
                                    # TODO Retrieve all authorised values at once, instead of 1 query per entry
562
                                if (   defined $itemtypes
586
                                    my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $one_facet });
563
                                    && ref($itemtypes) eq "HASH"
587
                                    $facet_label_value = $av->count ? $av->next->opac_description : '';
564
                                    && defined $itemtypes->{$one_facet}
565
                                    && ref( $itemtypes->{$one_facet} ) eq
566
                                    "HASH" )
567
                                {
568
                                    $facet_label_value =
569
                                      $itemtypes->{$one_facet}
570
                                      ->{translated_description};
588
                                }
571
                                }
572
                            }
589
573
590
                                # also, if it's a collection code, use the name instead of the code
574
           # also, if it's a location code, use the name instead of the code
591
                                if ( $link_value =~ /ccode/ ) {
575
                            if ( $link_value =~ /location/ ) {
592
                                    # TODO Retrieve all authorised values at once, instead of 1 query per entry
576
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
593
                                    my $av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $one_facet });
577
                                my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $one_facet });
594
                                    $facet_label_value = $av->count ? $av->next->opac_description : '';
578
                                $facet_label_value = $av->count ? $av->next->opac_description : '';
595
                                }
579
                            }
596
580
597
                # but we're down with the whole label being in the link's title.
581
                            # also, if it's a collection code, use the name instead of the code
598
                                push @this_facets_array,
582
                            if ( $link_value =~ /ccode/ ) {
599
                                  {
583
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
600
                                    facet_count =>
584
                                my $av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $one_facet });
601
                                      $facets_counter->{$link_value}
585
                                $facet_label_value = $av->count ? $av->next->opac_description : '';
602
                                      ->{$one_facet},
603
                                    facet_label_value => $facet_label_value,
604
                                    facet_title_value => $one_facet,
605
                                    facet_link_value  => $facet_link_value,
606
                                    type_link_value   => $link_value,
607
                                  }
608
                                  if ($facet_label_value);
609
                            }
586
                            }
610
                        }
611
587
612
                        # handle expanded option
588
            # but we're down with the whole label being in the link's title.
613
                        unless ( $facets_info->{$link_value}->{'expanded'} ) {
589
                            push @this_facets_array,
614
                            $expandable = 1
590
                              {
615
                              if ( ( $number_of_facets > 5 )
591
                                facet_count =>
616
                                && ( $expanded_facet ne $link_value ) );
592
                                  $facets_counter->{$link_value}
593
                                  ->{$one_facet},
594
                                facet_label_value => $facet_label_value,
595
                                facet_title_value => $one_facet,
596
                                facet_link_value  => $facet_link_value,
597
                                type_link_value   => $link_value,
598
                              }
599
                              if ($facet_label_value);
617
                        }
600
                        }
601
618
                        push @facets_loop,
602
                        push @facets_loop,
619
                          {
603
                          {
620
                            type_link_value => $link_value,
604
                            type_link_value => $link_value,
Lines 623-630 sub getRecords { Link Here
623
                              . $facets_info->{$link_value}->{'label_value'} =>
607
                              . $facets_info->{$link_value}->{'label_value'} =>
624
                              1,
608
                              1,
625
                            facets     => \@this_facets_array,
609
                            facets     => \@this_facets_array,
626
                            expandable => $expandable,
627
                            expand     => $link_value,
628
                          }
610
                          }
629
                          unless (
611
                          unless (
630
                            (
612
                            (
Lines 852-858 sub _get_facets_info { Link Here
852
834
853
    for my $facet ( @$facets ) {
835
    for my $facet ( @$facets ) {
854
        $facets_info->{ $facet->{ idx } }->{ label_value } = $facet->{ label };
836
        $facets_info->{ $facet->{ idx } }->{ label_value } = $facet->{ label };
855
        $facets_info->{ $facet->{ idx } }->{ expanded }    = $facet->{ expanded };
856
    }
837
    }
857
838
858
    return $facets_info;
839
    return $facets_info;
Lines 861-868 sub _get_facets_info { Link Here
861
sub pazGetRecords {
842
sub pazGetRecords {
862
    my (
843
    my (
863
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
844
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
864
        $results_per_page, $offset,       $expanded_facet, $branches,
845
        $results_per_page, $offset,       $branches,       $query_type,
865
        $query_type,       $scan
846
        $scan
866
    ) = @_;
847
    ) = @_;
867
    #NOTE: Parameter $branches is not used here !
848
    #NOTE: Parameter $branches is not used here !
868
849
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-12 / +9 lines)
Lines 111-125 sub build_query { Link Here
111
111
112
    # See _convert_facets in Search.pm for how these get turned into
112
    # See _convert_facets in Search.pm for how these get turned into
113
    # things that Koha can use.
113
    # things that Koha can use.
114
    my $size = C4::Context->preference('FacetMaxCount');
114
    $res->{aggregations} = {
115
    $res->{aggregations} = {
115
        author         => { terms => { field => "author__facet" } },
116
        author         => { terms => { field => "author__facet" , size => $size } },
116
        subject        => { terms => { field => "subject__facet" } },
117
        subject        => { terms => { field => "subject__facet", size => $size } },
117
        itype          => { terms => { field => "itype__facet" } },
118
        itype          => { terms => { field => "itype__facet", size => $size} },
118
        location       => { terms => { field => "location__facet" } },
119
        location       => { terms => { field => "location__facet", size => $size } },
119
        'su-geo'       => { terms => { field => "su-geo__facet" } },
120
        'su-geo'       => { terms => { field => "su-geo__facet", size => $size} },
120
        'title-series' => { terms => { field => "title-series__facet" } },
121
        'title-series' => { terms => { field => "title-series__facet", size => $size } },
121
        ccode          => { terms => { field => "ccode__facet" } },
122
        ccode          => { terms => { field => "ccode__facet", size => $size } },
122
        ln             => { terms => { field => "ln__facet" } },
123
        ln             => { terms => { field => "ln__facet", size => $size } },
123
    };
124
    };
124
125
125
    my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
126
    my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
Lines 131-139 sub build_query { Link Here
131
        or $display_library_facets eq 'holding' ) {
132
        or $display_library_facets eq 'holding' ) {
132
        $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet" } };
133
        $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet" } };
133
    }
134
    }
134
    if ( my $ef = $options{expanded_facet} ) {
135
        $res->{aggregations}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount');
136
    };
137
    return $res;
135
    return $res;
138
}
136
}
139
137
Lines 243-249 sub build_query_compat { Link Here
243
    my %options;
241
    my %options;
244
    $options{fields} = \@fields;
242
    $options{fields} = \@fields;
245
    $options{sort} = \@sort_params;
243
    $options{sort} = \@sort_params;
246
    $options{expanded_facet} = $params->{expanded_facet};
247
    my $query = $self->build_query( $query_str, %options );
244
    my $query = $self->build_query( $query_str, %options );
248
245
249
    # We roughly emulate the CGI parameters of the zebra query builder
246
    # We roughly emulate the CGI parameters of the zebra query builder
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-14 / +7 lines)
Lines 132-139 sub count { Link Here
132
132
133
    my ( $error, $results, $facets ) = $search->search_compat(
133
    my ( $error, $results, $facets ) = $search->search_compat(
134
        $query,            $simple_query, \@sort_by,       \@servers,
134
        $query,            $simple_query, \@sort_by,       \@servers,
135
        $results_per_page, $offset,       $expanded_facet, $branches,
135
        $results_per_page, $offset,       $branches,       $query_type,
136
        $query_type,       $scan
136
        $scan
137
      )
137
      )
138
138
139
A search interface somewhat compatible with L<C4::Search->getRecords>. Anything
139
A search interface somewhat compatible with L<C4::Search->getRecords>. Anything
Lines 145-159 get ignored here, along with some other things (like C<@servers>.) Link Here
145
sub search_compat {
145
sub search_compat {
146
    my (
146
    my (
147
        $self,     $query,            $simple_query, $sort_by,
147
        $self,     $query,            $simple_query, $sort_by,
148
        $servers,  $results_per_page, $offset,       $expanded_facet,
148
        $servers,  $results_per_page, $offset,       $branches,
149
        $branches, $query_type,       $scan
149
        $query_type,       $scan
150
    ) = @_;
150
    ) = @_;
151
    my %options;
151
    my %options;
152
    if ( !defined $offset or $offset < 0 ) {
152
    if ( !defined $offset or $offset < 0 ) {
153
        $offset = 0;
153
        $offset = 0;
154
    }
154
    }
155
    $options{offset} = $offset;
155
    $options{offset} = $offset;
156
    $options{expanded_facet} = $expanded_facet;
157
    my $results = $self->search($query, undef, $results_per_page, %options);
156
    my $results = $self->search($query, undef, $results_per_page, %options);
158
157
159
    # Convert each result into a MARC::Record
158
    # Convert each result into a MARC::Record
Lines 171-177 sub search_compat { Link Here
171
    my %result;
170
    my %result;
172
    $result{biblioserver}{hits} = $hits->{'total'};
171
    $result{biblioserver}{hits} = $hits->{'total'};
173
    $result{biblioserver}{RECORDS} = \@records;
172
    $result{biblioserver}{RECORDS} = \@records;
174
    return (undef, \%result, $self->_convert_facets($results->{aggregations}, $expanded_facet));
173
    return (undef, \%result, $self->_convert_facets($results->{aggregations}));
175
}
174
}
176
175
177
=head2 search_auth_compat
176
=head2 search_auth_compat
Lines 418-432 sub max_result_window { Link Here
418
417
419
=head2 _convert_facets
418
=head2 _convert_facets
420
419
421
    my $koha_facets = _convert_facets($es_facets, $expanded_facet);
420
    my $koha_facets = _convert_facets($es_facets);
422
421
423
Converts elasticsearch facets types to the form that Koha expects.
422
Converts elasticsearch facets types to the form that Koha expects.
424
It expects the ES facet name to match the Koha type, for example C<itype>,
423
It expects the ES facet name to match the Koha type, for example C<itype>,
425
C<au>, C<su-to>, etc.
424
C<au>, C<su-to>, etc.
426
425
427
C<$expanded_facet> is the facet that we want to show FacetMaxCount entries for, rather
428
than just 5 like normal.
429
430
=cut
426
=cut
431
427
432
sub _convert_facets {
428
sub _convert_facets {
Lines 476-487 sub _convert_facets { Link Here
476
        next if !exists( $type_to_label{$type} );
472
        next if !exists( $type_to_label{$type} );
477
473
478
        # We restrict to the most popular $limit !results
474
        # We restrict to the most popular $limit !results
479
        my $limit = ( $type eq $exp_facet ) ? C4::Context->preference('FacetMaxCount') : 5;
475
        my $limit = C4::Context->preference('FacetMaxCount');
480
        my $facet = {
476
        my $facet = {
481
            type_id    => $type . '_id',
477
            type_id    => $type . '_id',
482
            expand     => $type,
483
            expandable => ( $type ne $exp_facet )
484
              && ( @{ $data->{buckets} } > $limit ),
485
            "type_label_$type_to_label{$type}{label}" => 1,
478
            "type_label_$type_to_label{$type}{label}" => 1,
486
            type_link_value                    => $type,
479
            type_link_value                    => $type,
487
            order      => $type_to_label{$type}{order},
480
            order      => $type_to_label{$type}{order},
(-)a/catalogue/search.pl (-3 / +2 lines)
Lines 459-465 my $offset = $params->{'offset'} || 0; Link Here
459
$offset = 0 if $offset < 0;
459
$offset = 0 if $offset < 0;
460
my $page = $cgi->param('page') || 1;
460
my $page = $cgi->param('page') || 1;
461
#my $offset = ($page-1)*$results_per_page;
461
#my $offset = ($page-1)*$results_per_page;
462
my $expanded_facet = $params->{'expand'};
463
462
464
# Define some global variables
463
# Define some global variables
465
my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
464
my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
Lines 536-543 eval { Link Here
536
    my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
535
    my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
537
    ( $error, $results_hashref, $facets ) = $searcher->search_compat(
536
    ( $error, $results_hashref, $facets ) = $searcher->search_compat(
538
        $query,            $simple_query, \@sort_by,       \@servers,
537
        $query,            $simple_query, \@sort_by,       \@servers,
539
        $results_per_page, $offset,       $expanded_facet, undef,
538
        $results_per_page, $offset,       undef,           $itemtypes,
540
        $itemtypes,        $query_type,   $scan
539
        $query_type,       $scan
541
    );
540
    );
542
};
541
};
543
542
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc (-3 / +10 lines)
Lines 33-39 Link Here
33
  [% FOREACH facet IN facets_loo.facets %]
33
  [% FOREACH facet IN facets_loo.facets %]
34
  [% IF facets_loo.type_label_CollectionCodes %][% SET facet.facet_label_value = AuthorisedValues.GetByCode('CCODE',facet.facet_label_value,0) || facet.facet_label_value %][% END %]
34
  [% IF facets_loo.type_label_CollectionCodes %][% SET facet.facet_label_value = AuthorisedValues.GetByCode('CCODE',facet.facet_label_value,0) || facet.facet_label_value %][% END %]
35
  [% IF facets_loo.type_label_Language %][% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %][% END %]
35
  [% IF facets_loo.type_label_Language %][% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %][% END %]
36
  [% IF loop.count > 5 && !facet.active %]
37
    <li class="collapsible-facet" style="display:none">
38
  [% ELSE %]
36
    <li>
39
    <li>
40
  [% END %]
37
      [% IF facet.active %]
41
      [% IF facet.active %]
38
        [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _  facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %]
42
        [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _  facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %]
39
        <span class="facet-label">[% facet.facet_label_value | html %]</span>
43
        <span class="facet-label">[% facet.facet_label_value | html %]</span>
Lines 47-55 Link Here
47
      [% END %]
51
      [% END %]
48
    </li>
52
    </li>
49
  [% END %]
53
  [% END %]
50
  [% IF ( facets_loo.expandable ) %]
54
  [% IF facets_loo.facets.size > 5 %]
51
      <li class="showmore">
55
      <li class="moretoggle">
52
          <a href="[% url | $raw %][% IF offset %]&amp;offset=[% offset | uri %][% END %]&amp;expand=[% facets_loo.expand | uri %]#[% facets_loo.type_id | uri %]">Show more</a>
56
          <a href="#"><strong>Show more</strong></a>
57
      </li>
58
      <li class="moretoggle" style="display:none">
59
          <a href="#"><strong>Show less</strong></a>
53
      </li>
60
      </li>
54
  [% END %]
61
  [% END %]
55
</ul></li>
62
</ul></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt (+8 lines)
Lines 667-672 Link Here
667
        [% END %]
667
        [% END %]
668
        var Sticky;
668
        var Sticky;
669
        $(document).ready(function() {
669
        $(document).ready(function() {
670
671
            $(".moretoggle").click(function(e) {
672
                e.preventDefault();
673
                $(this).siblings(".collapsible-facet").toggle();
674
                $(this).siblings(".moretoggle").toggle();
675
                $(this).toggle();
676
            });
677
670
            Sticky = $("#searchheader");
678
            Sticky = $("#searchheader");
671
            Sticky.hcSticky({
679
            Sticky.hcSticky({
672
                stickTo: "main",
680
                stickTo: "main",
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc (-3 / +10 lines)
Lines 42-48 Link Here
42
                            [% FOREACH facet IN facets_loo.facets %]
42
                            [% FOREACH facet IN facets_loo.facets %]
43
                            [% IF facets_loo.type_label_CollectionCodes %][% SET facet.facet_label_value = AuthorisedValues.GetByCode('CCODE',facet.facet_label_value,1) || facet.facet_label_value %][% END %]
43
                            [% IF facets_loo.type_label_CollectionCodes %][% SET facet.facet_label_value = AuthorisedValues.GetByCode('CCODE',facet.facet_label_value,1) || facet.facet_label_value %][% END %]
44
                            [% IF facets_loo.type_label_Language %][% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %][% END %]
44
                            [% IF facets_loo.type_label_Language %][% SET facet.facet_label_value = Languages.GetByISOCode(lang,facet.facet_label_value) || facet.facet_label_value %][% END %]
45
                            [% IF loop.count > 5 && !facet.active %]
46
                                <li class="collapsible-facet" style="display:none">
47
                            [% ELSE %]
45
                                <li>
48
                                <li>
49
                            [% END %]
46
                                  [% IF facet.active %]
50
                                  [% IF facet.active %]
47
                                    [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _  facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %]
51
                                    [% local_url = BLOCK %][% url | $raw %][% "&nolimit=" _  facet.type_link_value _ ":" _ facet.facet_link_value | url %][% END %]
48
                                    <span class="facet-label">[% facet.facet_label_value | html %]</span>
52
                                    <span class="facet-label">[% facet.facet_label_value | html %]</span>
Lines 56-64 Link Here
56
                                  [% END %]
60
                                  [% END %]
57
                                </li>
61
                                </li>
58
                            [% END %]
62
                            [% END %]
59
                            [% IF ( facets_loo.expandable ) %]
63
                            [% IF facets_loo.facets.size > 5 %]
60
                                <li class="showmore">
64
                                <li class="moretoggle">
61
                                    <a href="[% url | $raw %][% IF offset %]&amp;offset=[% offset | uri %][% END %]&amp;expand=[% facets_loo.expand | uri %]#[% facets_loo.type_id | uri %]">Show more</a>
65
                                    <a href="#"><strong>Show more</strong></a>
66
                                </li>
67
                                <li class="moretoggle" style="display:none">
68
                                    <a href="#"><strong>Show less</strong></a>
62
                                </li>
69
                                </li>
63
                            [% END %]
70
                            [% END %]
64
                        </ul>
71
                        </ul>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (+8 lines)
Lines 737-742 function highlightOn() { Link Here
737
}
737
}
738
[% END %]
738
[% END %]
739
$(document).ready(function(){
739
$(document).ready(function(){
740
741
    $(".moretoggle").click(function(e){
742
        e.preventDefault();
743
        $(this).siblings(".collapsible-facet").toggle();
744
        $(this).siblings(".moretoggle").toggle();
745
        $(this).toggle();
746
    });
747
740
    [% IF ( OpacHighlightedWords ) %]
748
    [% IF ( OpacHighlightedWords ) %]
741
        $('a.title').each(function() {
749
        $('a.title').each(function() {
742
            $(this).attr("href", $(this).attr("href") + "&query_desc=[% query_desc | uri %]");
750
            $(this).attr("href", $(this).attr("href") + "&query_desc=[% query_desc | uri %]");
(-)a/opac/opac-detail.pl (-2 / +1 lines)
Lines 224-230 if ($session->param('busc')) { Link Here
224
    {
224
    {
225
        my ($arrParamsBusc, $offset, $results_per_page) = @_;
225
        my ($arrParamsBusc, $offset, $results_per_page) = @_;
226
226
227
        my $expanded_facet = $arrParamsBusc->{'expand'};
228
        my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
227
        my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
229
        my @servers;
228
        my @servers;
230
        @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
229
        @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
Lines 236-242 if ($session->param('busc')) { Link Here
236
        $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
235
        $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
237
        my ($error, $results_hashref, $facets);
236
        my ($error, $results_hashref, $facets);
238
        eval {
237
        eval {
239
            ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
238
            ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
240
        };
239
        };
241
        my $hits;
240
        my $hits;
242
        my @newresults;
241
        my @newresults;
(-)a/opac/opac-search.pl (-4 / +2 lines)
Lines 535-541 $offset = 0 if $offset < 0; Link Here
535
my $page = $cgi->param('page') || 1;
535
my $page = $cgi->param('page') || 1;
536
$offset = ($page-1)*$results_per_page if $page>1;
536
$offset = ($page-1)*$results_per_page if $page>1;
537
my $hits;
537
my $hits;
538
my $expanded_facet = $params->{'expand'};
539
538
540
# Define some global variables
539
# Define some global variables
541
my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
540
my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
Lines 556-562 if (C4::Context->preference('OpacSuppression')) { Link Here
556
}
555
}
557
556
558
my $build_params = {
557
my $build_params = {
559
    expanded_facet => $expanded_facet,
560
    suppress => $suppress
558
    suppress => $suppress
561
};
559
};
562
560
Lines 622-628 if ($tag) { Link Here
622
    # FIXME: No facets for tags search.
620
    # FIXME: No facets for tags search.
623
} elsif ($build_grouped_results) {
621
} elsif ($build_grouped_results) {
624
    eval {
622
    eval {
625
        ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$query_type,$scan);
623
        ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$query_type,$scan);
626
    };
624
    };
627
} else {
625
} else {
628
    $pasarParams .= '&amp;query=' . uri_escape_utf8($query);
626
    $pasarParams .= '&amp;query=' . uri_escape_utf8($query);
Lines 631-637 if ($tag) { Link Here
631
    $pasarParams .= '&amp;query_type=' . uri_escape_utf8($query_type) if ($query_type);
629
    $pasarParams .= '&amp;query_type=' . uri_escape_utf8($query_type) if ($query_type);
632
    my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
630
    my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
633
    eval {
631
    eval {
634
        ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$itemtypes_nocategory,$query_type,$scan,1);
632
        ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes_nocategory,$query_type,$scan,1);
635
};
633
};
636
}
634
}
637
635
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-1 / +6 lines)
Lines 178-184 subtest 'build_authorities_query_compat() tests' => sub { Link Here
178
};
178
};
179
179
180
subtest 'build_query tests' => sub {
180
subtest 'build_query tests' => sub {
181
    plan tests => 38;
181
    plan tests => 40;
182
182
183
    my $qb;
183
    my $qb;
184
184
Lines 205-210 subtest 'build_query tests' => sub { Link Here
205
        "sort parameter properly formed"
205
        "sort parameter properly formed"
206
    );
206
    );
207
207
208
    t::lib::Mocks::mock_preference('FacetMaxCount','37');
209
    $query = $qb->build_query('test', %options);
210
    ok( defined $query->{aggregations}{ccode}{terms}{size},'we need to ask for a size or we get only 5 facet' );
211
    is( $query->{aggregations}{ccode}{terms}{size}, 37,'we ask for the size as defined by the syspref FacetMaxCount');
212
208
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
213
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
209
    $query = $qb->build_query();
214
    $query = $qb->build_query();
210
    ok( defined $query->{aggregations}{homebranch},
215
    ok( defined $query->{aggregations}{homebranch},
(-)a/t/db_dependent/Search.t (-76 / +58 lines)
Lines 347-358 sub run_marc21_search_tests { Link Here
347
    my $results_hashref;
347
    my $results_hashref;
348
    my $facets_loop;
348
    my $facets_loop;
349
    ( undef, $results_hashref, $facets_loop ) =
349
    ( undef, $results_hashref, $facets_loop ) =
350
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
350
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '19', 0, \%branches, \%itemtypes, 'ccl', undef);
351
    is($results_hashref->{biblioserver}->{hits}, 101, "getRecords keyword search for 'book' matched right number of records");
351
    is($results_hashref->{biblioserver}->{hits}, 101, "getRecords keyword search for 'book' matched right number of records");
352
    is(scalar @{$results_hashref->{biblioserver}->{RECORDS}}, 19, "getRecords returned requested number of records");
352
    is(scalar @{$results_hashref->{biblioserver}->{RECORDS}}, 19, "getRecords returned requested number of records");
353
    my $record5 = $results_hashref->{biblioserver}->{RECORDS}->[5];
353
    my $record5 = $results_hashref->{biblioserver}->{RECORDS}->[5];
354
    ( undef, $results_hashref, $facets_loop ) =
354
    ( undef, $results_hashref, $facets_loop ) =
355
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '20', 5, undef, \%branches, \%itemtypes, 'ccl', undef);
355
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '20', 5, \%branches, \%itemtypes, 'ccl', undef);
356
    ok(!defined $results_hashref->{biblioserver}->{RECORDS}->[0] &&
356
    ok(!defined $results_hashref->{biblioserver}->{RECORDS}->[0] &&
357
        !defined $results_hashref->{biblioserver}->{RECORDS}->[1] &&
357
        !defined $results_hashref->{biblioserver}->{RECORDS}->[1] &&
358
        !defined $results_hashref->{biblioserver}->{RECORDS}->[2] &&
358
        !defined $results_hashref->{biblioserver}->{RECORDS}->[2] &&
Lines 361-410 sub run_marc21_search_tests { Link Here
361
        $results_hashref->{biblioserver}->{RECORDS}->[5] eq $record5, "getRecords cursor works");
361
        $results_hashref->{biblioserver}->{RECORDS}->[5] eq $record5, "getRecords cursor works");
362
362
363
    ( undef, $results_hashref, $facets_loop ) =
363
    ( undef, $results_hashref, $facets_loop ) =
364
        getRecords('ti:book', 'ti:book', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
364
        getRecords('ti:book', 'ti:book', [], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, 'ccl', undef);
365
    is($results_hashref->{biblioserver}->{hits}, 11, "getRecords title search for 'book' matched right number of records");
365
    is($results_hashref->{biblioserver}->{hits}, 11, "getRecords title search for 'book' matched right number of records");
366
366
367
    ( undef, $results_hashref, $facets_loop ) =
367
    ( undef, $results_hashref, $facets_loop ) =
368
        getRecords('au:Lessig', 'au:Lessig', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
368
        getRecords('au:Lessig', 'au:Lessig', [], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, 'ccl', undef);
369
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords title search for 'Australia' matched right number of records");
369
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords title search for 'Australia' matched right number of records");
370
370
371
( undef, $results_hashref, $facets_loop ) =
371
( undef, $results_hashref, $facets_loop ) =
372
    getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
372
    getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, \%branches, \%itemtypes, 'ccl', undef);
373
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
373
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
374
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
374
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
375
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
375
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
376
    , "Simple relevance sorting in getRecords matches old behavior");
376
    , "Simple relevance sorting in getRecords matches old behavior");
377
377
378
( undef, $results_hashref, $facets_loop ) =
378
( undef, $results_hashref, $facets_loop ) =
379
    getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
379
    getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, \%branches, \%itemtypes, 'ccl', undef);
380
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
380
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
381
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[6],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
381
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[6],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
382
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'World health statistics 2009^ien'
382
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'World health statistics 2009^ien'
383
    , "Simple ascending author sorting in getRecords matches old behavior");
383
    , "Simple ascending author sorting in getRecords matches old behavior");
384
384
385
( undef, $results_hashref, $facets_loop ) =
385
( undef, $results_hashref, $facets_loop ) =
386
    getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
386
    getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, \%branches, \%itemtypes, 'ccl', undef);
387
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
387
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
388
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[12],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
388
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[12],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
389
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/
389
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/
390
    , "Simple descending author sorting in getRecords matches old behavior");
390
    , "Simple descending author sorting in getRecords matches old behavior");
391
391
392
( undef, $results_hashref, $facets_loop ) =
392
( undef, $results_hashref, $facets_loop ) =
393
    getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
393
    getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, \%branches, \%itemtypes, 'ccl', undef);
394
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies' &&
394
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies' &&
395
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
395
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
396
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
396
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
397
    , "Simple ascending publication date sorting in getRecords matches old behavior");
397
    , "Simple ascending publication date sorting in getRecords matches old behavior");
398
398
399
( undef, $results_hashref, $facets_loop ) =
399
( undef, $results_hashref, $facets_loop ) =
400
    getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
400
    getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, \%branches, \%itemtypes, 'ccl', undef);
401
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Estado de salud/ &&
401
ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Estado de salud/ &&
402
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
402
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
403
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
403
    MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
404
    , "Simple descending publication date sorting in getRecords matches old behavior");
404
    , "Simple descending publication date sorting in getRecords matches old behavior");
405
405
406
    ( undef, $results_hashref, $facets_loop ) =
406
    ( undef, $results_hashref, $facets_loop ) =
407
        getRecords('books', 'books', [ 'relevance' ], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, undef, 1);
407
        getRecords('books', 'books', [ 'relevance' ], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, undef, 1);
408
    $record = MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0]);
408
    $record = MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0]);
409
    is($record->title_proper(), 'Books', "Scan returned requested item");
409
    is($record->title_proper(), 'Books', "Scan returned requested item");
410
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
410
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
Lines 418-424 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
418
    $query_type ) = buildQuery([], [ 'salud' ], [], [], [], 0, 'en');
418
    $query_type ) = buildQuery([], [ 'salud' ], [], [], [], 0, 'en');
419
    like($query, qr/kw\W.*salud/, "Built CCL keyword query");
419
    like($query, qr/kw\W.*salud/, "Built CCL keyword query");
420
420
421
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
421
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
422
    is($results_hashref->{biblioserver}->{hits}, 19, "getRecords generated keyword search for 'salud' matched right number of records");
422
    is($results_hashref->{biblioserver}->{hits}, 19, "getRecords generated keyword search for 'salud' matched right number of records");
423
423
424
    my @newresults = searchResults({'interface' => 'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 18, 0, 0,
424
    my @newresults = searchResults({'interface' => 'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 18, 0, 0,
Lines 430-436 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
430
    $query_type ) = buildQuery([ 'and' ], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
430
    $query_type ) = buildQuery([ 'and' ], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
431
    like($query, qr/kw\W.*salud\W.*and.*kw\W.*higiene/, "Built composed explicit-and CCL keyword query");
431
    like($query, qr/kw\W.*salud\W.*and.*kw\W.*higiene/, "Built composed explicit-and CCL keyword query");
432
432
433
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
433
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
434
    is($results_hashref->{biblioserver}->{hits}, 3, "getRecords generated composed keyword search for 'salud' explicit-and 'higiene' matched right number of records");
434
    is($results_hashref->{biblioserver}->{hits}, 3, "getRecords generated composed keyword search for 'salud' explicit-and 'higiene' matched right number of records");
435
435
436
    ( $error, $query, $simple_query, $query_cgi,
436
    ( $error, $query, $simple_query, $query_cgi,
Lines 438-444 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
438
    $query_type ) = buildQuery([ 'or' ], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
438
    $query_type ) = buildQuery([ 'or' ], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
439
    like($query, qr/kw\W.*salud\W.*or.*kw\W.*higiene/, "Built composed explicit-or CCL keyword query");
439
    like($query, qr/kw\W.*salud\W.*or.*kw\W.*higiene/, "Built composed explicit-or CCL keyword query");
440
440
441
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
441
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
442
    is($results_hashref->{biblioserver}->{hits}, 20, "getRecords generated composed keyword search for 'salud' explicit-or 'higiene' matched right number of records");
442
    is($results_hashref->{biblioserver}->{hits}, 20, "getRecords generated composed keyword search for 'salud' explicit-or 'higiene' matched right number of records");
443
443
444
    ( $error, $query, $simple_query, $query_cgi,
444
    ( $error, $query, $simple_query, $query_cgi,
Lines 446-452 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
446
    $query_type ) = buildQuery([], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
446
    $query_type ) = buildQuery([], [ 'salud', 'higiene' ], [], [], [], 0, 'en');
447
    like($query, qr/kw\W.*salud\W.*and.*kw\W.*higiene/, "Built composed implicit-and CCL keyword query");
447
    like($query, qr/kw\W.*salud\W.*and.*kw\W.*higiene/, "Built composed implicit-and CCL keyword query");
448
448
449
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
449
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
450
    is($results_hashref->{biblioserver}->{hits}, 3, "getRecords generated composed keyword search for 'salud' implicit-and 'higiene' matched right number of records");
450
    is($results_hashref->{biblioserver}->{hits}, 3, "getRecords generated composed keyword search for 'salud' implicit-and 'higiene' matched right number of records");
451
451
452
    ( $error, $query, $simple_query, $query_cgi,
452
    ( $error, $query, $simple_query, $query_cgi,
Lines 455-461 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
455
    like($query, qr/kw\W.*salud\W*and\W*su-to\W.*Laboratorios/, "Faceted query generated correctly");
455
    like($query, qr/kw\W.*salud\W*and\W*su-to\W.*Laboratorios/, "Faceted query generated correctly");
456
    unlike($query_desc, qr/Laboratorios/, "Facets not included in query description");
456
    unlike($query_desc, qr/Laboratorios/, "Facets not included in query description");
457
457
458
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
458
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
459
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated faceted search matched right number of records");
459
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated faceted search matched right number of records");
460
460
461
461
Lines 463-469 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
463
    $query_desc, $limit, $limit_cgi, $limit_desc,
463
    $query_desc, $limit, $limit_cgi, $limit_desc,
464
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'mc-itype:MP', 'mc-itype:MU' ], [], 0, 'en');
464
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'mc-itype:MP', 'mc-itype:MU' ], [], 0, 'en');
465
465
466
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
466
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
467
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated mc-faceted search matched right number of records");
467
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated mc-faceted search matched right number of records");
468
468
469
469
Lines 471-483 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
471
    $query_desc, $limit, $limit_cgi, $limit_desc,
471
    $query_desc, $limit, $limit_cgi, $limit_desc,
472
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'mc-loc:GEN', 'branch:FFL' ], [], 0, 'en');
472
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'mc-loc:GEN', 'branch:FFL' ], [], 0, 'en');
473
473
474
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
474
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
475
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated multi-faceted search matched right number of records");
475
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated multi-faceted search matched right number of records");
476
476
477
    ( $error, $query, $simple_query, $query_cgi,
477
    ( $error, $query, $simple_query, $query_cgi,
478
    $query_desc, $limit, $limit_cgi, $limit_desc,
478
    $query_desc, $limit, $limit_cgi, $limit_desc,
479
    $query_type ) = buildQuery([], [ 'NEKLS' ], [ 'Code-institution' ], [], [], 0, 'en');
479
    $query_type ) = buildQuery([], [ 'NEKLS' ], [ 'Code-institution' ], [], [], 0, 'en');
480
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
480
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
481
    is($results_hashref->{biblioserver}->{hits}, 12,
481
    is($results_hashref->{biblioserver}->{hits}, 12,
482
       'search using index whose name contains "ns" returns expected results (bug 10271)');
482
       'search using index whose name contains "ns" returns expected results (bug 10271)');
483
483
Lines 485-496 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
485
    ( $error, $query, $simple_query, $query_cgi,
485
    ( $error, $query, $simple_query, $query_cgi,
486
    $query_desc, $limit, $limit_cgi, $limit_desc,
486
    $query_desc, $limit, $limit_cgi, $limit_desc,
487
    $query_type ) = buildQuery([], [ 'book' ], [ 'kw' ], [], [], 0, 'en');
487
    $query_type ) = buildQuery([], [ 'book' ], [ 'kw' ], [], [], 0, 'en');
488
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
488
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
489
    is($results_hashref->{biblioserver}->{hits}, 101, "Search for 'book' with index set to 'kw' returns 101 hits");
489
    is($results_hashref->{biblioserver}->{hits}, 101, "Search for 'book' with index set to 'kw' returns 101 hits");
490
    ( $error, $query, $simple_query, $query_cgi,
490
    ( $error, $query, $simple_query, $query_cgi,
491
    $query_desc, $limit, $limit_cgi, $limit_desc,
491
    $query_desc, $limit, $limit_cgi, $limit_desc,
492
    $query_type ) = buildQuery([ 'and' ], [ 'book', 'another' ], [ 'kw', 'kw' ], [], [], 0, 'en');
492
    $query_type ) = buildQuery([ 'and' ], [ 'book', 'another' ], [ 'kw', 'kw' ], [], [], 0, 'en');
493
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
493
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
494
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'kw:book && kw:another' returns 1 hit");
494
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'kw:book && kw:another' returns 1 hit");
495
    $UseQueryParser = 0;
495
    $UseQueryParser = 0;
496
496
Lines 498-504 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
498
    $query_desc, $limit, $limit_cgi, $limit_desc,
498
    $query_desc, $limit, $limit_cgi, $limit_desc,
499
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'available' ], [], 0, 'en');
499
    $query_type ) = buildQuery([], [ '' ], [ 'kw' ], [ 'available' ], [], 0, 'en');
500
500
501
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
501
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
502
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated availability-limited search matched right number of records");
502
    is($results_hashref->{biblioserver}->{hits}, 2, "getRecords generated availability-limited search matched right number of records");
503
503
504
    @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
504
    @newresults = searchResults({'interface'=>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
Lines 514-541 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
514
    $query_desc, $limit, $limit_cgi, $limit_desc,
514
    $query_desc, $limit, $limit_cgi, $limit_desc,
515
    $query_type ) = buildQuery([], [ 'pqf=@attr 1=_ALLRECORDS @attr 2=103 ""' ], [], [], [], 0, 'en');
515
    $query_type ) = buildQuery([], [ 'pqf=@attr 1=_ALLRECORDS @attr 2=103 ""' ], [], [], [], 0, 'en');
516
516
517
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
517
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
518
    is($results_hashref->{biblioserver}->{hits}, 180, "getRecords on _ALLRECORDS PQF returned all records");
518
    is($results_hashref->{biblioserver}->{hits}, 180, "getRecords on _ALLRECORDS PQF returned all records");
519
519
520
    ( $error, $query, $simple_query, $query_cgi,
520
    ( $error, $query, $simple_query, $query_cgi,
521
    $query_desc, $limit, $limit_cgi, $limit_desc,
521
    $query_desc, $limit, $limit_cgi, $limit_desc,
522
    $query_type ) = buildQuery([], [ 'pqf=@attr 1=1016 "Lessig"' ], [], [], [], 0, 'en');
522
    $query_type ) = buildQuery([], [ 'pqf=@attr 1=1016 "Lessig"' ], [], [], [], 0, 'en');
523
523
524
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
524
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
525
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords PQF author search for Lessig returned proper number of matches");
525
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords PQF author search for Lessig returned proper number of matches");
526
526
527
    ( $error, $query, $simple_query, $query_cgi,
527
    ( $error, $query, $simple_query, $query_cgi,
528
    $query_desc, $limit, $limit_cgi, $limit_desc,
528
    $query_desc, $limit, $limit_cgi, $limit_desc,
529
    $query_type ) = buildQuery([], [ 'ccl=au:Lessig' ], [], [], [], 0, 'en');
529
    $query_type ) = buildQuery([], [ 'ccl=au:Lessig' ], [], [], [], 0, 'en');
530
530
531
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
531
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
532
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords CCL author search for Lessig returned proper number of matches");
532
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords CCL author search for Lessig returned proper number of matches");
533
533
534
    ( $error, $query, $simple_query, $query_cgi,
534
    ( $error, $query, $simple_query, $query_cgi,
535
    $query_desc, $limit, $limit_cgi, $limit_desc,
535
    $query_desc, $limit, $limit_cgi, $limit_desc,
536
    $query_type ) = buildQuery([], [ 'cql=dc.author any lessig' ], [], [], [], 0, 'en');
536
    $query_type ) = buildQuery([], [ 'cql=dc.author any lessig' ], [], [], [], 0, 'en');
537
537
538
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
538
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
539
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords CQL author search for Lessig returned proper number of matches");
539
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords CQL author search for Lessig returned proper number of matches");
540
540
541
    $QueryStemming = $QueryAutoTruncate = $QueryFuzzy = 0;
541
    $QueryStemming = $QueryAutoTruncate = $QueryFuzzy = 0;
Lines 544-550 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
544
    $query_desc, $limit, $limit_cgi, $limit_desc,
544
    $query_desc, $limit, $limit_cgi, $limit_desc,
545
    $query_type ) = buildQuery([], [ 'salud' ], [ 'kw' ], [], [], 0, 'en');
545
    $query_type ) = buildQuery([], [ 'salud' ], [ 'kw' ], [], [], 0, 'en');
546
546
547
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
547
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
548
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
548
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
549
    is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
549
    is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
550
550
Lines 554-567 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
554
    $query_desc, $limit, $limit_cgi, $limit_desc,
554
    $query_desc, $limit, $limit_cgi, $limit_desc,
555
    $query_type ) = buildQuery([], [ 'medic' ], [ 'kw' ], [], [], 0, 'en');
555
    $query_type ) = buildQuery([], [ 'medic' ], [ 'kw' ], [], [], 0, 'en');
556
556
557
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
557
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
558
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic' returns matches  with automatic truncation on");
558
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic' returns matches  with automatic truncation on");
559
559
560
    ( $error, $query, $simple_query, $query_cgi,
560
    ( $error, $query, $simple_query, $query_cgi,
561
    $query_desc, $limit, $limit_cgi, $limit_desc,
561
    $query_desc, $limit, $limit_cgi, $limit_desc,
562
    $query_type ) = buildQuery([], [ 'medic*' ], [ 'kw' ], [], [], 0, 'en');
562
    $query_type ) = buildQuery([], [ 'medic*' ], [ 'kw' ], [], [], 0, 'en');
563
563
564
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
564
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
565
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic*' returns matches with automatic truncation on");
565
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic*' returns matches with automatic truncation on");
566
566
567
    $QueryStemming = $QueryFuzzy = $QueryAutoTruncate = 0;
567
    $QueryStemming = $QueryFuzzy = $QueryAutoTruncate = 0;
Lines 569-581 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
569
    ( $error, $query, $simple_query, $query_cgi,
569
    ( $error, $query, $simple_query, $query_cgi,
570
    $query_desc, $limit, $limit_cgi, $limit_desc,
570
    $query_desc, $limit, $limit_cgi, $limit_desc,
571
    $query_type ) = buildQuery([], [ 'web application' ], [ 'kw' ], [], [], 0, 'en');
571
    $query_type ) = buildQuery([], [ 'web application' ], [ 'kw' ], [], [], 0, 'en');
572
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
572
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
573
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'web application' returns one hit with QueryWeightFields on");
573
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'web application' returns one hit with QueryWeightFields on");
574
574
575
    ( $error, $query, $simple_query, $query_cgi,
575
    ( $error, $query, $simple_query, $query_cgi,
576
    $query_desc, $limit, $limit_cgi, $limit_desc,
576
    $query_desc, $limit, $limit_cgi, $limit_desc,
577
    $query_type ) = buildQuery([], [ 'web "application' ], [ 'kw' ], [], [], 0, 'en');
577
    $query_type ) = buildQuery([], [ 'web "application' ], [ 'kw' ], [], [], 0, 'en');
578
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
578
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
579
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'web \"application' returns one hit with QueryWeightFields on (bug 7518)");
579
    is($results_hashref->{biblioserver}->{hits}, 1, "Search for 'web \"application' returns one hit with QueryWeightFields on (bug 7518)");
580
580
581
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryAutoTruncate = 0;
581
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryAutoTruncate = 0;
Lines 583-596 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
583
    $query_desc, $limit, $limit_cgi, $limit_desc,
583
    $query_desc, $limit, $limit_cgi, $limit_desc,
584
    $query_type ) = buildQuery([], [ 'medic' ], [ 'kw' ], [], [], 0, 'en');
584
    $query_type ) = buildQuery([], [ 'medic' ], [ 'kw' ], [], [], 0, 'en');
585
585
586
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
586
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
587
    is($results_hashref->{biblioserver}->{hits}, undef, "Search for 'medic' returns no matches with automatic truncation off");
587
    is($results_hashref->{biblioserver}->{hits}, undef, "Search for 'medic' returns no matches with automatic truncation off");
588
588
589
    ( $error, $query, $simple_query, $query_cgi,
589
    ( $error, $query, $simple_query, $query_cgi,
590
    $query_desc, $limit, $limit_cgi, $limit_desc,
590
    $query_desc, $limit, $limit_cgi, $limit_desc,
591
    $query_type ) = buildQuery([], [ 'medic*' ], [ 'kw' ], [], [], 0, 'en');
591
    $query_type ) = buildQuery([], [ 'medic*' ], [ 'kw' ], [], [], 0, 'en');
592
592
593
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
593
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
594
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic*' returns matches with automatic truncation off");
594
    is($results_hashref->{biblioserver}->{hits}, 5, "Search for 'medic*' returns matches with automatic truncation off");
595
595
596
    $QueryStemming = $QueryWeightFields = 1;
596
    $QueryStemming = $QueryWeightFields = 1;
Lines 599-605 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
599
    $query_desc, $limit, $limit_cgi, $limit_desc,
599
    $query_desc, $limit, $limit_cgi, $limit_desc,
600
    $query_type ) = buildQuery([], [ 'pressed' ], [ 'kw' ], [], [], 0, 'en');
600
    $query_type ) = buildQuery([], [ 'pressed' ], [ 'kw' ], [], [], 0, 'en');
601
601
602
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
602
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
603
    is($results_hashref->{biblioserver}->{hits}, 7, "Search for 'pressed' returns matches when stemming (and query weighting) is on");
603
    is($results_hashref->{biblioserver}->{hits}, 7, "Search for 'pressed' returns matches when stemming (and query weighting) is on");
604
604
605
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryAutoTruncate = 0;
605
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryAutoTruncate = 0;
Lines 607-613 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
607
    $query_desc, $limit, $limit_cgi, $limit_desc,
607
    $query_desc, $limit, $limit_cgi, $limit_desc,
608
    $query_type ) = buildQuery([], [ 'pressed' ], [ 'kw' ], [], [], 0, 'en');
608
    $query_type ) = buildQuery([], [ 'pressed' ], [ 'kw' ], [], [], 0, 'en');
609
609
610
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
610
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
611
    is($results_hashref->{biblioserver}->{hits}, undef, "Search for 'pressed' returns no matches when stemming is off");
611
    is($results_hashref->{biblioserver}->{hits}, undef, "Search for 'pressed' returns no matches when stemming is off");
612
612
613
    ( $error, $query, $simple_query, $query_cgi,
613
    ( $error, $query, $simple_query, $query_cgi,
Lines 629-644 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
629
    isnt($error, undef, "SimpleSearch returns an error when passed gibberish");
629
    isnt($error, undef, "SimpleSearch returns an error when passed gibberish");
630
630
631
    warning_like {( undef, $results_hashref, $facets_loop ) =
631
    warning_like {( undef, $results_hashref, $facets_loop ) =
632
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'nonsense', undef) }
632
        getRecords('kw:book', 'book', [], [ 'biblioserver' ], '19', 0, \%branches, \%itemtypes, 'nonsense', undef) }
633
        qr/Unknown query_type/, "getRecords warns about unknown query type";
633
        qr/Unknown query_type/, "getRecords warns about unknown query type";
634
634
635
    warning_like {( undef, $results_hashref, $facets_loop ) =
635
    warning_like {( undef, $results_hashref, $facets_loop ) =
636
        getRecords('pqf=@attr 1=4 "title"', 'pqf=@attr 1=4 "title"', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, '', undef) }
636
        getRecords('pqf=@attr 1=4 "title"', 'pqf=@attr 1=4 "title"', [], [ 'biblioserver' ], '19', 0, \%branches, \%itemtypes, '', undef) }
637
        qr/WARNING: query problem/, "getRecords warns when query type is not specified for non-CCL query";
637
        qr/WARNING: query problem/, "getRecords warns when query type is not specified for non-CCL query";
638
638
639
    # Let's just test a few other bits and bobs, just for fun
639
    # Let's just test a few other bits and bobs, just for fun
640
640
641
    ($error, $results_hashref, $facets_loop) = getRecords("Godzina pąsowej róży","Godzina pąsowej róży",[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
641
    ($error, $results_hashref, $facets_loop) = getRecords("Godzina pąsowej róży","Godzina pąsowej róży",[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
642
    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
642
    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
643
        $results_hashref->{'biblioserver'}->{"RECORDS"});
643
        $results_hashref->{'biblioserver'}->{"RECORDS"});
644
    is($newresults[0]->{'alternateholdings_count'}, 1, 'Alternate holdings filled in correctly');
644
    is($newresults[0]->{'alternateholdings_count'}, 1, 'Alternate holdings filled in correctly');
Lines 657-670 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
657
        }
657
        }
658
    });
658
    });
659
659
660
    ($error, $results_hashref, $facets_loop) = getRecords("TEST12121212","TEST12121212",[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
660
    ($error, $results_hashref, $facets_loop) = getRecords("TEST12121212","TEST12121212",[ ], [ 'biblioserver' ],20,0,\%branches,\%itemtypes,$query_type,0);
661
    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
661
    @newresults = searchResults({'interface'=>'intranet'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
662
        $results_hashref->{'biblioserver'}->{"RECORDS"});
662
        $results_hashref->{'biblioserver'}->{"RECORDS"});
663
    ok(!exists($newresults[0]->{norequests}), 'presence of a transit does not block hold request action (bug 10741)');
663
    ok(!exists($newresults[0]->{norequests}), 'presence of a transit does not block hold request action (bug 10741)');
664
664
665
    ## Regression test for bug 10684
665
    ## Regression test for bug 10684
666
    ( undef, $results_hashref, $facets_loop ) =
666
    ( undef, $results_hashref, $facets_loop ) =
667
        getRecords('ti:punctuation', 'punctuation', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
667
        getRecords('ti:punctuation', 'punctuation', [], [ 'biblioserver' ], '19', 0, \%branches, \%itemtypes, 'ccl', undef);
668
    is($results_hashref->{biblioserver}->{hits}, 1, "search for ti:punctuation returned expected number of records");
668
    is($results_hashref->{biblioserver}->{hits}, 1, "search for ti:punctuation returned expected number of records");
669
    warning_like { @newresults = searchResults({'intranet' => 'intranet'}, $query_desc,
669
    warning_like { @newresults = searchResults({'intranet' => 'intranet'}, $query_desc,
670
                    $results_hashref->{'biblioserver'}->{'hits'}, 20, 0, 0,
670
                    $results_hashref->{'biblioserver'}->{'hits'}, 20, 0, 0,
Lines 812-818 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
812
812
813
    # retrieve records that are larger than the MARC limit of 99,999 octets
813
    # retrieve records that are larger than the MARC limit of 99,999 octets
814
    ( undef, $results_hashref, $facets_loop ) =
814
    ( undef, $results_hashref, $facets_loop ) =
815
        getRecords('ti:marc the large record', '', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
815
        getRecords('ti:marc the large record', '', [], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, 'ccl', undef);
816
    is($results_hashref->{biblioserver}->{hits}, 1, "Can do a search that retrieves an over-large bib record (bug 11096)");
816
    is($results_hashref->{biblioserver}->{hits}, 1, "Can do a search that retrieves an over-large bib record (bug 11096)");
817
    @newresults = searchResults({'interface' =>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 10, 0, 0,
817
    @newresults = searchResults({'interface' =>'opac'}, $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 10, 0, 0,
818
        $results_hashref->{'biblioserver'}->{"RECORDS"});
818
        $results_hashref->{'biblioserver'}->{"RECORDS"});
Lines 829-835 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
829
    # verify that we don't attempt to sort if no results were returned
829
    # verify that we don't attempt to sort if no results were returned
830
    # because of a query error
830
    # because of a query error
831
    warning_like {( undef, $results_hashref, $facets_loop ) =
831
    warning_like {( undef, $results_hashref, $facets_loop ) =
832
        getRecords('ccl=( AND )', '', ['title_az'], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef)
832
        getRecords('ccl=( AND )', '', ['title_az'], [ 'biblioserver' ], '20', 0, \%branches, \%itemtypes, 'ccl', undef)
833
    } qr/WARNING: query problem with/, 'got warning instead of crash when attempting to run invalid query (bug 9578)';
833
    } qr/WARNING: query problem with/, 'got warning instead of crash when attempting to run invalid query (bug 9578)';
834
    
834
    
835
    # Test facet calculation
835
    # Test facet calculation
Lines 860-883 ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],' Link Here
860
    # Test _get_facets_info
860
    # Test _get_facets_info
861
    my $facets_info = C4::Search::_get_facets_info( $facets );
861
    my $facets_info = C4::Search::_get_facets_info( $facets );
862
    my $expected_facets_info_marc21 = {
862
    my $expected_facets_info_marc21 = {
863
                   'au' => { 'expanded'    => undef,
863
                   'au' => { 'label_value' => "Authors" },
864
                             'label_value' => "Authors" },
864
                'ccode' => { 'label_value' => "CollectionCodes" },
865
                'ccode' => { 'expanded'    => undef,
865
        'holdingbranch' => { 'label_value' => "HoldingLibrary" },
866
                             'label_value' => "CollectionCodes" },
866
                'itype' => { 'label_value' => "ItemTypes" },
867
        'holdingbranch' => { 'expanded'    => undef,
867
             'location' => { 'label_value' => "Location" },
868
                             'label_value' => "HoldingLibrary" },
868
                   'se' => { 'label_value' => "Series" },
869
                'itype' => { 'expanded'    => undef,
869
               'su-geo' => { 'label_value' => "Places" },
870
                             'label_value' => "ItemTypes" },
870
                'su-to' => { 'label_value' => "Topics" },
871
             'location' => { 'expanded'    => undef,
871
                'su-ut' => { 'label_value' => "Titles" }
872
                             'label_value' => "Location" },
873
                   'se' => { 'expanded'    => undef,
874
                             'label_value' => "Series" },
875
               'su-geo' => { 'expanded'    => undef,
876
                             'label_value' => "Places" },
877
                'su-to' => { 'expanded'    => undef,
878
                             'label_value' => "Topics" },
879
                'su-ut' => { 'expanded'    => undef,
880
                             'label_value' => "Titles" }
881
    };
872
    };
882
    delete $expected_facets_info_marc21->{holdingbranch}
873
    delete $expected_facets_info_marc21->{holdingbranch}
883
        if Koha::Libraries->count == 1;
874
        if Koha::Libraries->count == 1;
Lines 959-980 sub run_unimarc_search_tests { Link Here
959
    my $facets      = C4::Koha::getFacets();
950
    my $facets      = C4::Koha::getFacets();
960
    my $facets_info = C4::Search::_get_facets_info( $facets );
951
    my $facets_info = C4::Search::_get_facets_info( $facets );
961
    my $expected_facets_info_unimarc = {
952
    my $expected_facets_info_unimarc = {
962
                   'au' => { 'expanded'    => undef,
953
                   'au' => { 'label_value' => "Authors" },
963
                             'label_value' => "Authors" },
954
                'ccode' => { 'label_value' => "CollectionCodes" },
964
                'ccode' => { 'expanded'    => undef,
955
        'holdingbranch' => { 'label_value' => "HoldingLibrary" },
965
                             'label_value' => "CollectionCodes" },
956
             'location' => { 'label_value' => "Location" },
966
        'holdingbranch' => { 'expanded'    => undef,
957
                   'se' => { 'label_value' => "Series" },
967
                             'label_value' => "HoldingLibrary" },
958
               'su-geo' => { 'label_value' => "Places" },
968
             'location' => { 'expanded'    => undef,
959
                'su-to' => { 'label_value' => "Topics" },
969
                             'label_value' => "Location" },
960
                'su-ut' => { 'label_value' => "Titles" }
970
                   'se' => { 'expanded'    => undef,
971
                             'label_value' => "Series" },
972
               'su-geo' => { 'expanded'    => undef,
973
                             'label_value' => "Places" },
974
                'su-to' => { 'expanded'    => undef,
975
                             'label_value' => "Topics" },
976
                'su-ut' => { 'expanded'    => undef,
977
                             'label_value' => "Titles" }
978
    };
961
    };
979
    delete $expected_facets_info_unimarc->{holdingbranch}
962
    delete $expected_facets_info_unimarc->{holdingbranch}
980
        if Koha::Libraries->count == 1;
963
        if Koha::Libraries->count == 1;
981
- 

Return to bug 14419