-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(search): Result set cutoff #5906
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
Merged
+43
−20
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,8 +39,8 @@ class IndexResult { | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| BorrowedView Borrowed() const; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Move out of owned or copy borrowed | ||||||||||||||||||||||||||||||
| DocVec Take(); | ||||||||||||||||||||||||||||||
| // Move out of owned or copy borrowed. Take up to `limit` entries and return original size. | ||||||||||||||||||||||||||||||
| std::pair<DocVec, size_t /* full size */> Take(size_t limit = std::numeric_limits<size_t>::max()); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||
| bool IsOwned() const; | ||||||||||||||||||||||||||||||
|
|
@@ -82,18 +82,36 @@ inline IndexResult::BorrowedView IndexResult::Borrowed() const { | |||||||||||||||||||||||||||||
| return std::visit(cb, value_); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| inline IndexResult::DocVec IndexResult::Take() { | ||||||||||||||||||||||||||||||
| inline std::pair<IndexResult::DocVec, size_t> IndexResult::Take(size_t limit) { | ||||||||||||||||||||||||||||||
| if (IsOwned()) { | ||||||||||||||||||||||||||||||
| return std::move(std::get<DocVec>(value_)); | ||||||||||||||||||||||||||||||
| auto& vec = std::get<DocVec>(value_); | ||||||||||||||||||||||||||||||
| size_t size = vec.size(); | ||||||||||||||||||||||||||||||
| return {std::move(vec), size}; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| auto cb = [](auto* set) -> DocVec { | ||||||||||||||||||||||||||||||
| // Numeric ranges need to be filtered and don't know their exact size ahead | ||||||||||||||||||||||||||||||
| if (std::holds_alternative<RangeResult>(value_)) { | ||||||||||||||||||||||||||||||
| auto cb = [limit](auto* range) -> std::pair<DocVec, size_t> { | ||||||||||||||||||||||||||||||
| DocVec out; | ||||||||||||||||||||||||||||||
| size_t total = 0; | ||||||||||||||||||||||||||||||
| out.reserve(std::min(limit, range->size())); | ||||||||||||||||||||||||||||||
| for (auto it = range->begin(); it != range->end(); ++it) { | ||||||||||||||||||||||||||||||
| total++; | ||||||||||||||||||||||||||||||
| if (out.size() < limit) | ||||||||||||||||||||||||||||||
| out.push_back(*it); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| return {std::move(out), total}; | ||||||||||||||||||||||||||||||
|
Comment on lines
+96
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| return std::visit(cb, Borrowed()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Generic borrowed results sets don't need to be filtered, so we can tell the result size ahead | ||||||||||||||||||||||||||||||
| auto cb = [limit](auto* set) -> std::pair<DocVec, size_t> { | ||||||||||||||||||||||||||||||
| DocVec out; | ||||||||||||||||||||||||||||||
| out.reserve(set->size()); | ||||||||||||||||||||||||||||||
| for (auto it = set->begin(); it != set->end(); ++it) { | ||||||||||||||||||||||||||||||
| out.reserve(std::min(limit, set->size())); | ||||||||||||||||||||||||||||||
| for (auto it = set->begin(); it != set->end() && out.size() < limit; ++it) | ||||||||||||||||||||||||||||||
| out.push_back(*it); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| return out; | ||||||||||||||||||||||||||||||
| return {std::move(out), set->size()}; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| return std::visit(cb, Borrowed()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we do total increasing even if we don't add result into out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we want to return the original size, not the filtered size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment above