diff --git a/gorse/__init__.py b/gorse/__init__.py index 82d4bf6..24bd0fe 100644 --- a/gorse/__init__.py +++ b/gorse/__init__.py @@ -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: diff --git a/setup.py b/setup.py index 63c2b71..2297055 100644 --- a/setup.py +++ b/setup.py @@ -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'], diff --git a/tests/test_gorse.py b/tests/test_gorse.py index 1b42d7f..ccbf748 100644 --- a/tests/test_gorse.py +++ b/tests/test_gorse.py @@ -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():