Bugzilla – Attachment 117290 Details for
Bug 23887
Add support for client-specified sort order in Z3950Responder
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23887: Add support for sorting in Z3950Responder.
Bug-23887-Add-support-for-sorting-in-Z3950Responde.patch (text/plain), 3.12 KB, created by
Ere Maijala
on 2021-02-25 07:49:53 UTC
(
hide
)
Description:
Bug 23887: Add support for sorting in Z3950Responder.
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2021-02-25 07:49:53 UTC
Size:
3.12 KB
patch
obsolete
>From 2f20b99075adc8d0c3d7de34a0f792feddfd2cff Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Thu, 24 Oct 2019 13:33:15 +0300 >Subject: [PATCH] Bug 23887: Add support for sorting in Z3950Responder. > >Also enables sorting by any field that supports sorting and no longer ignores invalid or unsupported sorts. >--- > .../Elasticsearch/QueryBuilder.pm | 4 +-- > Koha/Z3950Responder/GenericSession.pm | 30 +++++++++++++++++-- > 2 files changed, 30 insertions(+), 4 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index d551ad93c1..55e8bd4975 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -696,7 +696,7 @@ sub _convert_sort_fields { > author => 'author', > call_number => 'local-classification', > popularity => 'issues', >- relevance => undef, # default >+ relevance => '', # default > title => 'title', > pubdate => 'date-of-publication', > ); >@@ -707,7 +707,7 @@ sub _convert_sort_fields { > grep { $_->{field} } map { > my ( $f, $d ) = /(.+)_(.+)/; > { >- field => $sort_field_convert{$f}, >+ field => $sort_field_convert{$f} // $f, > direction => $sort_order_convert{$d} > } > } @sort_by; >diff --git a/Koha/Z3950Responder/GenericSession.pm b/Koha/Z3950Responder/GenericSession.pm >index 103c627c53..cd816f4d93 100644 >--- a/Koha/Z3950Responder/GenericSession.pm >+++ b/Koha/Z3950Responder/GenericSession.pm >@@ -1,6 +1,6 @@ > package Koha::Z3950Responder::GenericSession; > >-# Copyright The National Library of Finland 2018 >+# Copyright The National Library of Finland 2018-2019 > # > # This file is part of Koha. > # >@@ -61,7 +61,9 @@ sub start_search { > my $query = $args->{RPN}->{'query'}->to_koha($self->{'attribute_mappings'}->{$database}); > $self->log_debug(" parsed search: $query"); > my @operands = $query; >- (undef, $built_query) = $builder->build_query_compat( undef, \@operands, undef, undef, undef, 0); >+ my $sort = $self->_convert_sort_rules($args->{SRW_SORTKEYS} // ''); >+ >+ (undef, $built_query) = $builder->build_query_compat( undef, \@operands, undef, undef, $sort, 0); > > my ($error, $marcresults, $hits ) = $searcher->simple_search_compat($built_query, 0, $num_to_prefetch); > if (defined $error) { >@@ -108,4 +110,28 @@ sub fetch_record { > return $resultset->{cached_results}[$offset - $resultset->{cached_offset}]; > } > >+=head2 Internal methods >+ >+=head3 _convert_sort_rules >+ >+ my $sort = $self->_convert_sort_rules($srw_sortkeys); >+ >+Convert SRW_SORTKEYS from SimpleServer to Koha's format >+ >+=cut >+ >+sub _convert_sort_rules { >+ my ( $self, $srw_sortkeys ) = @_; >+ >+ my @result; >+ my @sortkeys = split(' ', $srw_sortkeys); >+ foreach my $sortkey (@sortkeys) { >+ my @parts = split(',', $sortkey); >+ my $field = $parts[0]; >+ my $direction = $parts[2] // 1 == 1 ? 'asc' : 'desc'; >+ push @result, $field . '_' . $direction; >+ } >+ return \ >+} >+ > 1; >-- >2.25.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 23887
:
94655
|
117290
|
117967