Skip to content

Commit

Permalink
support get neighbors with offset
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz committed Sep 26, 2022
1 parent a171097 commit e267bc0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gorse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def session_recommend(self, feedbacks: list, n: int = 10) -> list:
return r.json()
raise GorseException(r.status_code, r.text)

def get_neighbors(self, item_id: str, n: int = 3) -> List[str]:
def get_neighbors(self, item_id: str, n: int = 10, offset: int = 0) -> List[str]:
r = requests.get(
self.entry_point + "/api/item/%s/neighbors?n=%d" % (item_id, n),
self.entry_point + "/api/item/%s/neighbors?n=%d&offset=%d" % (item_id, n, offset),
headers={"X-API-Key": self.api_key},
)
if r.status_code == 200:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = (this_directory / "README.md").read_text()

setup(name='PyGorse',
version='0.4.3',
version='0.4.4',
description='Python SDK for gorse recommender system',
packages=['gorse'],
install_requires=['requests>=2.14.0'],
Expand Down
4 changes: 3 additions & 1 deletion tests/test_gorse.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ def test_neighbors():
r.zadd('item_neighbors/100', {'1': 1, '2': 2, '3': 3})

client = Gorse(GORSE_ENDPOINT, GORSE_API_KEY)
items = client.get_neighbors('100')
items = client.get_neighbors('100', n=3)
assert items == [{'Id': '3', 'Score': 3}, {'Id': '2', 'Score': 2}, {'Id': '1', 'Score': 1}]
items = client.get_neighbors('100', n=1, offset=1)
assert items == [{'Id': '2', 'Score': 2}]


def test_session_recommend():
Expand Down

0 comments on commit e267bc0

Please sign in to comment.