| Lines 84-106
          sub search {
      
      
        Link Here | 
        
          | 84 |     my ($self, $query, $page, $count, %options) = @_; | 84 |     my ($self, $query, $page, $count, %options) = @_; | 
        
          | 85 |  | 85 |  | 
        
          | 86 |     my $params = $self->get_elasticsearch_params(); | 86 |     my $params = $self->get_elasticsearch_params(); | 
            
              | 87 |     my %paging; |  |  | 
        
          | 88 |     # 20 is the default number of results per page | 87 |     # 20 is the default number of results per page | 
          
            
              | 89 |     $paging{limit} = $count || 20; | 88 |     $query->{size} = $count || 20; | 
            
              | 90 |     # ES/Catmandu doesn't want pages, it wants a record to start from. | 89 |     # ES doesn't want pages, it wants a record to start from. | 
        
          | 91 |     if (exists $options{offset}) { | 90 |     if (exists $options{offset}) { | 
          
            
              | 92 |         $paging{start} = $options{offset}; | 91 |         $query->{from} = $options{offset}; | 
        
          | 93 |     } else { | 92 |     } else { | 
        
          | 94 |         $page = (!defined($page) || ($page <= 0)) ? 0 : $page - 1; | 93 |         $page = (!defined($page) || ($page <= 0)) ? 0 : $page - 1; | 
          
            
              | 95 |         $paging{start} = $page * $paging{limit}; | 94 |         $query->{from} = $page * $query->{size}; | 
        
          | 96 |     } | 95 |     } | 
          
            
              | 97 |     $self->store( | 96 |     my $elasticsearch = $self->get_elasticsearch(); | 
            
              | 98 |         Catmandu::Store::ElasticSearch->new( |  |  | 
            
              | 99 |             %$params, | 
            
              | 100 |         ) | 
            
              | 101 |     ) unless $self->store; | 
        
          | 102 |     my $results = eval { | 97 |     my $results = eval { | 
          
            
              | 103 |         $self->store->bag->search( %$query, %paging ); | 98 |         $elasticsearch->search( | 
            
              |  |  | 99 |             index => $params->{index_name}, | 
            
              | 100 |             body => $query | 
            
              | 101 |         ); | 
        
          | 104 |     }; | 102 |     }; | 
        
          | 105 |     if ($@) { | 103 |     if ($@) { | 
        
          | 106 |         die $self->process_error($@); | 104 |         die $self->process_error($@); | 
  
    | Lines 163-175
          sub search_compat {
      
      
        Link Here | 
        
          | 163 |     # opac-search expects results to be put in the | 161 |     # opac-search expects results to be put in the | 
        
          | 164 |     # right place in the array, according to $offset | 162 |     # right place in the array, according to $offset | 
        
          | 165 |     my $index = $offset; | 163 |     my $index = $offset; | 
          
            
              | 166 |     $results->each(sub { | 164 |     my $hits = $results->{'hits'}; | 
            
              | 167 |         $records[$index++] = $self->decode_record_from_result(@_); | 165 |     foreach my $es_record (@{$hits->{'hits'}}) { | 
            
              | 168 |     }); | 166 |         $records[$index++] = $self->decode_record_from_result($es_record->{'_source'}); | 
            
              |  |  | 167 |     } | 
            
              | 168 |  | 
        
          | 169 |     # consumers of this expect a name-spaced result, we provide the default | 169 |     # consumers of this expect a name-spaced result, we provide the default | 
        
          | 170 |     # configuration. | 170 |     # configuration. | 
        
          | 171 |     my %result; | 171 |     my %result; | 
          
            
              | 172 |     $result{biblioserver}{hits} = $results->total; | 172 |     $result{biblioserver}{hits} = $hits->{'total'}; | 
        
          | 173 |     $result{biblioserver}{RECORDS} = \@records; | 173 |     $result{biblioserver}{RECORDS} = \@records; | 
        
          | 174 |     return (undef, \%result, $self->_convert_facets($results->{aggregations}, $expanded_facet)); | 174 |     return (undef, \%result, $self->_convert_facets($results->{aggregations}, $expanded_facet)); | 
        
          | 175 | } | 175 | } | 
  
    | Lines 177-183
          sub search_compat {
      
      
        Link Here | 
        
          | 177 | =head2 search_auth_compat | 177 | =head2 search_auth_compat | 
        
          | 178 |  | 178 |  | 
        
          | 179 |     my ( $results, $total ) = | 179 |     my ( $results, $total ) = | 
          
            
              | 180 |       $searcher->search_auth_compat( $query, $page, $count, %options ); | 180 |       $searcher->search_auth_compat( $query, $offset, $count, $skipmetadata, %options ); | 
        
          | 181 |  | 181 |  | 
        
          | 182 | This has a similar calling convention to L<search>, however it returns its | 182 | This has a similar calling convention to L<search>, however it returns its | 
        
          | 183 | results in a form the same as L<C4::AuthoritiesMarc::SearchAuthorities>. | 183 | results in a form the same as L<C4::AuthoritiesMarc::SearchAuthorities>. | 
  
    | Lines 185-216
          results in a form the same as L<C4::AuthoritiesMarc::SearchAuthorities>.
      
      
        Link Here | 
        
          | 185 | =cut | 185 | =cut | 
        
          | 186 |  | 186 |  | 
        
          | 187 | sub search_auth_compat { | 187 | sub search_auth_compat { | 
          
            
              | 188 |     my $self = shift; | 188 |     my ($self, $query, $offset, $count, $skipmetadata, %options) = @_; | 
        
          | 189 |  | 189 |  | 
          
            
              | 190 |     # TODO handle paging | 190 |     if ( !defined $offset or $offset <= 0 ) { | 
            
              |  |  | 191 |         $offset = 1; | 
            
              | 192 |     } | 
            
              | 193 |     # Uh, authority search uses 1-based offset.. | 
            
              | 194 |     $options{offset} = $offset - 1; | 
        
          | 191 |     my $database = Koha::Database->new(); | 195 |     my $database = Koha::Database->new(); | 
        
          | 192 |     my $schema   = $database->schema(); | 196 |     my $schema   = $database->schema(); | 
          
            
              | 193 |     my $res      = $self->search(@_); | 197 |     my $res      = $self->search($query, undef, $count, %options); | 
            
              |  |  | 198 |  | 
        
          | 194 |     my $bib_searcher = Koha::SearchEngine::Elasticsearch::Search->new({index => 'biblios'}); | 199 |     my $bib_searcher = Koha::SearchEngine::Elasticsearch::Search->new({index => 'biblios'}); | 
        
          | 195 |     my @records; | 200 |     my @records; | 
          
            
              | 196 |     $res->each( | 201 |     my $hits = $res->{'hits'}; | 
            
              | 197 |         sub { | 202 |     foreach my $es_record (@{$hits->{'hits'}}) { | 
            
              | 198 |             my %result; | 203 |         my $record = $es_record->{'_source'}; | 
            
              |  |  | 204 |         my %result; | 
        
          | 199 |  | 205 |  | 
          
            
              | 200 |             # I wonder if these should be real values defined in the mapping | 206 |         # I wonder if these should be real values defined in the mapping | 
            
              | 201 |             # rather than hard-coded conversions. | 207 |         # rather than hard-coded conversions. | 
            
              | 202 |             my $record    = $_[0]; | 208 |         #my $record    = $_[0]; | 
            
              | 203 |             # Handle legacy nested arrays indexed with splitting enabled. | 209 |         # Handle legacy nested arrays indexed with splitting enabled. | 
            
              | 204 |             my $authid = $record->{ 'Local-number' }[0]; | 210 |         my $authid = $record->{ 'Local-number' }[0]; | 
            
              | 205 |             $authid = @$authid[0] if (ref $authid eq 'ARRAY'); | 211 |         $authid = @$authid[0] if (ref $authid eq 'ARRAY'); | 
        
          | 206 |  | 212 |  | 
          
            
              | 207 |             $result{authid} = $authid; | 213 |         $result{authid} = $authid; | 
        
          | 208 |  | 214 |  | 
            
              |  |  | 215 |         if (!defined $skipmetadata || !$skipmetadata) { | 
        
          | 209 |             # TODO put all this info into the record at index time so we | 216 |             # TODO put all this info into the record at index time so we | 
        
          | 210 |             # don't have to go and sort it all out now. | 217 |             # don't have to go and sort it all out now. | 
        
          | 211 |             my $authtypecode = $record->{authtype}; | 218 |             my $authtypecode = $record->{authtype}; | 
        
          | 212 |             my $rs           = $schema->resultset('AuthType') | 219 |             my $rs           = $schema->resultset('AuthType') | 
          
            
              | 213 |               ->search( { authtypecode => $authtypecode } ); | 220 |             ->search( { authtypecode => $authtypecode } ); | 
        
          | 214 |  | 221 |  | 
        
          | 215 |             # FIXME there's an assumption here that we will get a result. | 222 |             # FIXME there's an assumption here that we will get a result. | 
        
          | 216 |             # the original code also makes an assumption that some provided | 223 |             # the original code also makes an assumption that some provided | 
  
    | Lines 219-225
          sub search_auth_compat {
      
      
        Link Here | 
        
          | 219 |             # it's not reproduced here yet. | 226 |             # it's not reproduced here yet. | 
        
          | 220 |             my $authtype           = $rs->single; | 227 |             my $authtype           = $rs->single; | 
        
          | 221 |             my $auth_tag_to_report = $authtype ? $authtype->auth_tag_to_report : ""; | 228 |             my $auth_tag_to_report = $authtype ? $authtype->auth_tag_to_report : ""; | 
          
            
              | 222 |             my $marc               = $self->decode_record_from_result(@_); | 229 |             my $marc               = $self->decode_record_from_result($record); | 
        
          | 223 |             my $mainentry          = $marc->field($auth_tag_to_report); | 230 |             my $mainentry          = $marc->field($auth_tag_to_report); | 
        
          | 224 |             my $reported_tag; | 231 |             my $reported_tag; | 
        
          | 225 |             if ($mainentry) { | 232 |             if ($mainentry) { | 
  
    | Lines 233-245
          sub search_auth_compat {
      
      
        Link Here | 
        
          | 233 |  | 240 |  | 
        
          | 234 |             # Reimplementing BuildSummary is out of scope because it'll be hard | 241 |             # Reimplementing BuildSummary is out of scope because it'll be hard | 
        
          | 235 |             $result{summary} = | 242 |             $result{summary} = | 
          
            
              | 236 |               C4::AuthoritiesMarc::BuildSummary( $marc, $result{authid}, | 243 |             C4::AuthoritiesMarc::BuildSummary( $marc, $result{authid}, | 
        
          | 237 |                 $authtypecode ); | 244 |                 $authtypecode ); | 
        
          | 238 |             $result{used} = $self->count_auth_use($bib_searcher, $authid); | 245 |             $result{used} = $self->count_auth_use($bib_searcher, $authid); | 
            
              | 239 |             push @records, \%result; |  |  | 
        
          | 240 |         } | 246 |         } | 
          
            
              | 241 |     ); | 247 |         push @records, \%result; | 
            
              | 242 |     return ( \@records, $res->total ); | 248 |     } | 
            
              |  |  | 249 |     return ( \@records, $hits->{'total'} ); | 
        
          | 243 | } | 250 | } | 
        
          | 244 |  | 251 |  | 
        
          | 245 | =head2 count_auth_use | 252 | =head2 count_auth_use |