Skip to content

Add SRU 2.0 support (backwards compatible)#52

Open
Copilot wants to merge 3 commits intodevelopfrom
copilot/support-sru-2-0-backward-compatibility
Open

Add SRU 2.0 support (backwards compatible)#52
Copilot wants to merge 3 commits intodevelopfrom
copilot/support-sru-2-0-backward-compatibility

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 26, 2026

SRU 2.0 uses different XML namespaces than SRU 1.x for response, explain, and diagnostics elements. The library had no awareness of these namespaces, causing SRU 2.0 server responses to fail parsing entirely.

Changes

  • xmlparse.py: Register SRU 2.0 namespaces (sruResponse, sruExplain) in both namespaces and dict_namespaces, mapping them to the existing "sru" key so all downstream XPath queries work without modification.
  • response.py: Refactored _check_response_tag to detect SRU 2.0 root namespaces and hot-swap xmlparser.namespaces["sru"] accordingly, making version detection transparent to all response parsing logic.
  • client.py: Extended _check_errors to also probe the SRU 2.0 diagnostics namespace (http://docs.oasis-open.org/ns/search-ws/diagnostic). Added a sort_keys parameter to searchretrieve() that maps to the sortKeys URL parameter for SRU 1.x requests; the parameter is silently omitted for SRU 2.0, where sorting is done via the CQL sortby clause in the query.
  • __init__.py: Exposed sort_keys as a passthrough parameter in the module-level searchretrieve() function.
  • README.md: Updated to advertise SRU 1.1, 1.2, and 2.0 support.

Usage

# SRU 2.0 endpoint — just pass sru_version="2.0"
client = sruthi.Client("https://example.com/sru", sru_version="2.0")
results = client.searchretrieve("query")  # sruResponse namespace handled automatically

info = client.explain()  # sruExplain namespace handled automatically
print(info.sru_version)  # "2.0"

# SRU 1.x sorting via sortKeys parameter
results = client_1x.searchretrieve("query", sort_keys="title,,0")

# SRU 2.0 sorting via CQL sortby clause (sortKeys is ignored)
results = client_2x.searchretrieve("query sortby title/sort.ascending")

SRU 1.1 and 1.2 behavior is unchanged.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Implement SRU 2.0 with backward compatibility support Add SRU 2.0 support (backwards compatible) Feb 26, 2026
@metaodi metaodi marked this pull request as ready for review February 26, 2026 09:17
@metaodi metaodi linked an issue Feb 26, 2026 that may be closed by this pull request
@metaodi
Copy link
Copy Markdown
Owner

metaodi commented Feb 26, 2026

@copilot is everything listed here addressed in this PR? E.g. the new sortKeys parameter.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 26, 2026

@copilot is everything listed here addressed in this PR? E.g. the new sortKeys parameter.

The differences page wasn't reachable from this environment, but based on the SRU 2.0 specification the relevant differences for a client library are:

  • Namespaces (sruResponse, sruExplain, diagnostic) — handled ✅
  • sortKeys parametersortKeys is a SRU 1.x-only request parameter (in SRU 2.0, sorting is done via the CQL sortby clause in the query). I've added a sort_keys parameter to searchretrieve() that emits sortKeys for SRU 1.x and silently omits it for SRU 2.0 (commit e0cb958).
  • recordXMLEscaping vs recordPacking — renamed in SRU 2.0 responses, but since the parsing goes directly to recordData, this doesn't affect functionality ✅
  • operation parameter — optional in SRU 2.0 but still accepted by all known implementations; we keep sending it ✅
  • README — updated to advertise SRU 2.0 support ✅

If there's a specific item from that page I missed, happy to address it.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.loc.gov
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)
    • Triggering command: /usr/bin/curl curl -A Mozilla/5.0 -L REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for SRU 2.0

2 participants