Bug 9747: Fix NSB/NSE sorting issues on z3950 search results
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 5 Mar 2013 12:52:20 +0000 (13:52 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 9 Oct 2013 04:21:03 +0000 (04:21 +0000)
At least the BNF server returns results containing non-sorting
characters (NSB/NSE).
In order to sort results according these characters, this patch adds a
new Datatable function.

Test plan:
- search 'tintin' on the z3950 search (cataloguing/z3950_search.pl)
- sort on title (default sort) and check that results are not well
  sorted.
- apply this patch
- do the same search and check that the first result is "HergĂ©. Les
  Aventures de Tintin..."
  The value of the cell is:
      <td>\88HergĂ©. Les \89Aventures de Tintin...</td>

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Works as advertised and doesn't break existing searching

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt

index d243392..cca389d 100644 (file)
@@ -471,6 +471,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
 } );
 
 }());
+
 /* Plugin to allow sorting on data stored in a span's title attribute
  *
  * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
@@ -495,7 +496,6 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
     }
 } );
 
-
 /* Plugin to allow sorting on numeric data stored in a span's title attribute
  *
  * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
@@ -566,3 +566,17 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
     });
 
 }());
+
+// Remove string between NSB NSB characters
+$.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
+    var pattern = new RegExp("\x88.*\x89");
+    a = a.replace(pattern, "");
+    b = b.replace(pattern, "");
+    return (a > b) ? 1 : ((a < b) ? -1 : 0);
+}
+$.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
+    var pattern = new RegExp("\x88.*\x89");
+    a = a.replace(pattern, "");
+    b = b.replace(pattern, "");
+    return (b > a) ? 1 : ((b < a) ? -1 : 0);
+}
index 7e5b0af..d8d370e 100644 (file)
@@ -33,6 +33,7 @@ $(document).ready(function(){
         "sDom": 't',
         "aoColumnDefs": [
             { "aTargets": [ -1,-2,-3 ], "bSortable": false, "bSearchable": false },
+            { "aTargets": [ 1 ], "sType": "nsb-nse" },
         ],
         "aaSorting": [[ 1, "asc" ]],
         "bPaginate": false