Bug 8837

Summary: Dewey cn_sort inaccurate
Product: Koha Reporter: Joy Nelson <1joynelson>
Component: CatalogingAssignee: simith.doliveira
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P5 - low CC: eric.begin, francois.charbonnier, giuseppe.angilella, m.de.rooy, paola.rossi, philippe.blouin, simith.doliveira, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 12424    
Bug Blocks:    
Attachments: Bug 8837 - Dewey cn_sort inaccurate
Bug 8837 - Dewey cn_sort inaccurate
[PASSED QA] Bug 8837 - Dewey cn_sort inaccurate
[PASSED QA] Bug 8837 [QA Followup] - Add unit tests

Description Joy Nelson 2012-09-27 14:57:06 UTC
The items.cn_sort value created by the Dewey.pm does not create accurate sorting (cn_sort) values.

Example 1:  Three similar callnumbers do not sort the same way .  Suggested fix is to replace / with spaces.  (note: if any token[$i] consists of only one space when sort routine progresses it should be disregarded/removed)
+--------------------------+--------------------------------+
| itemcallnumber           | cn_sort                        |
+--------------------------+--------------------------------+
| 971/P23w/v.1-2/pt.8      | 971P23WV_000000000000000_12PT_ |
| 971.01/P23w/v.1-2/pt.6-7 | 971_000000000000000_01P23WV_12 |
| 971.01/P23w/v.1-2/pt.7   | 971_01P23WV_12PT_7000000000000 |
+--------------------------+--------------------------------+

That would improve the cn_sort values:
Manually replaced '/' with spaces in items.itemcallnumber to illustrate that process.
+--------------------------+--------------------------------+
| itemcallnumber           | cn_sort                        |
+--------------------------+--------------------------------+
| 971.01 P23w v.1-2 pt.6-7 | 971_010000000000000_P23W_V_12_ |
| 971.01 P23w v.1-2 pt.7   | 971_010000000000000_P23W_V_12_ |
| 971 P23w v.1-2 pt.8      | 971_P23W_V_12_PT_8000000000000 |
+--------------------------+--------------------------------+

However, the sort routine will adjust the second 'token' it finds that is all digit.  In the above case it is in the last callnumber (the 8) which is padded.  A better option would be to only adjust the only adjust the second 'token' if it is the second token.  Further if there are two token and the second token is not $token[2] then pad the first token with _zeros

An ideal result would be:
+--------------------------+--------------------------------+
| itemcallnumber           | cn_sort                        |
+--------------------------+--------------------------------+
| 971 P23w v.1-2 pt.8      | 971_000000000000000_P23W_V_12_ |
| 971.01 P23w v.1-2 pt.6-7 | 971_010000000000000_P23W_V_12_ |
| 971.01 P23w v.1-2 pt.7   | 971_010000000000000_P23W_V_12_ |
+--------------------------+--------------------------------+

note: 30 character limit does chop the rest of the cn_sort. Without an update to the database, this will be 'collateral damage'.
Comment 1 simith.doliveira 2014-08-06 13:15:13 UTC Comment hidden (obsolete)
Comment 2 Paola Rossi 2014-10-16 13:57:00 UTC Comment hidden (obsolete)
Comment 3 Kyle M Hall 2014-10-24 13:38:30 UTC
Created attachment 32665 [details] [review]
[PASSED QA] Bug 8837 - Dewey cn_sort inaccurate

This patch fix the cn_sort sorting accurace described by Joy Nelson.

Testing:

I) Appy the bug 12424 patch

Before applying this patch:
0) Select 3 items.
1) Edit the items selected
2) Change "Full call number" option to 971/P23w/v.1-2/pt.8, 971.01/P23w/v.1-2/pt.6-7 and 971.01/P23w/v.1-2/pt.7
3) Save changes
4) Valide 971P23WV_12PT_8_000000000000000, 971_000000000000000_01P23WV_12PT_67 and 971_01P23WV_12PT_700000000000000  (table items - cn_sort column).

After applying this patch:
5) Edit again the item selected in 0
3) Save changes
4) Valide 971_000000000000000_P23W_V_12_PT_8, 971_010000000000000_P23W_V_12_PT_67, 971_010000000000000_P23W_V_12_PT_7 (table items - cn_sort column).

Signed-off-by: Paola Rossi <paola.rossi@cineca.it>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 4 Kyle M Hall 2014-10-24 13:38:37 UTC
Created attachment 32666 [details] [review]
[PASSED QA] Bug 8837 [QA Followup] - Add unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 5 Tomás Cohen Arazi 2014-10-28 13:24:27 UTC
Patches pushed to master.

Thanks Simith and Kyle!