From a690af7ef92a4b5eb58645e21cf9632959a200fc Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Tue, 24 Feb 2015 14:43:01 +1300 Subject: [PATCH] Bug 12478 - more authorites Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- .../Elasticsearch/QueryBuilder.pm | 2 +- Koha/SearchEngine/Elasticsearch/Search.pm | 30 ++++++++++++------- opac/opac-authorities-home.pl | 3 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index ec6309782e..3fc238c36e 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -265,7 +265,7 @@ sub build_authorities_query { my @filter_parts; foreach my $s ( @{ $search->{searches} } ) { my ($wh, $op, $val) = @{ $s }{qw(where operator value)}; - $wh = '_any' if $wh eq 'any'; + $wh = '_all' if $wh eq 'any'; if ($op eq 'is' || $op eq '=') { # look for something that matches completely # note, '=' is about numerical vals. May need special handling. diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 87c2d73a83..c1d3adce89 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -80,7 +80,7 @@ sub search { if (exists $options{offset}) { $paging{start} = $options{offset}; } else { - $page = (!defined($page) || ($page <= 0)) ? 1 : $page - 1; + $page = (!defined($page) || ($page <= 0)) ? 0 : $page - 1; $paging{start} = $page * $paging{limit}; } $self->store( @@ -136,27 +136,37 @@ sub search_compat { return (undef, \%result, $self->_convert_facets($results->{facets})); } -=head2 search_marc +=head2 search_auth_compat my ( $results, $total ) = - $searcher->search_marc( $query, $page, $count, %options ); + $searcher->search_auth_compat( $query, $page, $count, %options ); -This has a similar calling convention to L, however it assumes that all -the results are going to contain MARC, and just provides an arrayref of them, -along with a count of the total number of results. +This has a similar calling convention to L, however it returns its +results in a form the same as L. =cut -sub search_marc { - # TODO this probably should be temporary, until something more - # comprehensive is implemented using Koha::RecordProcessor and such. +sub search_auth_compat { my $self = shift; + my $database = Koha::Database->new(); + my $schema = $database->schema(); my $res = $self->search(@_); my @records; $res->each(sub { - my $marc_json = @_[0]->{record}; + my %result; + my $record = @_[0]; + my $marc_json = $record->{record}; + # I wonder if these should be real values defined in the mapping + # rather than hard-coded conversions. + $result{authid} = $record{Local-Number}; + # TODO put all this info into the record at index time so we + # don't have to go and sort it all out now. + my $rs = $schema->resultset('auth_types')->search({ authtypecode => $authtypecode }); + my $authtype = $rs->first; + my $authtypecode = $record{authtype}; my $marc = $self->json2marc($marc_json); + die Dumper(\@_); push @records, $marc; }); return (\@records, $res->total); diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index a99bc4742e..d22a53d8c7 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -68,8 +68,7 @@ if ( $op eq "do_search" ) { # die Dumper(\@marclist, \@and_or, # \@excluding, \@operator, \@value, $authtypecode, $orderby, $query); my ( $results, $total ) = - $searcher->search_marc( $search_query, $startfrom, $resultsperpage ); - + $searcher->search_auth_compat( $search_query, $startfrom, $resultsperpage ); ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "opac-authoritiessearchresultlist.tt", -- 2.20.1