Bugzilla – Attachment 148446 Details for
Bug 25870
Add a q_ccl query parameter to /biblios
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25870: (follow-up) Adding pagination information on the headers, returns an empty result when the query is empty
Bug-25870-follow-up-Adding-pagination-information-.patch (text/plain), 4.79 KB, created by
Hammat wele
on 2023-03-21 13:00:26 UTC
(
hide
)
Description:
Bug 25870: (follow-up) Adding pagination information on the headers, returns an empty result when the query is empty
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2023-03-21 13:00:26 UTC
Size:
4.79 KB
patch
obsolete
>From c67be1e64b7a6e40a92bbdab7129b855c434412f Mon Sep 17 00:00:00 2001 >From: Hammat Wele <hammat.wele@inlibro.com> >Date: Tue, 21 Mar 2023 12:55:52 +0000 >Subject: [PATCH] Bug 25870: (follow-up) Adding pagination information on the > headers, returns an empty result when the query is empty > >--- > Koha/REST/V1/Biblios.pm | 65 +++++++++++++++++++++++-------- > api/v1/swagger/paths/biblios.yaml | 3 ++ > 2 files changed, 51 insertions(+), 17 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index bff93b279e..3c170e2e82 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -161,37 +161,68 @@ sub get_biblios_public { > > my ( $error, $results, $total_hits ) = $searcher->simple_search_compat( $query, 0, undef ); > >- if ( !$total_hits ) { >- return $c->render( >- status => 404, >- openapi => { error => 'Nothing found.' } >- ); >- } >- > return try { > > my $patron = $c->stash('koha.user'); > my $is_public = $c->stash('is_public'); > my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); >- my $searchengine = C4::Context->preference('SearchEngine'); >- >- my @biblionumbers >- = $searchengine eq 'Zebra' >- ? map { MARC::Record->new_from_xml( $_, 'UTF-8' )->field('999')->subfield('c') } $results->@* >- : map { $_->field('999')->subfield('c') } $results->@*; >+ my @biblionumbers; >+ foreach my $res ( @$results ) { >+ my $bibno = $searcher->extract_biblionumber( $res ); >+ push @biblionumbers, $bibno if $bibno; >+ } > my @biblios = map { Koha::Biblios->find( { biblionumber => $_ } ) } @biblionumbers; >- my @records = map { >+ my @records; >+ foreach( @biblios ) { >+ next if ( $is_public >+ && !( $patron && $patron->category->override_hidden_items ) >+ && $_->hidden_in_opac( { rules => $opachiddenitems_rules } ) ); >+ push @records => $_->metadata->record; >+ } >+ >+ # Extract reserved params >+ my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params( $c->validation->output ); >+ $reserved_params->{_per_page} //= C4::Context->preference('RESTdefaultPageSize'); >+ $reserved_params->{_page} //= 1; >+ my $offset = $reserved_params->{_per_page} * ($reserved_params->{_page} - 1); >+ $offset = 0 if $offset < 0; >+ >+ my $total = scalar @records; >+ my @paged_records; >+ for ( my $i = $offset ; $i < ( $offset + $reserved_params->{_per_page} < $total ? $offset + $reserved_params->{_per_page} : $total ) ; $i++ ) { >+ push @paged_records, $records[$i]; >+ } >+ >+ #Calculate the total record by removing the record hidden in opac >+ my $biblios = Koha::Biblios->search(); >+ @biblionumbers = (); >+ while ( my $biblio = $biblios->next ) { >+ push @biblionumbers, $biblio->biblionumber if $biblio->biblionumber; >+ } >+ @biblios = map { Koha::Biblios->find( { biblionumber => $_ } ) } @biblionumbers; >+ my $base_total = 0; >+ foreach( @biblios ) { > next if ( $is_public > && !( $patron && $patron->category->override_hidden_items ) > && $_->hidden_in_opac( { rules => $opachiddenitems_rules } ) ); >- $_->metadata->record; >- } @biblios; >+ $base_total++; >+ } >+ >+ $c->add_pagination_headers( >+ { >+ base_total => $base_total, >+ page => $reserved_params->{_page}, >+ per_page => $reserved_params->{_per_page}, >+ query_params => $reserved_params->{_q_params}, >+ total => ( $reserved_params->{_page} ? $total : $reserved_params->{_per_page} ), >+ } >+ ); > > $c->respond_to( > mij => { > status => 200, > format => 'mij', >- data => '[' . ( join ',', map { $_->to_mij } @records ) . ']', >+ data => '[' . ( join ',', map { $_->to_mij } @paged_records ) . ']', > }, > any => { > status => 406, >diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml >index 0c3dc6e62a..3e048f2299 100644 >--- a/api/v1/swagger/paths/biblios.yaml >+++ b/api/v1/swagger/paths/biblios.yaml >@@ -463,6 +463,9 @@ > summary: Get biblios (public) > parameters: > - $ref: "../swagger.yaml#/parameters/q_ccl" >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/q_param" > produces: > - application/marc-in-json > responses: >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25870
:
138123
|
139452
|
139469
|
139491
|
148117
|
148247
| 148446