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

Add support for the 'sort' query string parameter in GET searches #44

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

bmquinn
Copy link
Contributor

@bmquinn bmquinn commented Nov 1, 2022

Steps to test:

  • Index some works
  • Perform a GET search with the sort query string parameter, e.g.
    https://[YOUR ENVIRONMENT]/search?sort=create_date:desc,accession_number:desc
  • Switch the sort direction to see the results change order
    Note: ElasticSearch only supports sorting keyword fields so you'll get errors if you try to sort a text field such as title

@bmquinn bmquinn requested a review from mbklein November 1, 2022 21:14
Copy link
Contributor

@mbklein mbklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes warrant updates to docs/spec/types.yaml and docs/spec/openapi.yaml to add the sort parameter to the Swagger docs. That could be a separate PR, but it's probably good to get into the habit of submitting doc/spec changes at the same time as route/parameter changes.

src/handlers/search-runner.js Outdated Show resolved Hide resolved
@bmquinn bmquinn temporarily deployed to test November 3, 2022 17:03 Inactive
Sort json in pipeline and event-builder, add docs for sort
@bmquinn bmquinn temporarily deployed to test November 3, 2022 17:04 Inactive
@mbklein
Copy link
Contributor

mbklein commented Nov 3, 2022

👍👍👍

$ curl "http://localhost:3000/collections?sort=modified_date:desc&size=2"

{
  "data": [
    {
      "admin_email": null,
      "api_link": "https://dcapi.rdc-staging.library.northwestern.edu/collections/bfeeb065-5b12-4b10-9883-f32b133c7cd1",
      "api_model": "Collection",
      "create_date": "2021-03-12T02:11:32.342977Z",
      "description": "These images were from the Slide Library which was once in the Visual Media Center under the Department of Art History at Northwestern University.",
      "featured": null,
      "finding_aid_url": null,
      "id": "bfeeb065-5b12-4b10-9883-f32b133c7cd1",
      "indexed_at": "2022-10-26T19:36:05.609672",
      "keywords": [],
      "modified_date": "2022-10-05T16:06:53.193250Z",
      "published": true,
      "representative_image": {
        "url": "https://iiif.dev.rdc.library.northwestern.edu/iiif/2/mbk-dev/fc265314-0006-42e6-bbb3-f4d74f57c21a",
        "work_id": "21991c2b-0e79-4705-9f66-a929d8919329"
      },
      "title": "Department of Art History || Slide Collection",
      "visibility": "Institution"
    },
    {
      "admin_email": null,
      "api_link": "https://dcapi.rdc-staging.library.northwestern.edu/collections/85af945f-1396-4b88-9087-c4f2fa64d21c",
      "api_model": "Collection",
      "create_date": "2021-03-12T02:11:32.427741Z",
      "description": "Rob Linrothe is an Associate Professor in the Department of Art History at Northwestern University. Here he shares his images of Tibetan, Chinese, and Indian monuments, field photography, and architecture. The collection has a strong focus on Tibetan sites, particularly petroglyphs, stupas, and monasteries in the Ladakh and Zangskar regions. Linrothe has also photographed the architecture and sculpture of monuments such as Borobudur in Indonesia and Sanchi in India. Rob Linrothe specializes in Buddhist art of the Himalayas. His recent fieldwork has focused on pre-modern mural painting in the Ladakh and Zangskar regions of Western Tibet (northwest India), as well as the contemporary revival of monastic painting in the Amdo province of Eastern Tibet (China).",
      "featured": null,
      "finding_aid_url": null,
      "id": "85af945f-1396-4b88-9087-c4f2fa64d21c",
      "indexed_at": "2022-10-26T19:36:05.607758",
      "keywords": [
        "photography"
      ],
      "modified_date": "2022-09-28T17:16:14.373640Z",
      "published": true,
      "representative_image": {
        "url": "https://iiif.dev.rdc.library.northwestern.edu/iiif/2/mbk-dev/4d899ca7-a0df-497a-b1e1-8f8749995993",
        "work_id": "b61d3148-79d1-4e3e-9aa2-625ef9a0e5c7"
      },
      "title": "Rob Linrothe Image Collection",
      "visibility": "Public"
    }
  ],
  "pagination": {
    "query_url": "http://localhost:3000/collections?sort=modified_date%3Adesc&size=2",
    "current_page": 1,
    "limit": "2",
    "offset": 0,
    "total_hits": 71,
    "total_pages": 36,
    "next_url": "http://localhost:3000/collections?sort=modified_date%3Adesc&size=2&page=2"
  },
  "info": {}
}
$ curl "http://localhost:3000/collections?sort=modified_date:asc&size=2"

{
  "data": [
    {
      "admin_email": null,
      "api_link": "https://dcapi.rdc-staging.library.northwestern.edu/collections/bc3a6195-e429-4378-958d-b88bce731d03",
      "api_model": "Collection",
      "create_date": "2021-03-12T02:11:32.290932Z",
      "description": "Items awaiting copyright review determinations.",
      "featured": null,
      "finding_aid_url": null,
      "id": "bc3a6195-e429-4378-958d-b88bce731d03",
      "indexed_at": "2022-10-26T19:36:05.582389",
      "keywords": [],
      "modified_date": "2021-03-17T20:18:35.644274Z",
      "published": true,
      "representative_image": {},
      "title": "BFMF Copyright Review",
      "visibility": "Private"
    },
    {
      "admin_email": null,
      "api_link": "https://dcapi.rdc-staging.library.northwestern.edu/collections/17a5d121-2bc2-4942-aa48-34ac86f3b83d",
      "api_model": "Collection",
      "create_date": "2021-03-12T02:11:32.319999Z",
      "description": "University Theatre Production Photographs consists of slides dating from 1953 to 1991, with the bulk of the slides dating from 1971 to 1991. Slides are grouped by production title and arranged chronologically by production date. The distinction has been maintained between slides received directly from Michael Ryzcek and from Jean Deven, so there are two chronological runs of slides.",
      "featured": null,
      "finding_aid_url": null,
      "id": "17a5d121-2bc2-4942-aa48-34ac86f3b83d",
      "indexed_at": "2022-10-26T19:36:05.582654",
      "keywords": [],
      "modified_date": "2021-03-17T20:18:35.644274Z",
      "published": true,
      "representative_image": {},
      "title": "University Theatre Production Photographs",
      "visibility": "Institution"
    }
  ],
  "pagination": {
    "query_url": "http://localhost:3000/collections?sort=modified_date%3Aasc&size=2",
    "current_page": 1,
    "limit": "2",
    "offset": 0,
    "total_hits": 71,
    "total_pages": 36,
    "next_url": "http://localhost:3000/collections?sort=modified_date%3Aasc&size=2&page=2"
  },
  "info": {}
}

@mbklein mbklein merged commit 86e8308 into deploy/staging Nov 3, 2022
@mbklein mbklein deleted the 3161-search-sort branch November 3, 2022 17:14
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.

2 participants