Search stories by tags
Use the search field on me to list the stories that carry a tag, limited to what the user is allowed to see.
The search entry point is search on me. It only searches what the user is allowed to see, so two users can get different results for the same query.
This example lists the stories that carry a tag. You need the GraphQL ID of the tag: Change the tags of a story shows how to find it.
query storiesWithATag {
me {
search(query: { tags: ["TAG_ID"] }) {
totalCount
stories {
story {
id
slug
version {
title
}
}
}
}
}
}
The response:
{
"data": {
"me": {
"search": {
"totalCount": 3,
"stories": [
{ "story": { "id": "U3Rvcnk6MQ==", "slug": 1, "version": { "title": "First story" } } },
{ "story": { "id": "U3Rvcnk6Mg==", "slug": 2, "version": { "title": "Second story" } } },
{ "story": { "id": "U3Rvcnk6Mw==", "slug": 3, "version": { "title": "Third story" } } }
]
}
}
}
}
query takes the same filters as the search page: text for the search words, spaces, hashtags, schemas (templates), users, langs, a dateRange, and sort (RELEVANCE by default, or NEWEST, UPDATED, ALPHABETICAL and others). limit and start paginate the results, 20 at a time by default.
Each result also carries highlightedTitle and highlightedSnippets, the matching passages with the search words marked. This is what the search page shows.