search dummy service
This commit is contained in:
parent
e16265a0c3
commit
d678729ffc
|
@ -14,6 +14,7 @@ from resolvers.topics import topic_follow, topic_unfollow
|
|||
from services.stat.viewed import ViewedStorage
|
||||
from services.zine.shoutauthor import ShoutAuthorStorage
|
||||
from services.zine.shoutscache import ShoutsCache
|
||||
from services.zine import SearchService
|
||||
|
||||
|
||||
@mutation.field("incrementView")
|
||||
|
@ -98,24 +99,14 @@ async def get_shout_by_slug(_, info, slug):
|
|||
|
||||
@query.field("searchQuery")
|
||||
async def get_search_results(_, _info, searchtext, offset, limit):
|
||||
# TODO: remove the copy of searchByTopics
|
||||
# with search ranking query
|
||||
with local_session() as session:
|
||||
shouts = (
|
||||
session.query(Shout)
|
||||
.join(ShoutTopic)
|
||||
.where(and_(ShoutTopic.topic.in_(searchtext), Shout.publishedAt.is_not(None)))
|
||||
.order_by(desc(Shout.publishedAt))
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
)
|
||||
|
||||
for s in shouts:
|
||||
shout = s.dict()
|
||||
for a in shout['authors']:
|
||||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||
s.stat.relevance = 1 # FIXME: expecting search engine rated relevance
|
||||
return shouts
|
||||
shouts = SearchService.search(searchtext)
|
||||
# TODO: sort and filter types for search service
|
||||
for s in shouts:
|
||||
shout = s.dict()
|
||||
for a in shout['authors']:
|
||||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||
s.stat.relevance = 1 # FIXME: expecting search engine rated relevance
|
||||
return shouts[offset : offset + limit]
|
||||
|
||||
|
||||
@query.field("shoutsByAuthors")
|
||||
|
|
|
@ -3,6 +3,7 @@ from services.stat.reacted import ReactedStorage
|
|||
from services.auth.roles import RoleStorage
|
||||
from services.auth.users import UserStorage
|
||||
from services.zine.topics import TopicStorage
|
||||
from services.search import SearchService
|
||||
from base.orm import local_session
|
||||
|
||||
|
||||
|
@ -14,4 +15,5 @@ async def storages_init():
|
|||
RoleStorage.init(session)
|
||||
UserStorage.init(session)
|
||||
TopicStorage.init(session)
|
||||
SearchService.init(session)
|
||||
session.commit()
|
||||
|
|
19
services/search.py
Normal file
19
services/search.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import asyncio
|
||||
from orm.shout import Shout
|
||||
|
||||
|
||||
class SearchService:
|
||||
lock = asyncio.Lock()
|
||||
cache = {}
|
||||
|
||||
@staticmethod
|
||||
def init(session):
|
||||
self = SearchService
|
||||
async with self.lock:
|
||||
self.cache = {}
|
||||
|
||||
@staticmethod
|
||||
async def search(text) -> [Shout]:
|
||||
self = SearchService
|
||||
async with self.lock:
|
||||
return [] # TODO: implement getting shouts list
|
Loading…
Reference in New Issue
Block a user