Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paginated post_search and scroll to SearchClient, plus role methods #507

Merged
merged 6 commits into from
Feb 10, 2022

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Jan 26, 2022

The SearchClient gains three new methods here: paginated.post_search, scroll, and paginated.scroll

This also begins the long road towards having more complete test coverage of the SearchClient, its helpers, and methods.
These APIs are slightly different from some of the existing paginated ones, in that their pagination parameters are body params, not query params. However, because the paginator objects "just" pass their relevant arguments through to the client methods (marker, limit, etc), it is possible to support these only by ensuring that marker, limit, and offset are supported as keyword args.
Some care is taken not to mutate the data which was passed in to these methods, but otherwise the implementation does not require special efforts.

In order to make scroll more usable, an additional helper object is added, SearchScrollQuery, for this specialized query type.
The newly fleshed out documentation on this and SearchQuery should clarify the difference.

Enable paginated searches via this method.

Pagination is different in this API from any existing APIs because
`limit` and `offset` are sent as body parameters. As a result, some
changes need to be made. The client method must support passing these
and setting them in the passed data (as overrides).

In the case that these are passed, the body therefore needs to be
(shallow) copied before being updated. Tests ensure that this is done
correctly, and that paging will therefore not be side-effecting.
A new method of `SearchClient`, `scroll`, allows access to the
scrolling API. `SearchScrollQuery` is a helper type for easily
building query documents. Scroll queries are similar to typical
searches, but do not support all of the same fields, including
boosts and facets. As a result, to support this alternate type, it and
SearchQuery now share an internal base class which provides several of
their shared methods.

A new test exercises `paginated.scroll`, confirming that it works as
expected with both dict data and `SearchScrollQuery`. Like paginated
`post_search`, the method is written carefully to not be
side-effecting on the data it is passed, and the test confirms this.
show-inheritance in autodoc behaves badly by default on these classes
because they inherit from UserDict, and it therefore shows all of
their dict-like methods.
In order to have clear, but non-repetitious, documentation, the
SearchQueryBase class is now documented, with a note that it is only
included in docs to show the methods it provides.

None of the methods of the search helpers were being picked up under
autodoc because they had no docstrings. To rectify, add docstrings to
all methods.
@sirosen sirosen changed the title Add paginated post_search and scroll to SearchClient Add paginated post_search and scroll to SearchClient, plus role methods Jan 26, 2022
@sirosen
Copy link
Member Author

sirosen commented Jan 26, 2022

I've added the methods which would be needed for globus/globus-cli#597 to this PR, and updated the title. It was easier to add them here than to deal with the (inevitable) merge conflicts that would arise from adding them separately.

The methods are extremely simple and easy to test.

@sirosen sirosen removed the request for review from rudyardrichter January 28, 2022 19:31
src/globus_sdk/services/search/client.py Outdated Show resolved Hide resolved
tests/functional/search/test_search.py Outdated Show resolved Hide resolved
tests/functional/search/test_search.py Outdated Show resolved Hide resolved
@sirosen sirosen merged commit 6f39701 into globus:main Feb 10, 2022
@sirosen sirosen deleted the search-client-updates branch May 27, 2022 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant