From 4e244fbe05939681dc05052175192ed0d72e689a Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Tue, 26 Sep 2017 13:43:05 -0400 Subject: [PATCH] Bug 19368 - Ignore words when sorting serial search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds the 'SerialSortIgnoreWords' system preference. It is empty by default, since words to ignore are very much language-specific. The functionality is achieved by adding a hidden column to the table, and sorting by this column by default. The downfall of this solution is that if the user sorts by another column, they cannot go back to this sorting without refreshing the page. To test: 0) Apply patch 1) Run updatedatabase.pl 2) Add test subscriptions if you have none. Make sure to have subscriptions starting with "The An A" or similar 3) Go to system preferences and edit the SerialSortIgnoreWords pref Add the words "The An A" or the ones you used in your subscriptions 4) Go to Serials 5) Search serials (empty field will return all serials) 6) Result table should be sorted ignoring leading "The An A..." Followed test plan, patch works as described Signed-off-by: Alex Buckley Signed-off-by: Séverine QUEUNE --- .../BugUndef-SerialSortIgnoreWords.sql | 1 + installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/serials.pref | 5 + .../prog/en/modules/serials/serials-search.tt | 117 +++++++++++++++++- serials/serials-search.pl | 36 ++++-- 5 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/BugUndef-SerialSortIgnoreWords.sql diff --git a/installer/data/mysql/atomicupdate/BugUndef-SerialSortIgnoreWords.sql b/installer/data/mysql/atomicupdate/BugUndef-SerialSortIgnoreWords.sql new file mode 100644 index 0000000000..5bcdfda506 --- /dev/null +++ b/installer/data/mysql/atomicupdate/BugUndef-SerialSortIgnoreWords.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('SerialSortIgnoreWords','',NULL,'Words to ignore in serial search','Free'); \ No newline at end of file diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ee2954d02f..0cf8e29e72 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -604,6 +604,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'), ('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'), ('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'), +('SerialSortIgnoreWords','des du de la le les leur d l an a the',NULL,'Words to ignore in serial search','Free'), ('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'), ('SessionStorage','mysql','mysql|Pg|tmp','Use database or a temporary file for storing session data','Choice'), ('ShelfBrowserUsesCcode','1','0','Use the item collection code when finding items for the shelf browser.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref index f6e818827c..a524ccf1a2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref @@ -62,3 +62,8 @@ Serials: 1: Do 0: Don't - prefill the notes from the last 'Arrived' serial when generating the next 'Expected' issue. + - + - 'Ignore the following words when sorting the serial search result table (separate words with spaces) :' + - pref: SerialSortIgnoreWords + class: free + - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index 587d8fa13a..3254f38520 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -307,7 +307,120 @@ [% ELSE %]
[% IF openedsubscriptions %] - [% INCLUDE subscriptions_table subscriptions = openedsubscriptions %] + + + + + + + + + + + + [% FOR field IN additional_fields_for_subscription %] + + [% END %] + + + + + + + + + + + + + [% FOR field IN additional_fields_for_subscription %] + + [% END %] + + + + + [% FOREACH subscription IN openedsubscriptions %] + [% UNLESS subscription.cannotdisplay %] + + + + + + + + + + + [% FOR field IN additional_fields_for_subscription %] + [% IF field.authorised_value_category %] + + [% ELSE %] + + [% END %] + [% END %] + + + + + [% END %] + [% END %] + +
SortISSNTitleNotesLibraryLocationCall numberExpiration date[% field.name %]Actions
[% IF ( subscription.titlesort ) %][% subscription.titlesort %][% END %] + [% IF ( subscription.issn ) %][% subscription.issn %] + [% END %] + [% subscription.title |html %] + [% IF ( subscription.publicnotes ) %][% subscription.publicnotes %][% END %] + [% IF ( subscription.internalnotes ) %]([% subscription.internalnotes %])[% END %] + + [% IF ( subscription.branchcode ) %][% Branches.GetName( subscription.branchcode ) %][% END %] + + [% IF ( subscription.location ) %][% AuthorisedValues.GetByCode( 'LOC', subscription.location ) %][% END %] + + [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %] + + [% IF ( subscription.enddate ) %] + [% subscription.enddate | $KohaDates %] + [% ELSE %] + + [% END %] + [% AuthorisedValues.GetByCode( field.authorised_value_category, subscription.additional_fields.${field.name} ) %][% subscription.additional_fields.${field.name} %] + +
[% ELSE %]

Your search returned no open subscriptions.

@@ -462,6 +575,8 @@ "sPaginationType": "full", "order": [[ 2, "asc" ]], "aoColumnDefs": [ + { 'visible' : false, "targets" : 0}, + { "iDataSort" : 0, 'aTargets' : [ 2 ] }, { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } ] diff --git a/serials/serials-search.pl b/serials/serials-search.pl index 56a16e6543..15f9f8450b 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -35,8 +35,9 @@ use C4::Context; use C4::Output qw( output_html_with_http_headers ); use C4::Serials qw( CloseSubscription ReopenSubscription SearchSubscriptions check_routing ); use Koha::AdditionalFields; - use Koha::DateUtils qw( dt_from_string ); +use Encode; +use Unicode::Normalize; use Koha::SharedContent; my $query = CGI->new; @@ -152,16 +153,33 @@ else } } - my (@openedsubscriptions, @closedsubscriptions); - for my $sub ( @subscriptions ) { - unless ( $sub->{closed} ) { - push @openedsubscriptions, $sub - unless $sub->{cannotdisplay}; - } else { - push @closedsubscriptions, $sub - unless $sub->{cannotdisplay}; +#sort stopword by string length +my @sortedstopword = sort{ length $b <=> length $a } split ( / / ,C4::Context->preference("SerialSortIgnoreWords")); +my $subsctitle; +my (@openedsubscriptions, @closedsubscriptions); +for my $sub ( @subscriptions ) { + $subsctitle = $sub->{title} ? ucfirst($sub->{title}): '' ; + if ($subsctitle){ + $subsctitle = NFKD($subsctitle); + $subsctitle =~ s/\p{NonspacingMark}//g; + foreach my $stop (@sortedstopword){ + my $ucfirststop = ucfirst($stop); + $subsctitle =~ s/$ucfirststop'//; + $subsctitle =~ s/$ucfirststop //; } } + $subsctitle =~ s/^\s+//; + $sub->{titlesort} = ucfirst($subsctitle); + + warn $subsctitle; + + unless ( $sub->{closed} ) { + push @openedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } else { + push @closedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } ); my @branches_loop; -- 2.25.1