Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
search: Display query in App Search benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaty committed Sep 10, 2021
1 parent 9c1ce86 commit 39a1dc9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/pcapi/scripts/benchmark_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def search(self, description, criteria):
result["objectID"] = human_ids.dehumanize(result["objectID"])
return ResultSet(
elapsed=elapsed,
query=filters, # searched text is missing but we don't need it for Algolia
results=[
Result(
id=int(result["objectID"]),
Expand Down Expand Up @@ -256,6 +257,7 @@ def search(self, description, criteria):
results = out["results"]
return ResultSet(
elapsed=response.elapsed.total_seconds() if response else 0,
query=query,
results=[
Result(
id=int(result["id"]["raw"]),
Expand Down Expand Up @@ -283,8 +285,13 @@ def url(self):
@dataclasses.dataclass
class ResultSet:
elapsed: float
query: dict
results: [Result]

@property
def pretty_printed_query(self):
return pprint.pformat(self.query)


@dataclasses.dataclass
class Case:
Expand Down Expand Up @@ -323,7 +330,10 @@ def default(self, obj):
"value": {"id": obj.id, "score": obj.score, "name": obj.name, "full": obj.full},
}
if isinstance(obj, ResultSet):
return {"__type__": "ResultSet", "value": {"elapsed": obj.elapsed, "results": obj.results}}
return {
"__type__": "ResultSet",
"value": {"elapsed": obj.elapsed, "query": obj.query, "results": obj.results},
}
if isinstance(obj, datetime.datetime):
return {"__type__": "datetime.datetime", "value": obj.isoformat()}
return json.JSONEncoder.default(self, obj)
Expand Down Expand Up @@ -489,6 +499,10 @@ def main():
<td>
<div class="elapsed {% if result_set.elapsed > 1 %} slow-search{% endif %}">
Temps de réponse : {{ "%.3f"|format(result_set.elapsed) }}s
<details>
<summary>Requête</summary>
<pre>{{ result_set.pretty_printed_query }}</pre>
</details>
</div>
<ol>
{% for result in result_set.results %}
Expand Down

0 comments on commit 39a1dc9

Please sign in to comment.