Search Content
Skylark features a powerful Search API that obeys content availability, and allows you to fetch nested content and metadata in a single query.
It is possible to search across multiple object types in Skylark by using the search
query. It respects all availability rules and also supports pagination. You can also specify the object types to perform the search on.
Here's a sample request to search for brands, seasons and episodes containing dragon
for language en-GB
subject to availability.
query search {
search(query: "dragon", language: "en-GB") {
objects {
... on Brand {
slug
uid
title
__typename
}
... on Season {
slug
uid
title
title_short
__typename
}
... on Episode {
external_id
slug
uid
title
__typename
}
}
}
}
Advanced search queries
You can dial in your search query by using double quotes for an exact match or excluding specific words from your search using the minus symbol.
For example:
"homepage" -SkylarkImage
This will return exact matches to the phrase "homepage", that aren't the type of "SkylarkImage".
This returns a paginated response. A sample response is given below:
{
"data": {
"search": {
"objects": [
{
"slug": "hod-season-1",
"uid": "01GMTT7X6HTACXEQME2QX8ETPC",
"title": "House of the dragons - Season 1",
"title_short": null,
"__typename": "Season"
},
{
"slug": "house-of-the-dragons",
"uid": "01GMTT122X911K1ZZD45B9NGDC",
"title": "House of the dragons",
"__typename": "Brand"
}
]
}
}
}
Just like any other query, it is possible to specify the dimensions
, language
, and limit
and offset
for pagination while searching.
It is possible to see the view and configure the fields on which contents are searched. To see the fields which are configured for search, you can use getSearchableFields
query.
query MyQuery {
getSearchableFields
}
Sample response:
{
"data": {
"getSearchableFields": [
"title",
"synopsis"
]
}
}
Advanced search options
The search query has a set of arguments for customising the results. These arguments are:
limit_search_fields
This argument takes an array of strings and allows you to search on a subset of the search fields you have defined.
This argument does not allow for new search fields to be added at search fields, only to limit the fields that have already been defined.
Example:
query search {
search(query: "dragon", limit_search_fields: ["title"]) {
objects {
...on Movie {
title
synopsis
release_date
}
}
}
highlight_results
This argument, which takes a boolean value, will change the return values and wrap match search terms in a <span>
tag. This will allow you to add result highlighting to your search query.
The tag has the class skylark-search-result
applied.
Example:
query search {
search(query: "dragon", highlight_results: true) {
objects {
... on Brand {
title
synopsis
release_date
}
}
}
}
Example response:
{
"data": {
"search": {
"objects": [
{
"title": "House of the <span class=\"skylark-search-highlight\">Dragon</span>",
"synopsis": "The prequel series finds the Targaryen dynasty at the absolute apex of its power, with more than 15 <span class=\"skylark-search-highlight\">dragon</span>s under their yoke. Most empires – real and imagined – crumble from such heights.\n\nIn the case of the Targaryens, their slow fall begins almost 193 years before the events of Game of Thrones, when King Viserys Targaryen breaks with a century of tradition by naming his daughter Rhaenyra heir to the Iron Throne.\n\nBut when Viserys later fathers a son, the court is shocked when Rhaenyra retains her status as his heir, and seeds of division sow friction across the realm.",
"release_date": "2022-08-21"
}
]
}
}
}
By default, __typename
is a searchable attribute letting you narrow the types in your search by just including it in the query. For example game of thrones brand
will return Brand
types matching the query "game of thrones". However it is impossible to highlight the __typename
field as the response would no longer be valid GraphQL.
However the highlighted typename can be accessed via the special field _context.typename_highlight
.
Example:
query search {
search(query: "game of thrones brand", highlight_results: true, ignore_availability: true) {
objects {
... on Brand {
title
_context {
typename_highlight
}
}
}
}
}
Example response:
{
"data": {
"search": {
"objects": [
{
"title": "House <span class=\"skylark-search-highlight\">of</span> the Dragon",
"_context": {
"typename_highlight": "<span class=\"skylark-search-highlight\">Brand</span>"
}
}
]
}
}
}
typo_tolerance
By default, Skylark's search is typo tolerant. But it is possible to override that at search time to turn off typo tolerance entirely, or adjust the tolerance levels. This argument accepts 4 values:
Value | Description |
---|---|
ON (default) | Full typo tolerance is enabled |
OFF | Completely disable typo tolerance |
MINIMAL | Reduce the tolerance level and only return very close matches |
STRICT | A middle ground between ON and MINIMAL , returns more results than MINIMAL but with stricter tolerance levels than ON . |
Example:
query search {
search(query: "gsme of trones", typo_tolerance: STRICT) {
objects {
... on Brand {
title
}
}
}
}
types
The types
argument takes an array of strings and allows you to return on specific types if objects being retreieved have a type field.
Built in object types such as SkylarkImage
, SkylarkSet
and SkylarkAsset
all have a field called type
, and you are free to add a type
field to your custom objects using the self-configuration API.
When the types
argument is supplied to a search query, only objects with a matching type are returned.
This example shows searching for images with the query homepage
, where the type is THUMBNAIL
:
query search {
search(query: "homepage", types: ["THUMBNAIL"]) {
objects {
... on SkylarkImage {
title
}
}
}
}
Updated 6 months ago