commit 4136079b4e38f5d072e1aa61baa8c28e5df6409b
parent 20a5cb896d0eee3d271565ce420f74a598e1f94b
Author: Natalie Pendragon <natpen@natpen.net>
Date: Sat, 16 May 2020 08:12:22 -0400
[serve] Improve search result data type
Diffstat:
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/gus/serve.py b/gus/serve.py
@@ -195,7 +195,14 @@ def _search_index(query, requested_page):
results = searcher.search_page(query, requested_page, pagelen=10)
return (
len(results),
- [(result.score, result["url"], result["content_type"], result["prompt"] if "prompt" in result else "") for result in results]
+ [{
+ "score" : result.score,
+ "indexed_at" : result["indexed_at"],
+ "url" : result["url"],
+ "content_type" : result["content_type"],
+ "prompt" : result["prompt"] if "prompt" in result else ""
+ } for result in results
+ ]
)
@@ -226,11 +233,12 @@ def _render_results(results):
for i, result in enumerate(results):
if i > 0:
data.append("")
+
prompt_suffix = ""
- if result[2] == "input":
- prompt_suffix = ": {}".format(result[3])
- data.append("=> {}".format(result[1]))
- data.append("{}{} (score: {:.2f})".format(result[2], prompt_suffix, result[0]))
+ if result["content_type"] == "input":
+ prompt_suffix = ": {}".format(result["prompt"])
+ data.append("=> {}".format(result["url"]))
+ data.append("{}{} (score: {:.2f})".format(result["content_type"], prompt_suffix, result["score"]))
return data