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

@next URLs in multi-category search results are broken #10

Open
Conal-Tuohy opened this issue Sep 15, 2023 · 1 comment
Open

@next URLs in multi-category search results are broken #10

Conal-Tuohy opened this issue Sep 15, 2023 · 1 comment
Assignees
Labels
bug Something isn't working Trove API relating to the underlying Trove API

Comments

@Conal-Tuohy
Copy link
Owner

At the moment I've written code in TroveProxy to fix these broken URLs, and it seems to me that the Trove API actually could incorporate this same fix, so I'd like to be able to move this fix "upstream" to Trove, so that other people who aren't using TroveProxy don't experience these broken links.

The XML response includes <records> elements with next attributes whose values are URLs which include a single category parameter whose value is a list of category names, separated by a (URL-encoded) comma. If I replace that category parameter with one whose value is taken from the code attribute of the parent (i.e. <category>) element of the <records> element, then the resulting URL does work.

e.g. take the following query URL:
https://api.trove.nla.gov.au/v3/result?category=book&category=newspaper&q=water%20dragon&s=*&n=1&bulkHarvest=true

The result looks like this:

<response>
  <query>water dragon</query>
  <category code="book" name="Books &amp; Libraries">
    <records s="*" n="1" total="3700" next="https://api.trove.nla.gov.au/v3/result?category=book%2Cnewspaper&amp;q=water+dragon&amp;n=1&amp;bulkHarvest=true&amp;s=AoEqc3UxMDAwMTE4Ng%3D%3D" nextStart="AoEqc3UxMDAwMTE4Ng==">
      <!-- omitted for brevity -->
    </records>
  </category>
  <category code="newspaper" name="Newspapers &amp; Gazettes">
    <records s="*" n="1" total="98345" next="https://api.trove.nla.gov.au/v3/result?category=book%2Cnewspaper&amp;q=water+dragon&amp;n=1&amp;bulkHarvest=true&amp;s=AoEpMTAwMDI0NDE5" nextStart="AoEpMTAwMDI0NDE5">
      <!-- omitted for brevity -->
    </records>
  </category>
</response>

Those "next" URLs are broken, but if I change them like so, they do appear to work correctly:

<response>
  <query>water dragon</query>
  <category code="book" name="Books &amp; Libraries">
    <records s="*" n="1" total="3700" next="https://api.trove.nla.gov.au/v3/result?category=book&amp;q=water+dragon&amp;n=1&amp;bulkHarvest=true&amp;s=AoEqc3UxMDAwMTE4Ng%3D%3D" nextStart="AoEqc3UxMDAwMTE4Ng==">
      <!-- omitted for brevity -->
    </records>
  </category>
  <category code="newspaper" name="Newspapers &amp; Gazettes">
    <records s="*" n="1" total="98345" next="https://api.trove.nla.gov.au/v3/result?category=newspaper&amp;q=water+dragon&amp;n=1&amp;bulkHarvest=true&amp;s=AoEpMTAwMDI0NDE5" nextStart="AoEpMTAwMDI0NDE5">
      <!-- omitted for brevity -->
    </records>
  </category>
</response>

The code I'm using to fix these broken URLs is here:

<xsl:variable name="category-code" select="ancestor::category/@code"/>

<xsl:variable name="parameters" select="$query => tokenize('&amp;')"/>
<!-- throw out any category parameters that don't match current category -->
<xsl:variable name="refined-parameters" select="
(
$parameters[substring-before(., '=') != 'category'], (: ditch any categories :)
concat('category=', $category-code) (: add the current category back :)
)
"/>
<xsl:attribute name="next" select="
concat($base-uri, '?', string-join($refined-parameters, '&amp;'))
"/>

@Conal-Tuohy
Copy link
Owner Author

Followed up on this with Trove Support this morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Trove API relating to the underlying Trove API
Development

No branches or pull requests

1 participant