dummy search query interface

This commit is contained in:
tonyrewin 2022-09-05 10:28:23 +03:00
parent 661bbcd1de
commit c85672b209
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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 {