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

Hard limit the number of results returned by a search #2281

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

Kerollmops
Copy link
Member

@Kerollmops Kerollmops commented Mar 29, 2022

This PR fixes #2133 by hard-limiting the number of results that a search request can return at any time. I would like the guidance of @MarinPostma to test that, should I use a mocking test here? Or should I do anything else?

I talked about touching the nb_hits value with @qdequele and we concluded that it was not correct to do so.

Could you please confirm that it is the right place to change that?

@MarinPostma
Copy link
Contributor

MarinPostma commented Mar 30, 2022

I don't think that this is how it should be done.

what if I ask for 1 document at offset 10000?

I think we need to pass the following params to milli:

offset = min(offset, HARD_RESULT_LIMIT);
limit = min(limit, HARD_RESULT_LIMIT - offset);

wdyt?

@Kerollmops
Copy link
Member Author

Ahha yeah, I'm dumb, you are absolutely right. That's probably due to jet lag. I will update my PR accordingly. Thanks!

meilisearch-lib/src/index/search.rs Show resolved Hide resolved
meilisearch-lib/src/index/search.rs Show resolved Hide resolved
meilisearch-lib/src/index/search.rs Show resolved Hide resolved
@MarinPostma
Copy link
Contributor

@Kerollmops, for testability, you could in fact do a mock here, but maybe the simple option would be to make a function like compute_offset_limit(offset: usize, limit: usize) -> (usize, uszie), and unit test that function instead, wdyt?

If we wanted to make integration tests, having a way to lower the value of MAX_RESULT_LIMIT would be useful so we don't have to create search results with 1000 hits, but who should own this setting is another question...

@Kerollmops
Copy link
Member Author

@Kerollmops, for testability, you could in fact do a mock here, but maybe the simple option would be to make a function like compute_offset_limit(offset: usize, limit: usize) -> (usize, uszie), and unit test that function instead, wdyt?

I don't think that we need to move this simple logic in another function, it is not used in any other place.

If we wanted to make integration tests, having a way to lower the value of MAX_RESULT_LIMIT would be useful so we don't have to create search results with 1000 hits, but who should own this setting is another question...

I just added two integration tests that check that a placeholder or normal search is limited and even changing the offset to a big number doesn't expose documents past our hard 1000 limit. Thank you for that by the way 😂

@curquiza curquiza added this to the v0.27.0 milestone Apr 4, 2022
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me ✅

Wait for the final Marin's approval for the merge

@Kerollmops
Copy link
Member Author

Thank you for the reviews, merging now!
bors merge

@bors
Copy link
Contributor

bors bot commented Apr 4, 2022

@bors bors bot merged commit 09a72ce into main Apr 4, 2022
@bors bors bot deleted the hard-limit-search-results branch April 4, 2022 17:35
@curquiza curquiza added the v0.27.0 PRs/issues solved in v0.27.0 label Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v0.27.0 PRs/issues solved in v0.27.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hard limit when searching documents
3 participants