Table of Contents

Property SearchAfter

Namespace
TantivyDotNet
Assembly
TantivyDotNet.dll

SearchAfter

Returns only hits that come after the hit whose Cursor this is, for deep paging: unlike Offset, the cost doesn't grow with the page number. Null (the default) starts from the first hit.

public string? SearchAfter { get; init; }

Property Value

string

Examples

var options = new SearchOptions { Limit = 100, OrderBy = [SortBy.Field("date", descending: true)] };
for (var page = searcher.Search(query, options); page.Count > 0;
     page = searcher.Search(query, new SearchOptions { Limit = 100, OrderBy = options.OrderBy, SearchAfter = page[^1].Cursor }))
{
    // ...
}

Remarks

The cursor must come from a search with the same OrderBy, and Offset must be 0. TotalCount still counts all matches.

A cursor stays valid after commits and merges, so the pages of one listing can come from different searchers, for example from a SearcherManager that refreshes between two requests. On the searcher that returned it, paging is exact. On a newer one, it continues with the documents of the new snapshot that sort after the cursor's sort values:

  • Documents committed meanwhile appear on a later page if they sort after the cursor, and are never seen if they sort before it. Deleted documents disappear.
  • A document whose sort value changed (for example through UpdateDocument(TermQuery, string)) can be returned twice or not at all.
  • Documents tied with the cursor on every sort key are skipped, because the cursor can't tell them apart in another snapshot. Make the last key unique, such as an id stored as a fast field, to avoid this: OrderBy = [SortBy.Field("date", descending: true), SortBy.Field("id")].
  • Relevance scores can change with the index (they depend on how common each term is), so paging by Score() across snapshots is approximate.

To page through one fixed snapshot instead, keep the same Searcher (or SearcherLease) for the whole listing.