Skip to content

Commit

Permalink
Limit results returned per plugin
Browse files Browse the repository at this point in the history
Related to #23
  • Loading branch information
otsaloma committed Oct 23, 2023
1 parent f4ffb00 commit 112f811
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
PENDING: Catapult 1.0
=====================

* Limit results returned per plugin (default 24) to avoid issues with
huge file indexes paired with short query strings (#23)

2023-08-31: Catapult 0.999
==========================

Expand Down
1 change: 1 addition & 0 deletions catapult/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ConfigurationStore(catapult.DebugMixin):

_defaults = {
"max_results": 24,
"max_results_per_plugin": 24,
"max_results_visible": 7,
"plugins": ["apps", "builtins", "calculator", "clipboard", "files", "session"],
"theme": "dark",
Expand Down
6 changes: 5 additions & 1 deletion catapult/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def _get_results(self, plugins, query):
for plugin in plugins:
self.tick()
try:
yield from plugin.search(query)
for i, result in enumerate(plugin.search(query)):
yield result
if i + 1 >= catapult.conf.max_results_per_plugin:
self.debug(f"Terminating after {i+1} results")
break
elapsed = self.tock()
self.debug(f"{plugin.name} delivered in {elapsed:.0f} ms")
except Exception:
Expand Down

0 comments on commit 112f811

Please sign in to comment.