Skip to content

Commit

Permalink
Merge branch 'third-try-trending' of github.com:benbdeitch/openlibrar…
Browse files Browse the repository at this point in the history
…yfork into third-try-trending
  • Loading branch information
benbdeitch committed Jan 10, 2025
2 parents 44ce878 + b2d10ca commit b16269d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions openlibrary/solr/data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,45 @@ def get_solr_trending_scores(self, work_key: str) -> dict | None:
}
return doc

def get_solr_trending_scores(self, work_key: str) -> dict | None:
"""
Fetches the record's information from Solr.
:param work_key: type-prefixed key
"""

response = requests.post(
get_solr_base_url() + '/query',
json={
"params": {
"json.nl": "arrarr",
"q": "key: %s" % work_key,
"fl": [
"trending_score_hourly_sum",
'trending_score_hourly_*',
"trending_score_daily_*",
"trending_z_score",
],
"sort": "trending_z_score desc",
}
},
)
reply = response.json().get('docs', {}) if response.json() else {}
reply = reply[0] if reply else {}
doc: dict = {
f'trending_score_hourly_{index}': reply.get(
f'trending_score_hourly_{index}', 0
)
for index in range(24)
}
doc |= {"trending_score_hourly_sum": reply.get("trending_score_hourly_sum", 0)}
doc |= {
f'trending_score_daily_{index}': reply.get(
f'trending_score_daily_{index}', 0
)
for index in range(7)
}
return doc

def get_work_ratings(self, work_key: str) -> WorkRatingsSummary | None:
raise NotImplementedError

Expand Down

0 comments on commit b16269d

Please sign in to comment.