[OPEN-ILS-DEV] Parts sorting by month name

Josh Stompro stomproj at exchange.larl.org
Thu Feb 4 14:45:11 EST 2016


As I've been cleaning up the part labels I've noticed that there is a generated sorting field in the biblio.monograph_parts table, and I'm wondering how hard it would be to sort them by month based on the month name.

If I modified the trigger biblio.normalize_biblio_monograph_part_sortkey to add a prefix to the sortkey of the month index, would that do it?

JAN = 01jan
FEB = 02feb
MAR = 03mar

Would anyone else find this useful?  Or is this abusing parts too much from its intended use, since we are using it instead of serials for magazines?  Maybe this is also to English centric?

Something like this maybe?  I would probably include the full month names in this also.

CREATE OR REPLACE FUNCTION biblio.normalize_biblio_monograph_part_sortkey () RETURNS TRIGGER AS $$
BEGIN
    NEW.label_sortkey := REGEXP_REPLACE(
        evergreen.lpad_number_substrings(
            naco_normalize(NEW.label),
            '0',
            10
        ),
        E'\\s+',
        '',
        'g'
    );
    -- Sort by month name abreviation
    IF new.label ~* '^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\M' THEN
        CASE
         WHEN new.label ~* '^JAN' THEN
          new.label_sortkey =: '01'||new.label_sortkey;
         WHEN new.label ~* '^FEB' THEN
          new.label_sortkey =: '02'||new.label_sortkey;
         WHEN new.label ~* '^MAR' THEN
          new.label_sortkey =: '03'||new.label_sortkey;
        END CASE;
    END IF;
    RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;

CREATE TRIGGER norm_sort_label BEFORE INSERT OR UPDATE ON biblio.monograph_part FOR EACH ROW EXECUTE PROCEDURE biblio.normalize_biblio_monograph_part_sortkey();


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libmail.georgialibraries.org/pipermail/open-ils-dev/attachments/20160204/66f0035b/attachment.html>


More information about the Open-ils-dev mailing list