This commit is contained in:
parent
67e4cacb28
commit
465d9093bd
|
@ -297,14 +297,19 @@ async def load_shouts_feed(_, info, options):
|
||||||
async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
||||||
if isinstance(text, str) and len(text) > 2:
|
if isinstance(text, str) and len(text) > 2:
|
||||||
results = await search_text(text, limit, offset)
|
results = await search_text(text, limit, offset)
|
||||||
shouts_ids = []
|
scores = {}
|
||||||
|
hits_ids = []
|
||||||
for sr in results:
|
for sr in results:
|
||||||
shout_id = sr.get("id")
|
shout_id = sr.get("id")
|
||||||
if shout_id:
|
if shout_id:
|
||||||
shouts_ids.append(int(shout_id))
|
shout_id = int(shout_id)
|
||||||
|
scores[shout_id] = sr.get("score")
|
||||||
|
hits_ids.append(shout_id)
|
||||||
shouts = []
|
shouts = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shouts = session.query(Shout).filter(Shout.id.in_(shouts_ids)).all()
|
shouts = session.query(Shout).filter(Shout.id.in_(hits_ids)).all()
|
||||||
|
for shout in shouts:
|
||||||
|
shout["score"] = scores[int(shout.id)]
|
||||||
return shouts
|
return shouts
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
|
@ -166,12 +166,7 @@ class SearchService:
|
||||||
async def search(self, text, limit, offset):
|
async def search(self, text, limit, offset):
|
||||||
logger.debug(f"Ищем: {text}")
|
logger.debug(f"Ищем: {text}")
|
||||||
search_body = {
|
search_body = {
|
||||||
"query": {
|
"query": {"multi_match": {"query": text, "fields": ["title", "lead", "subtitle", "body", "media"]}}
|
||||||
"multi_match": {
|
|
||||||
"query": text,
|
|
||||||
"fields": ["title", "lead", "subtitle", "body", "media"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.client:
|
if self.client:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user