[Evergreen-dev] Struggling with title sorting

Jeff Davis jeff.davis at bc.libraries.coop
Fri Feb 3 13:37:13 EST 2023


Hi Ken,

I'm not very familiar with title sorting. That said, it looks to me like the code in misc_util.tt2 is only used for sorting the user's circs, holds, and circ history in My Account. Search results appear to be sorted as part of the actual search query - that is, selecting "Title: A to Z" as your sort option adds a "sort(titlesort)" parameter to your search query and then re-runs the search. The easiest option would probably be to let the underlying Evergreen search sort the results for you in this way.

I believe the titlesort parameter ends up sorting on the value in the metabib.record_sorter table for each record in your results. I'm not sure exactly how metabib.record_sorter values are generated when records are ingested (there's some deep magic involving record attributes); at a minimum, it looks like it takes MARC non-filing characters into account and also strips punctuation.

It seems to me that there are a few cataloguing errors in your examples. There should be no space after the apostrophe in "L'événement" and the non-filing indicator should be "2". For the Sue Grafton books, I think the non-filing indicator should be "1" since the initial character (") is non-filing. But you should definitely verify that stuff with an actual cataloguer. 🙂

Hopefully some of the above is useful and at least vaguely accurate!

Jeff
________________________________
From: Evergreen-dev <evergreen-dev-bounces at list.evergreen-ils.org> on behalf of Ken Cox via Evergreen-dev <evergreen-dev at list.evergreen-ils.org>
Sent: Saturday, January 28, 2023 7:07 PM
To: evergreen-dev at list.evergreen-ils.org <evergreen-dev at list.evergreen-ils.org>
Subject: [Evergreen-dev] Struggling with title sorting

I am struggling to sort lists by title in the mobile app.  Can somebody point me to the code where it happens, or explain how it's supposed to happen?

I found code in misc_utils.tt2<https://git.evergreen-ils.org/?p=Evergreen.git;a=blob;f=Open-ILS/src/templates/opac/parts/misc_util.tt2;h=283bcb098c37f58337cffc5ec4a60c7403e154cd;hb=HEAD#l275>, and read up on MARC 245 ind2 non-filing characters, hooray!  I implemented the logic and it doesn't match the OPAC, boo!

Is this the right code in misc_utils.tt2<https://git.evergreen-ils.org/?p=Evergreen.git;a=blob;f=Open-ILS/src/templates/opac/parts/misc_util.tt2;h=283bcb098c37f58337cffc5ec4a60c7403e154cd;hb=HEAD#l275> ?

 275         # If the title has a "non-filing chaaracters"
 276         # (to logically remove leading "The " for example)
 277         # chop the title. Otherwise, chop until the first alphanumeric.
 278         # BTW: Template Toolkit folds 1-element arrays to scalars!
 279         title_node = xml.findnodes('//*[@tag="245"]');
 280
 281         args.nonfiling_characters = title_node.findvalue('@ind2');
 282
 283         IF (args.nonfiling_characters > 0);
 284              args.sort_title = args.sort_title.substr(args.nonfiling_characters);
 285         ELSE;
 286              args.sort_title = args.sort_title.replace('^[^A-Z0-9]*','');
 287         END;

small example

My public list<https://catalog.cwmars.org/eg/opac/results?query=&qtype=keyword&fi%3Asearch_format=&locg=1&detail_record_view=0&bookbag=1952592&sort=titlesort&depth=0> in the OPAC sorted by Title looks like this:

  1.  "E" is for evidence
  2.  L'événement = Happening
  3.  "G" is for gumshoe

That looks right.  Logging from the app show why this sort is wrong:

item 4692942 has 2 non-filing chars: "L' événement = : Happening" -> " ÉVÉNEMENT = : HAPPENING"
item 3152814 has 0 non-filing chars: ""E" is for evidence" -> "E" IS FOR EVIDENCE"
item 3176781 has 0 non-filing chars: ""G" is for gumshoe" -> "G" IS FOR GUMSHOE"

The first item has a space after L' in the mvr record<https://catalog.cwmars.org/osrf-gateway-v1?service=open-ils.search&method=open-ils.search.biblio.record.mods_slim.retrieve&param=4692942&_ck=114&_sk=3-7-3>, and so skipping 2 chars sorts on the space.  Maybe this is an encoding issue in the OSRF gateway?

Thanks for listening!
--
Ken
This message originated from outside the M365 organisation. Please be careful with links, and don't trust messages you don't recognise.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.evergreen-ils.org/pipermail/evergreen-dev/attachments/20230203/d6a0e9d3/attachment.htm>


More information about the Evergreen-dev mailing list