Skip to content

Commit

Permalink
chore: ckanapi compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 4, 2023
1 parent 1b6f891 commit fff9f07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion ckanext/search_tweaks/query_popularity/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def search_tweaks_query_popularity_export(
return {"results": results, "count": len(results)}


@tk.side_effect_free
def search_tweaks_query_popularity_ignore(
context: types.Context, data_dict: dict[str, Any]
):
Expand Down
11 changes: 7 additions & 4 deletions ckanext/search_tweaks/query_popularity/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):

def export(self):
data: dict[bytes, dict[str, Any]] = {
hash: {"query": query, "records": []}
hash: {"query": query.decode(), "records": []}
for hash, query in self.redis.hgetall(self.trans_key()).items()
}
for k, v in self.redis.hscan_iter(self.distribution_key()):
Expand All @@ -36,7 +36,7 @@ def export(self):
except ValueError:
continue

data[q_hash]["records"].append({"date": date, "count": int(v)})
data[q_hash]["records"].append({"date": date.isoformat(), "count": int(v)})

return list(data.values())

Expand Down Expand Up @@ -155,11 +155,14 @@ def distribution_key(self):
def format_date_stem(self, date: datetime):
return date.strftime(self.date_format)

def stats(self, num: int) -> Iterable[dict[str, Any]]:
def stats(self, num: int) -> Iterable[dict[str, str | float]]:
scores: list[tuple[bytes, float]] = self.redis.zrange(
self.score_key(), 0, num - 1, desc=True, withscores=True
)
trans_key = self.trans_key()

for k, v in scores:
yield {"query": self.redis.hget(trans_key, k), "score": v}
query = self.redis.hget(trans_key, k)
if not query:
continue
yield {"query": query.decode(), "score": v}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-search-tweaks
version = 0.6.0
version = 0.6.1a0
description =
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit fff9f07

Please sign in to comment.