Skip to content

Commit

Permalink
Don't apply SQL-side result limits as they aren't sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 15, 2019
1 parent cdd57d0 commit 7c80851
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ def _sort_search_results(self, results: List[XKCDIndex], query: str
@command.argument("query", pass_raw=True)
async def search(self, evt: MessageEvent, query: str) -> None:
sql_query = f"%{query}%"
limit = self.config["max_search_results"]
results = self.xkcd_index.query.filter(or_(self.xkcd_index.title.like(sql_query),
self.xkcd_index.alt.like(sql_query),
self.xkcd_index.transcript.like(sql_query))
).limit(limit * 2).all()
).all()
if len(results) == 0:
await evt.reply("No results :(")
else:
results = list(self._sort_search_results(results, query))
msg = "Results:\n\n"
more_results = None
limit = self.config["max_search_results"]
if len(results) > limit:
more_results = len(results) - limit, results[limit][1]
results = results[:limit]
Expand Down

0 comments on commit 7c80851

Please sign in to comment.