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:
|
||||
|
||||
Reference in New Issue
Block a user