This commit is contained in:
@@ -21,6 +21,7 @@ from orm.community import Community, CommunityAuthor, CommunityFollower
|
||||
from orm.shout import Shout, ShoutAuthor
|
||||
from resolvers.stat import get_with_stat
|
||||
from services.auth import login_required
|
||||
from services.search import search_service
|
||||
from storage.db import local_session
|
||||
from storage.redis import redis
|
||||
from storage.schema import mutation, query
|
||||
@@ -445,9 +446,40 @@ async def load_authors_by(
|
||||
|
||||
@query.field("load_authors_search")
|
||||
async def load_authors_search(_: None, info: GraphQLResolveInfo, **kwargs: Any) -> list[Any]:
|
||||
"""Search for authors"""
|
||||
# TODO: Implement search functionality
|
||||
return []
|
||||
"""Search for authors by name or bio using Muvera search service"""
|
||||
text = kwargs.get("text", "")
|
||||
limit = kwargs.get("limit", 10)
|
||||
offset = kwargs.get("offset", 0)
|
||||
|
||||
if not text or len(text.strip()) < 2:
|
||||
return []
|
||||
|
||||
try:
|
||||
# Use Muvera search service for authors
|
||||
search_results = await search_service.search_authors(text, limit, offset)
|
||||
|
||||
if not search_results:
|
||||
return []
|
||||
|
||||
# Extract author IDs from search results
|
||||
author_ids = [int(result["id"]) for result in search_results if result.get("id", "").isdigit()]
|
||||
|
||||
if not author_ids:
|
||||
return []
|
||||
|
||||
# Fetch full author data from database
|
||||
with local_session() as session:
|
||||
authors = session.query(Author).where(Author.id.in_(author_ids)).all()
|
||||
|
||||
# Sort by search relevance (maintain order from search results)
|
||||
author_dict = {author.id: author for author in authors}
|
||||
sorted_authors = [author_dict.get(aid) for aid in author_ids if aid in author_dict]
|
||||
|
||||
return [author.dict() for author in sorted_authors if author]
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Error in author search for '{text}': {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_author_id_from(slug: str | None = None, user: str | None = None, author_id: int | None = None) -> int | None:
|
||||
|
||||
@@ -429,7 +429,7 @@ async def publish_draft(_: None, info: GraphQLResolveInfo, draft_id: int) -> dic
|
||||
return {"error": f"Cannot publish draft: {error}"}
|
||||
|
||||
# Проверяем, есть ли уже публикация для этого черновика
|
||||
shout = None
|
||||
shout: Any = None
|
||||
if draft.shout:
|
||||
shout = session.query(Shout).where(Shout.id == draft.shout).first()
|
||||
if shout:
|
||||
@@ -463,6 +463,10 @@ async def publish_draft(_: None, info: GraphQLResolveInfo, draft_id: int) -> dic
|
||||
session.add(shout)
|
||||
session.flush() # Получаем ID нового шаута
|
||||
|
||||
# Ensure shout is not None before proceeding
|
||||
if not shout:
|
||||
return {"error": "Failed to create or update shout"}
|
||||
|
||||
# Очищаем существующие связи
|
||||
session.query(ShoutAuthor).where(ShoutAuthor.shout == shout.id).delete()
|
||||
session.query(ShoutTopic).where(ShoutTopic.shout == shout.id).delete()
|
||||
@@ -493,7 +497,7 @@ async def publish_draft(_: None, info: GraphQLResolveInfo, draft_id: int) -> dic
|
||||
await notify_shout(shout.dict(), "published")
|
||||
|
||||
# Обновляем поисковый индекс
|
||||
await search_service.perform_index(shout)
|
||||
search_service.index(shout)
|
||||
|
||||
logger.info(f"Successfully published shout #{shout.id} from draft #{draft_id}")
|
||||
logger.debug(f"Shout data: {shout.dict()}")
|
||||
|
||||
@@ -553,7 +553,7 @@ async def update_shout(
|
||||
await notify_shout(shout_by_id.dict(), "update")
|
||||
else:
|
||||
await notify_shout(shout_by_id.dict(), "published")
|
||||
# search service indexing
|
||||
# Обновляем поисковый индекс
|
||||
search_service.index(shout_by_id)
|
||||
for a in shout_by_id.authors:
|
||||
await cache_by_id(Author, a.id, cache_author)
|
||||
|
||||
@@ -10,7 +10,7 @@ from orm.author import Author
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from services.search import SearchService, search_text
|
||||
from services.search import search_service
|
||||
from services.viewed import ViewedStorage
|
||||
from storage.db import json_array_builder, json_builder, local_session
|
||||
from storage.schema import query
|
||||
@@ -491,8 +491,8 @@ async def load_shouts_search(
|
||||
logger.info(f"[load_shouts_search] Starting search for '{text}' with limit={limit}, offset={offset}")
|
||||
|
||||
if isinstance(text, str) and len(text) > 2:
|
||||
logger.debug(f"[load_shouts_search] Calling search_text service for '{text}'")
|
||||
results = await search_text(text, limit, offset)
|
||||
logger.debug(f"[load_shouts_search] Calling Muvera search service for '{text}'")
|
||||
results = await search_service.search(text, limit, offset)
|
||||
|
||||
logger.debug(f"[load_shouts_search] Search service returned {len(results)} results for '{text}'")
|
||||
|
||||
@@ -624,7 +624,6 @@ async def load_shouts_random_top(_: None, info: GraphQLResolveInfo, options: dic
|
||||
|
||||
async def fetch_all_shouts(
|
||||
session: Session,
|
||||
search_service: SearchService,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
search_query: str = "",
|
||||
|
||||
Reference in New Issue
Block a user