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

Aw/pagination #58

Merged
merged 15 commits into from
Nov 6, 2024
Merged

Aw/pagination #58

merged 15 commits into from
Nov 6, 2024

Conversation

AsiaWi
Copy link
Collaborator

@AsiaWi AsiaWi commented Oct 25, 2024

No description provided.

@AsiaWi AsiaWi marked this pull request as ready for review November 4, 2024 14:13
Copy link
Member

@RogerHowellDfE RogerHowellDfE left a comment

Choose a reason for hiding this comment

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

Do we definitely, always, return results in a consistent and deterministic order/sequence?

If not, I suggest using an offset may not make sense.

I mean, can we point to what, exactly, is stopping results coming back in a different order each time we submit a query? For example, in theory, could this result in page 1 being B, D, A, F and page 2 being D, E, G, H (noting the duplicated D)?

(if I have missed a SortBy somewhere, I apologise! 😁)

Comment on lines 16 to 19
/// <summary>
/// The value used to define how many records are skipped in the search response (if any).
/// </summary>
public int Offset { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Should this have an explicit default value?

e.g., if there is no offset given, the int will default to 0 but this is easy to gloss over.

Copy link
Collaborator

@spanersoraferty spanersoraferty Nov 6, 2024

Choose a reason for hiding this comment

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

Change made. On the point above regarding ordering, this has already been noted and the pagination has been built with the expectation that the ticket to handle ordering will follow which such ensure such anomalies don't occur 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

... cog search attaches a significance to each result and returns in that order though, so it should be consistent? https://learn.microsoft.com/en-us/azure/search/search-pagination-page-layout#paging-results

Copy link
Member

Choose a reason for hiding this comment

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

@CathLass -- from that page (emphasis mine):

The results of paginated queries aren't guaranteed to be stable if the underlying index is changing. Paging changes the value of $skip for each page, but each query is independent and operates on the current view of the data as it exists in the index at query time (in other words, there's no caching or snapshot of results, such as those found in a general purpose database).

If the data changes, or additions/deletions occur, then it looks like results on e.g. page 20 might not be consistent?

Similarly, if we have many documents with the same score how will they be sorted? To illustrate, here's an adapted example from the docs -- for records with a rating of 3, are we sure we won't get ids 2,5,6 on one request/page load and 6,5,2 on another?

{ "id": "1", "rating": 5 }
{ "id": "2", "rating": 3 }
{ "id": "5", "rating": 3 }
{ "id": "6", "rating": 3 }
{ "id": "3", "rating": 2 }
{ "id": "4", "rating": 1 }

In terms of what a user would potentially see is different search results for each refresh of e.g., page 2 (or they'd potentially be in a different order).

Equally, it could be a complete non-issue if the ratings are to, say, fifty decimal places and it's massively unlikely that ratings will ever duplicate? I do not know cog search well enough to know what is normal here, sorry!

/// The Total Count returned from Establishment search gives us a total
/// of all available records which correlates with the given search criteria.
/// </summary>
public long? TotalNumberOfEstablishments { get; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does TotalNumberOfEstablishments belong here? I thought this class was here to give us a readonly list of establishments. The encapsulating class SearchResults pulls all the elements of the search response together, so it might sit there better? And that would remove the need to pass that long into the mapper, which is what I object to most :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Change made.

@@ -29,6 +29,22 @@ public void Build_WithSize_SearchOptionsWithCorrectSize()
searchOptions.Size.Should().Be(100);
}

[Fact]
public void Build_WithOfset_SearchOptionsWithCorrectOffset()
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo ofset

Copy link
Collaborator

Choose a reason for hiding this comment

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

Change made.

@spanersoraferty spanersoraferty merged commit 89ac543 into main Nov 6, 2024
2 checks passed
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.

5 participants