This commit is contained in:
parent
c4c7ce0ad4
commit
48b8209e23
|
@ -287,11 +287,11 @@ 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 text and len(text) > 2:
|
if text and len(text) > 2:
|
||||||
results = await SearchService.search(text, limit, offset)
|
results = await SearchService.search(text, limit, offset)
|
||||||
results_dict = {}
|
results_dict = {r["slug"]: r for r in results}
|
||||||
for r in results:
|
print(results_dict)
|
||||||
results_dict[r["slug"]] = r
|
|
||||||
q = (
|
q = (
|
||||||
select(Shout) # Add "score" column
|
select(Shout)
|
||||||
.options(
|
.options(
|
||||||
joinedload(Shout.authors),
|
joinedload(Shout.authors),
|
||||||
joinedload(Shout.topics),
|
joinedload(Shout.topics),
|
||||||
|
@ -299,15 +299,20 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
||||||
.where(and_(Shout.deleted_at.is_(None), Shout.slug.in_(results_dict.keys())))
|
.where(and_(Shout.deleted_at.is_(None), Shout.slug.in_(results_dict.keys())))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
shouts_data = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
results = session.execute(q).unique()
|
results = list(session.execute(q).unique())
|
||||||
|
print(results)
|
||||||
for result in results:
|
print(f"[resolvers.reader] searched, preparing {len(results)} results")
|
||||||
shout_slug = result.get("slug")
|
for x in results:
|
||||||
|
shout = x[0]
|
||||||
|
shout_slug = shout.dict().get("slug", "")
|
||||||
score = results_dict.get(shout_slug, {}).get("score", 0)
|
score = results_dict.get(shout_slug, {}).get("score", 0)
|
||||||
result["score"] = score
|
shout_data = shout.dict() # Convert the Shout instance to a dictionary
|
||||||
|
shout_data["score"] = score # Add the score to the dictionary
|
||||||
|
shouts_data.append(shout_data)
|
||||||
|
|
||||||
return results
|
return shouts_data
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user