Skip to content

Instantly share code, notes, and snippets.

@gmcharlt
Last active October 27, 2020 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmcharlt/055fff4543f52a3813defc2e1f925bfc to your computer and use it in GitHub Desktop.
Save gmcharlt/055fff4543f52a3813defc2e1f925bfc to your computer and use it in GitHub Desktop.
Using SRU to fetch LC NAF and SAF authority records modified on a given date

Here is a spell for retrieving MARCXML records from the Library of Congress's SRU server. It relies on the fact that IndexData-written SRU servers (such as Metaproxy) offer a convenient way to pass Z39.50 PQF query strings, so we're not stuck using just the predefined SRU search attributes.

Here's an example of retrieving all NAF records that were last updated on 2016-05-16:

http://lx2.loc.gov:210/NAF?operation=searchRetrieve&version=1.1&queryType=pqf&query=@attr 5=1 @attr 1=1012 2016-05-16&recordSchema=marcxml&maximumRecords=20

Here are some interesting bits from the URL:

  • NAF means we're drawing from the Name Authority File. Another interesting database is SAF (subject authorities).
  • searchRetrieve is the SRU verb to, well, search and retrieve
  • queryType=pqf means we want to go old-school, use numeric numeric Z39.50 attribues, and blithely ignore any possibility of human-readable labels, 'cause that's how we roll! (Actually, we're using PQF because the local.dateTimeLastModified SRU search attribute that's advertised doesn't seem to work.)
  • query=@attr 5=1 @attr 1=1012 2016-05-16 is the actual query. @attr 5=1 is a Bib-1 truncation attribute saying that we want to right-truncate our search; @attr 1=1012 is a Bib-1 use attribute for the record's last modification time, and 2016-05-16 is just a date.
  • recordSchema=marcxml ... because MARC will never die! At least, not just yet.
  • maximumRecords=20 ... 20 records at a time. We can add a startRecord parameter to page through results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment