diff --git a/pyproject.toml b/pyproject.toml index cbce9144..46e2d6f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "discoursio-core" -version = "0.2.21" +version = "0.2.22" description = "core module for discours.io" authors = ["discoursio devteam"] license = "MIT" @@ -18,7 +18,6 @@ ariadne = "^0.21" aiohttp = "^3.9.1" google-oauth2-tool = "^0.0.3" google-api-python-client = "^2.114.0" -pandas = "^2.2.0" pre-commit = "^3.6.0" granian = "^1.0.1" diff --git a/resolvers/reader.py b/resolvers/reader.py index b8969e59..a506626a 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -326,9 +326,36 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0): print(f'[resolvers.reader] searched, preparing {len(results)} results') for x in results: shout = x[0] - shout_slug = shout.dict().get('slug', '') + shout_data = shout.dict() + shout_slug = shout_data.get('slug', '') + topic = ( + session.query(Topic) + .join( + ShoutTopic, + and_( + ShoutTopic.topic == Topic.id, + ShoutTopic.shout == shout.id, + ShoutTopic.main == True, + ), + ) + .first() + ) + if topic: + shout_data['main_topic'] = topic + authors = ( + session.query(Author) + .join( + ShoutTopic, + and_( + ShoutAuthor.author == Author.id, + ShoutTopic.shout == shout.id, + ), + ) + .all() + ) + if authors: + shout_data['authors'] = authors score = results_dict.get(shout_slug, {}).get('score', 0) - shout_data = shout.dict() # Convert the Shout instance to a dictionary shout_data['score'] = score # Add the score to the dictionary shouts_data.append(shout_data) diff --git a/schemas/core.graphql b/schemas/core.graphql index 4a3ab404..135b2cd2 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -138,6 +138,7 @@ type Shout { published_at: Int media: String stat: Stat + score: Float } type Stat {