From c85672b2093c46828031f68a52fa97eac5bfeb19 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Mon, 5 Sep 2022 10:28:23 +0300 Subject: [PATCH] dummy search query interface --- resolvers/zine.py | 22 ++++++++++++++++++++++ schema.graphql | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/resolvers/zine.py b/resolvers/zine.py index 02d66fac..85d69d9d 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -83,6 +83,28 @@ async def get_shout_by_slug(_, info, slug): return shout +@query.field("searchQuery") +async def get_search_results(_, info, query, page, size): + # TODO: remove the copy of searchByTopics + # with search ranking query + page = page - 1 + with local_session() as session: + shouts = ( + session.query(Shout) + .join(ShoutTopic) + .where(and_(ShoutTopic.topic.in_(query), bool(Shout.publishedAt))) + .order_by(desc(Shout.publishedAt)) + .limit(size) + .offset(page * size) + ) + + for s in shouts: + for a in s.authors: + a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug) + s.stat.search = 1 # FIXME + return shouts + + @query.field("shoutsByTopics") async def shouts_by_topics(_, info, slugs, page, size): page = page - 1 diff --git a/schema.graphql b/schema.graphql index 8716636f..411be838 100644 --- a/schema.graphql +++ b/schema.graphql @@ -259,6 +259,9 @@ type Query { # communities getCommunity(slug: String): Community! getCommunities: [Community]! # all + + # search + searchQuery(q: String, page: Int, size: Int): Shout[] } ############################################ Subscription @@ -423,6 +426,7 @@ type Stat { reacted: Int rating: Int commented: Int + ranking: Int } type Community {