Bug 12478 - more authorites
authorRobin Sheat <robin@catalyst.net.nz>
Tue, 24 Feb 2015 01:43:01 +0000 (14:43 +1300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 26 Apr 2016 12:55:13 +0000 (09:55 -0300)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
Koha/SearchEngine/Elasticsearch/Search.pm
opac/opac-authorities-home.pl

index ec63097..3fc238c 100644 (file)
@@ -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.
index 87c2d73..c1d3adc 100644 (file)
@@ -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<search>, 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<search>, however it returns its
+results in a form the same as L<C4::AuthoritiesMarc::SearchAuthorities>.
 
 =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);
index a99bc47..d22a53d 100755 (executable)
@@ -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",