Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for correct sorting with other call numbers #30

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions test/tests/utilities_itemTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,58 @@ describe("Zotero.Utilities.Item", function () {
];
checkSort(numbersInOrder);
});

it("should correctly order RVK call numbers (Regensburger Verbundklassifikation)", function () {
let numbersInOrder = [
'NH 7000 T288-2,4,55',
'NH 7000 T288-2,32,5',
'NH 7000 T288-2,33,1',
'NH 7000 T288-2,33,2',
'NS 3293 W642-1',
'NS 3293 W642-1+1',
'NS 3293 W642-2',
'NS 3293 W828',
'NS 3293 W828(3)',
'NS 3293 W828(20)',
'PF 912',
'PF 912.307',
'PF 912.370'
];
checkSort(numbersInOrder);
});

it("should correctly order BK call numbers (Basisklassifikation)", function () {
let numbersInOrder = [
'24.99',
'31',
'31.01',
'31.02',
'31.10'
];
checkSort(numbersInOrder);
});

it("should correctly order call numbers containing a simple combination of a letter and an increasing number (numerus currens)", function () {
let numbersInOrder = [
'M 1',
'M 2',
'M 10',
'M 10a',
'M 11',
'M 100 b'
];
checkSort(numbersInOrder);

numbersInOrder = [
'M1',
'M2',
'M10',
'M10a',
'M11',
'M100b'
];
checkSort(numbersInOrder);
});
});

describe("#languageToISO6391()", function () {
Expand Down
4 changes: 2 additions & 2 deletions utilities_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ var Utilities_Item = {

let onlyNumbersRe = /^\d*$/;
let deweyRe = /^(\d{3})(?:\.(\d+))?(?:\/([a-zA-Z]{3}))?$/;
let lcWithClassificationRe = /^[a-zA-Z]{1,3}\d+($|(?=\s*[.\d]))/;
let lcWithClassificationRe = /^[a-zA-Z]{1,3}\d+($|(?=\s*(.|\s\d)))/;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the recognition and matching of patterns like "M100a", where before "M10" was recognized as the main class and the next "0" as the look-ahead here.


if (onlyNumbersRe.test(fieldA) && onlyNumbersRe.test(fieldB)) {
return parseInt(fieldA) - parseInt(fieldB);
Expand Down Expand Up @@ -1067,7 +1067,7 @@ var Utilities_Item = {
}
}

return (fieldA > fieldB) ? 1 : (fieldA < fieldB) ? -1 : 0;
return Zotero.localeCompare(fieldA, fieldB);
}
}

Expand Down
Loading