Skip to content

Commit

Permalink
Merge pull request #114 from ecolabdata/fix/search-off-by-one
Browse files Browse the repository at this point in the history
  • Loading branch information
streino authored Feb 19, 2025
2 parents cf939b7 + 4e30752 commit f262808
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions isomorphe/geonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def info(self):
def get_records(self, query: dict[str, Any] | None = None) -> list[Record]:
params = self._search_params(query)
records = []
to = 0
from_pos = 0
while True:
hits = self._search_hits(params, from_pos=to + 1)
hits = self._search_hits(params, from_pos=from_pos)
if not hits:
break
recs = []
Expand All @@ -146,7 +146,7 @@ def get_records(self, query: dict[str, Any] | None = None) -> list[Record]:
else:
log.debug(f"Skipping empty record: {hit}")
records += recs
to += len(hits)
from_pos += len(hits)
return records

@abc.abstractmethod
Expand Down Expand Up @@ -386,7 +386,7 @@ def _search_hits(self, params: dict[str, Any], from_pos: int) -> list[dict[str,
r = self.session.get(
f"{self.api}/q",
headers={"Accept": "application/json"},
params=params | {"from": from_pos},
params=params | {"from": from_pos + 1}, # v3 'from' param starts at 1
)
r.raise_for_status()
rsp = r.json()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gn_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_get_records_v4(requests_mock: requests_mock.Mocker):
"isTemplate",
"mdStatus",
],
"from": 1,
"from": 0,
}


Expand Down

0 comments on commit f262808

Please sign in to comment.