diff --git a/src/main/scala/com/gu/contentapi/porter/graphql/RootQuery.scala b/src/main/scala/com/gu/contentapi/porter/graphql/RootQuery.scala index 84f3860..437e49e 100644 --- a/src/main/scala/com/gu/contentapi/porter/graphql/RootQuery.scala +++ b/src/main/scala/com/gu/contentapi/porter/graphql/RootQuery.scala @@ -1,6 +1,7 @@ package com.gu.contentapi.porter.graphql import com.gu.contentapi.porter.model.{Content, Tag} +import com.sksamuel.elastic4s.requests.searches.sort.SortOrder import sangria.schema._ import datastore.GQLQueryContext import deprecated.anotherschema.Edge @@ -24,14 +25,32 @@ object RootQuery { ) ) - val TagEdge: ObjectType[Unit, Edge[Tag]] = ObjectType( + val TagEdge: ObjectType[GQLQueryContext, Edge[Tag]] = ObjectType( "TagEdge", "A list of tags with pagination features", - () => fields[Unit, Edge[Tag]]( + () => fields[GQLQueryContext, Edge[Tag]]( Field("totalCount", LongType, Some("Total number of results that match your query"), resolve = _.value.totalCount), Field("endCursor", OptionType(StringType), Some("The last record cursor in the set"), resolve = _.value.endCursor), Field("hasNextPage", BooleanType, Some("Whether there are any more records to retrieve"), resolve = _.value.hasNextPage), - Field("nodes", ListType(com.gu.contentapi.porter.graphql.Tags.Tag), Some("The actual tags returned"), resolve = _.value.nodes) + Field("nodes", ListType(com.gu.contentapi.porter.graphql.Tags.Tag), Some("The actual tags returned"), resolve = _.value.nodes), + Field("matching_content", ArticleEdge, Some("Content which matches any of the tags returned"), + arguments= ContentQueryParameters.AllContentQueryParameters, + resolve = { ctx=> + ctx.ctx.repo.marshalledDocs(ctx arg ContentQueryParameters.QueryString, + queryFields=ctx arg ContentQueryParameters.QueryFields, + atomId = None, + forChannel = ctx arg ContentQueryParameters.ChannelArg, + userTier = ctx.ctx.userTier, + tagIds = Some(ctx.value.nodes.map(_.id)), + excludeTags = ctx arg ContentQueryParameters.ExcludeTagArg, + sectionIds = ctx arg ContentQueryParameters.SectionArg, + excludeSections = ctx arg ContentQueryParameters.ExcludeSectionArg, + orderDate = ctx arg PaginationParameters.OrderDate, + orderBy = ctx arg PaginationParameters.OrderBy, + limit = ctx arg PaginationParameters.Limit, + cursor = ctx arg PaginationParameters.Cursor, + ) + }) ) ) diff --git a/src/main/scala/com/gu/contentapi/porter/graphql/TagQueryParameters.scala b/src/main/scala/com/gu/contentapi/porter/graphql/TagQueryParameters.scala index 2c3d86d..80df28f 100644 --- a/src/main/scala/com/gu/contentapi/porter/graphql/TagQueryParameters.scala +++ b/src/main/scala/com/gu/contentapi/porter/graphql/TagQueryParameters.scala @@ -121,5 +121,6 @@ object TagQueryParameters { val AllTagQueryParameters = QueryString :: tagId :: Section :: TagType :: Fuzziness :: Category :: Reference :: Cursor :: OrderBy :: Limit :: Nil - val NonPaginatedTagQueryParameters = Section :: TagType :: Nil + val NonPaginatedTagQueryParameters = QueryString :: tagId :: Section :: TagType :: Fuzziness :: Category :: + Reference :: Nil } diff --git a/src/main/scala/datastore/ElasticsearchRepo.scala b/src/main/scala/datastore/ElasticsearchRepo.scala index a23d3cd..ed5d00e 100644 --- a/src/main/scala/datastore/ElasticsearchRepo.scala +++ b/src/main/scala/datastore/ElasticsearchRepo.scala @@ -163,7 +163,7 @@ class ElasticsearchRepo(endpoint:ElasticNodeEndpoint, val defaultPageSize:Int=20 Some(limitToChannelQuery(selectedChannel)), queryString.map(MultiMatchQuery(_, fields = fieldsToQuery)), atomId.map(MatchQuery("atomIds.id", _)), - tagIds.map(tags=>BoolQuery(must=tags.map(MatchQuery("tags", _)))) , + tagIds.map(tags=>BoolQuery(should=tags.map(MatchQuery("tags", _)))) , excludeTags.map(tags=>BoolQuery(not=Seq(BoolQuery(should=tags.map(MatchQuery("tags", _)))))), sectionIds.map(s=>BoolQuery(should=s.map(MatchQuery("sectionId", _)))), excludeSections.map(s=>BoolQuery(not=Seq(BoolQuery(should=s.map(MatchQuery("sectionId", _))))))