Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::DocumentSearchSession Class Reference

Bounded worker cursor for exact, case-sensitive literal search without normalization. Search starts at the real source origin so grapheme boundaries are proven. Query, KMP/scalar maps, scratch and selected results use source->budget(). Sources must be seekable; unsupported streams return UNSUPPORTED explicitly. Operations serialize on this session, but start/advance belong on workers: they may wait for another operation, and advance performs source I/O. No UI reference or callback is retained. Cancellation preserves consistent accepted input; a later advance can resume when the query/request/revision is unchanged. A revision change fails instead of mixing matches from different generations. The byte quantum limits logical source admissions/processing; an underlying provider's cold replay or blocking I/O can still occupy its worker longer. Capacity failures preserve exact budgetDemand; budgetPeak includes retained session/page storage plus the failed operation, excluding source/provider pins and other callers' retained matches. These are capacities, not process RSS. More...

#include <document_search.hpp>

Public Member Functions

 ~DocumentSearchSession ()
 Release retained pages/maps before their accounting owners.
SourceBudgetUsage retainedUsage () const noexcept
std::expected< void, DocumentSearchFailure > start (DocumentSearchDirection direction, std::uint64_t anchorByte=0)
std::expected< DocumentSearchStep, DocumentSearchFailure > advance (std::stop_token stop={})

Static Public Member Functions

static std::expected< std::shared_ptr< DocumentSearchSession >, DocumentSearchFailure > create (std::shared_ptr< ByteDocumentSource > source, std::string_view utf8Query, DocumentDecoderOptions decoderOptions={.hint=DocumentEncoding::UTF8}, DocumentSearchOptions options={})

Detailed Description

Bounded worker cursor for exact, case-sensitive literal search without normalization. Search starts at the real source origin so grapheme boundaries are proven. Query, KMP/scalar maps, scratch and selected results use source->budget(). Sources must be seekable; unsupported streams return UNSUPPORTED explicitly. Operations serialize on this session, but start/advance belong on workers: they may wait for another operation, and advance performs source I/O. No UI reference or callback is retained. Cancellation preserves consistent accepted input; a later advance can resume when the query/request/revision is unchanged. A revision change fails instead of mixing matches from different generations. The byte quantum limits logical source admissions/processing; an underlying provider's cold replay or blocking I/O can still occupy its worker longer. Capacity failures preserve exact budgetDemand; budgetPeak includes retained session/page storage plus the failed operation, excluding source/provider pins and other callers' retained matches. These are capacities, not process RSS.

Member Function Documentation

◆ advance()

std::expected< DocumentSearchStep, DocumentSearchFailure > portals::DocumentSearchSession::advance ( std::stop_token stop = {})
Parameters
stopCooperative cancellation before/after reads and during bounded processing.
Returns
PENDING, FOUND or END with owning progress, or an exact source/decoder/admission cause. NEXT continues after FOUND and includes overlaps. PREVIOUS rescans only the needed prefix, retains the last eligible match, and is terminal after FOUND.

◆ create()

std::expected< std::shared_ptr< DocumentSearchSession >, DocumentSearchFailure > portals::DocumentSearchSession::create ( std::shared_ptr< ByteDocumentSource > source,
std::string_view utf8Query,
DocumentDecoderOptions decoderOptions = {.hint=DocumentEncoding::UTF8},
DocumentSearchOptions options = {} )
static
Parameters
sourceRetained logical byte source with an existing accounting root.
utf8QueryNonempty valid UTF-8 literal; matching never folds case or normalizes.
decoderOptionsOriginal source encoding/error policy; UTF-8 hint is the default.
optionsBounded query, worker and result capacities.
Returns
Cold session with initial NEXT-from-zero request, or typed validation/admission failure. Creation performs no source metadata/read I/O and may run on a worker.

◆ retainedUsage()

SourceBudgetUsage portals::DocumentSearchSession::retainedUsage ( ) const
noexcept
Returns
Retained session/page capacities, excluding independent matches and source/provider pins. Allocation-free and lock-free. The caller must serialize this worker-only observation with start/advance; concurrent UI reads are not supported.

◆ start()

std::expected< void, DocumentSearchFailure > portals::DocumentSearchSession::start ( DocumentSearchDirection direction,
std::uint64_t anchorByte = 0 )
Parameters
directionNEXT or PREVIOUS; wrapping is not performed by the kernel.
anchorByteNEXT accepts starts >= anchor; PREVIOUS accepts starts < anchor.
Returns
Success after resetting a request, or typed validation failure. Both directions restart from the real origin. Consecutive NEXT after FOUND should call advance directly to preserve the streaming overlap/KMP state. A new request also clears the previous revision qualification.

The documentation for this class was generated from the following file: