add /v1/search/top
This commit is contained in:
parent
84ed2a5785
commit
3a77357b8e
2 changed files with 18 additions and 2 deletions
|
|
@ -26,7 +26,7 @@ from suou import twocolon_list, WantsContentType
|
||||||
|
|
||||||
from .colors import color_themes, theme_classes
|
from .colors import color_themes, theme_classes
|
||||||
|
|
||||||
__version__ = '0.5.0-dev40'
|
__version__ = '0.5.0-dev41'
|
||||||
|
|
||||||
APP_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
APP_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
@ -14,6 +15,7 @@ from suou.quart import add_rest
|
||||||
|
|
||||||
from freak.accounts import LoginStatus, check_login
|
from freak.accounts import LoginStatus, check_login
|
||||||
from freak.algorithms import public_timeline, top_guilds_query, topic_timeline, user_timeline
|
from freak.algorithms import public_timeline, top_guilds_query, topic_timeline, user_timeline
|
||||||
|
from freak.search import SearchQuery
|
||||||
|
|
||||||
from ..models import Guild, Post, User, db
|
from ..models import Guild, Post, User, db
|
||||||
from .. import UserLoader, app, app_config, __version__ as freak_version, csrf
|
from .. import UserLoader, app, app_config, __version__ as freak_version, csrf
|
||||||
|
|
@ -258,5 +260,19 @@ async def top_guilds():
|
||||||
|
|
||||||
return dict(has=top_g)
|
return dict(has=top_g)
|
||||||
|
|
||||||
|
## SEARCH ##
|
||||||
|
|
||||||
|
class QueryIn(BaseModel):
|
||||||
|
query: str
|
||||||
|
|
||||||
|
@bp.post('/search/top')
|
||||||
|
@validate_request(QueryIn)
|
||||||
|
async def search_top(data: QueryIn):
|
||||||
|
async with db as session:
|
||||||
|
sq = SearchQuery(data.query)
|
||||||
|
|
||||||
|
result: Iterable[Post] = (await session.execute(sq.select(Post, [Post.title]).limit(20))).scalars()
|
||||||
|
|
||||||
|
return dict(has = [p.feed_info() for p in result])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue