The search() query provides a way to search and browse the content of a portal. It returns a list of learning objects and their metadata as well as available filtering and sorting options. It would support the display of a page looking like this:
Here is an example request:
query { search( filters: { keyword: "some search" } sort: { field: RELEVANT, direction: DESC } context: { appId: "partnerABC", language: "en", region: GLOBAL } ) { blocks { ... on SearchFilterBlock { filters(types:[TAG, DURATION, PROVIDER, PRICE, LANGUAGE]) { ... on ListFilter { type label options { label value count } } } } ... on SortBlock { options { label field direction } } ... on SearchResult { response(first: 20) { pageInfo { startCursor endCursor hasNextPage totalCount hasPreviousPage } edges { node { ... on CourseSlat { id title description rating tags duration image createdAt updatedAt } } } } } } } }
Let's examine the query in more detail. Firstly, the search query expects three arguments:
After we have defined what we are searching for, the next step is to define, what we want the server to return. In our example case, we have specified:
{ "data": { "search": { "blocks": [ { "filters": [ { "type": "DURATION", "label": "Duration", "options": [ { "label": "< 15 min", "value": "1.0-15.0", "count": 4 }, { "label": "15 – 30 min", "value": "15.0-30.0", "count": 0 }, { "label": "30 – 60 min", "value": "30.0-60.0", "count": 1 }, { "label": "> 60 min", "value": "60.0-*", "count": 4 } ] }, { "type": "PROVIDER", "label": "Providers", "options": [ { "label": "Provider A", "value": "520356", "count": 5 }, ... ] }, { "type": "PRICE", "label": "Price", "options": [ { "label": "Free", "value": "Free", "count": 0 }, { "label": "Paid", "value": "Paid", "count": 0 } ] } ] }, { "options": [ { "label": "Most relevant", "field": "RELEVANT", "direction": "DESC" }, { "label": "Popular", "field": "POPULAR", "direction": "DESC" }, { "label": "Latest", "field": "CREATED", "direction": "DESC" }, { "label": "Alphabetical", "field": "TITLE", "direction": "ASC" } ] }, { "response": { "pageInfo": { "startCursor": "BL_0_2", "endCursor": "EI_20", "hasNextPage": true, "totalCount": 21, "hasPreviousPage": false }, "edges": [ { "node": { "id": "513941", "title": "Test Course Assign", "description": "<p>This is to test assignment of Portal admin</p>", "rating": 0.5, "tags": null, "duration": 0, "image": "", "createdAt": "2018-08-06T09:20:37Z", "updatedAt": "2018-08-07T07:14:58Z" } ... } ] } } ] } } }
Further documentation and the GraphQL API Schema/Reference can be found here.