Skip to content

Commit

Permalink
Add support for the 'sort' query string parameter in GET searches
Browse files Browse the repository at this point in the history
Sort json in pipeline and event-builder, add docs for sort
  • Loading branch information
bmquinn committed Nov 3, 2022
1 parent a41ab21 commit 03e4b4f
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 62 deletions.
69 changes: 37 additions & 32 deletions docs/docs/spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ info:
name: NUL Repository Team
email: [email protected]
servers:
- url: https://dcapi.rdc.library.northwestern.edu/api/v2
- url: https://dcapi.rdc.library.northwestern.edu/api/v2
tags:
- name: Models
description: >
Expand All @@ -24,34 +24,35 @@ paths:
get:
operationId: getCollections
tags:
- Collection
- Collection
parameters:
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/sort"
responses:
200:
$ref: "./types.yaml#/components/responses/SearchResponse"
/collections/{id}:
get:
tags:
- Collection
- Collection
operationId: getCollectionById
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/as"
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/as"
responses:
200:
$ref: "./types.yaml#/components/responses/DocumentResponse"
/collections/{id}/thumbnail:
get:
operationId: getCollectionThumbnail
tags:
- Collection
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/thumbnailAspect"
- $ref: "./types.yaml#/components/parameters/thumbnailSize"
- Collection
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/thumbnailAspect"
- $ref: "./types.yaml#/components/parameters/thumbnailSize"
responses:
200:
description: A thumbnail image for the given collection
Expand All @@ -64,44 +65,45 @@ paths:
get:
operationId: getFileSetById
tags:
- FileSet
- FileSet
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/id"
responses:
200:
$ref: "./types.yaml#/components/responses/DocumentResponse"
/works/{id}:
get:
operationId: getWorkById
tags:
- Work
- Work
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/id"
responses:
200:
$ref: "./types.yaml#/components/responses/DocumentResponse"
/works/{id}/similar:
get:
operationId: getSimilarWorks
tags:
- Work
- Work
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/as"
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/sort"
- $ref: "./types.yaml#/components/parameters/as"
responses:
200:
$ref: "./types.yaml#/components/responses/SearchResponse"
/works/{id}/thumbnail:
get:
operationId: getWorkThumbnail
tags:
- Work
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/thumbnailAspect"
- $ref: "./types.yaml#/components/parameters/thumbnailSize"
- Work
parameters:
- $ref: "./types.yaml#/components/parameters/id"
- $ref: "./types.yaml#/components/parameters/thumbnailAspect"
- $ref: "./types.yaml#/components/parameters/thumbnailSize"
responses:
200:
description: A thumbnail image for the given work
Expand All @@ -114,52 +116,55 @@ paths:
get:
operationId: getSearch
tags:
- Search
- Search
parameters:
- $ref: "./types.yaml#/components/parameters/query"
- $ref: "./types.yaml#/components/parameters/searchToken"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/sort"
- $ref: "./types.yaml#/components/parameters/as"
responses:
200:
$ref: "./types.yaml#/components/responses/SearchResponse"
post:
operationId: postSearch
tags:
- Search
- Search
requestBody:
content:
application/json:
schema:
type: object

responses:
200:
$ref: "./types.yaml#/components/responses/SearchResponse"
/search/{models}:
get:
operationId: getSearchWithModels
tags:
- Search
- Search
parameters:
- $ref: "./types.yaml#/components/parameters/models"
- $ref: "./types.yaml#/components/parameters/query"
- $ref: "./types.yaml#/components/parameters/searchToken"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/sort"
- $ref: "./types.yaml#/components/parameters/as"
responses:
200:
$ref: "./types.yaml#/components/responses/SearchResponse"
post:
operationId: postSearchWithModels
tags:
- Search
- Search
parameters:
- $ref: "./types.yaml#/components/parameters/models"
- $ref: "./types.yaml#/components/parameters/page"
- $ref: "./types.yaml#/components/parameters/size"
- $ref: "./types.yaml#/components/parameters/sort"
- $ref: "./types.yaml#/components/parameters/as"
responses:
200:
Expand Down
15 changes: 11 additions & 4 deletions docs/docs/spec/types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ components:
schema:
type: integer
minimum: 0
sort:
name: sort
in: query
required: false
description: Comma-delimited list of fields to sort search results (e.g. "create_date:asc,modified_date:desc")
schema:
type: string
as:
name: as
in: query
Expand All @@ -70,10 +77,10 @@ components:
description: Desired aspect ratio
schema:
type: string
enum:
enum:
- full
- square
thumbnailSize:
thumbnailSize:
name: size
in: query
required: false
Expand All @@ -100,8 +107,8 @@ components:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/OpenSearchResponse"
- $ref: "#/components/schemas/IiifPresentationManifest"
- $ref: "#/components/schemas/OpenSearchResponse"
- $ref: "#/components/schemas/IiifPresentationManifest"
schemas:
IiifPresentationManifest:
type: object
Expand Down
68 changes: 66 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/api/request/pipeline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { isFromReadingRoom } = require("../../helpers");
const sortJson = require("sort-json");

function filterFor(query, event) {
const matchTheQuery = query;
Expand Down Expand Up @@ -32,6 +33,6 @@ module.exports = class RequestPipeline {
}

toJson() {
return JSON.stringify(this.searchContext);
return JSON.stringify(sortJson(this.searchContext));
}
};
Loading

0 comments on commit 03e4b4f

Please sign in to comment.