Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
search.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/list_text.hpp>
6#include <portals/model.hpp>
7
8#include <tuple>
9
10namespace portals {
23
28
31 std::size_t maxSourceRows{100000};
32 std::size_t maxProjectedBytes{33554432};
33 std::size_t maxRowBytes{4096};
34 std::size_t maxRowGraphemes{1024};
35 std::size_t maxQueryBytes{4096};
36 std::size_t maxQueryGraphemes{64};
37 std::size_t maxTermsPerRow{64};
38 std::size_t maxIndexBytes{268435456};
39 std::size_t maxBuildScratchBytes{268435456};
40 std::size_t topK{32};
41 std::size_t maxHighlightRangesPerItem{64};
42 std::size_t maxQuerySteps{2000000};
43 std::size_t maxQueryScratchBytes{8388608};
45};
46
49 std::size_t begin{};
50 std::size_t end{};
52 bool operator==(const SearchHighlight &) const noexcept = default;
53};
54
56struct SearchRank {
57 std::uint8_t edits{};
58 bool token{};
59 std::size_t unmatched{};
60 std::uint64_t sourceOrdinal{};
62
64 auto tuple() const noexcept {
65 return std::tie(edits, token, unmatched, sourceOrdinal, row.value, row.generation);
66 }
67};
68
70struct SearchItem {
71 SearchItem() = default;
72 SearchItem(const SearchItem &) = default;
74 SearchItem &operator=(const SearchItem &) = default;
75
80 SearchItem(SearchItem &&other) : presentation(std::move(other.presentation)), highlights(0), rank(other.rank) {
81 highlights.swap(other.highlights);
82 }
83
88 SearchItem &operator=(SearchItem &&other) noexcept {
89 presentation = std::move(other.presentation);
90 highlights.swap(other.highlights);
91 rank = other.rank;
92 return *this;
93 }
94
95 std::shared_ptr<const detail::PreparedListText> presentation;
96 std::vector<SearchHighlight> highlights = std::vector<SearchHighlight>(0);
98
100 const GraphemeText &text() const noexcept {
101 return presentation->text;
102 }
103};
104
107 std::weak_ptr<const void> owner;
108 const void *pin{};
109 std::uint64_t revision{};
110 std::uint64_t session{};
111 std::uint64_t normalizationVersion{1};
113
117 bool operator==(const SearchSourceIdentity &other) const noexcept {
118 return !owner.owner_before(other.owner) && !other.owner.owner_before(owner) && pin == other.pin &&
119 revision == other.revision && session == other.session &&
120 normalizationVersion == other.normalizationVersion && width == other.width;
121 }
122};
123
127 std::string query = std::string(0, '\0');
128 std::uint64_t generation{};
129 std::vector<ModelRow<SearchItem>> rows = std::vector<ModelRow<SearchItem>>(0);
130 bool hasMore{};
131 std::size_t querySteps{};
132};
133} // namespace portals
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Public Portals API.
Definition action.hpp:8
SearchError
Search/provider errors, separate from scheduler and UI delivery errors.
Definition search.hpp:12
SearchStrategy
Indexed term-prefix strategy; fuzzy edit distance is over normalized graphemes.
Definition search.hpp:24
@ FUZZY_PREFIX
Also allow one insertion/deletion/substitution from three query graphemes.
Definition search.hpp:26
@ PREFIX
Exact normalized prefix of the complete label or a whitespace token.
Definition search.hpp:25
@ NOT_READY
Immutable provider range is pending or failed; no I/O was started.
Definition find_bar.hpp:54
@ INVALID_TEXT
Projected row is not admitted UTF-8 under the scene text policy.
Definition find_bar.hpp:53
@ CALLBACK_FAILED
A non-allocation exception escaped into a runner callback boundary.
Definition application.hpp:34
@ NO_MEMORY
Allocation failed at a runner exception boundary.
Definition application.hpp:33
@ CANCELLED
Explicit cancellation or replacement stopped the invocation.
Definition async.hpp:29
@ INVALID_ARGUMENT
Empty task, callback or immutable data owner, or invalid policy.
Definition async.hpp:26
@ UNAVAILABLE
A hosted session requires a borrowed executor.
Definition background_options.hpp:13
@ LIMIT_EXCEEDED
A storage request cannot fit its configured aggregate budget.
Definition background_options.hpp:19
@ STALE_SOURCE
Result does not have the exact requested source revision.
Definition model_query.hpp:16
Provider-assigned row identity, independent of position; increment generation on reuse.
Definition row_id.hpp:9
Half-open byte range in the original label, always on complete grapheme boundaries.
Definition search.hpp:48
std::size_t begin
Inclusive original UTF-8 byte offset.
Definition search.hpp:49
std::size_t end
Exclusive original UTF-8 byte offset.
Definition search.hpp:50
bool operator==(const SearchHighlight &) const noexcept=default
SearchRank rank
Exact deterministic provider rank.
Definition search.hpp:97
SearchItem()=default
Construct an empty item inside a checked allocation boundary.
std::vector< SearchHighlight > highlights
Whole original grapheme ranges.
Definition search.hpp:96
const GraphemeText & text() const noexcept
Definition search.hpp:100
SearchItem & operator=(SearchItem &&other) noexcept
Transfer bounded output without allocating another container proxy.
Definition search.hpp:88
std::shared_ptr< const detail::PreparedListText > presentation
Bounded prevalidated worker display.
Definition search.hpp:95
SearchItem(const SearchItem &)=default
Copy only bounded presentation and highlight data.
SearchItem(SearchItem &&other)
Transfer output through a potentially throwing empty-container construction. MSVC checked iterators a...
Definition search.hpp:80
SearchItem & operator=(const SearchItem &)=default
Configurable finite source, index, query and result budgets.
Definition search.hpp:30
std::size_t maxQueryScratchBytes
Query frontier/DP/dedup allocation-capacity ceiling.
Definition search.hpp:43
std::size_t maxRowGraphemes
Maximum source graphemes per label.
Definition search.hpp:34
std::size_t maxIndexBytes
Resident/transient resident allocation-capacity ceiling.
Definition search.hpp:38
std::size_t maxProjectedBytes
Maximum original projected UTF-8 bytes per index.
Definition search.hpp:32
std::size_t maxHighlightRangesPerItem
Maximum merged whole-grapheme highlight ranges.
Definition search.hpp:41
SearchStrategy strategy
Prefix or one-edit prefix matching.
Definition search.hpp:44
std::size_t maxQueryGraphemes
Maximum normalized query graphemes.
Definition search.hpp:36
std::size_t maxRowBytes
Maximum bytes in one suggestion label.
Definition search.hpp:33
std::size_t maxQuerySteps
Grapheme DP cells, heap pushes/pops and postings examined.
Definition search.hpp:42
std::size_t maxTermsPerRow
Complete label plus nonempty whitespace tokens.
Definition search.hpp:37
std::size_t maxSourceRows
Maximum immutable source rows.
Definition search.hpp:31
std::size_t maxBuildScratchBytes
Independent build scratch ceiling.
Definition search.hpp:39
std::size_t maxQueryBytes
Maximum owning query bytes, independently editor-limited.
Definition search.hpp:35
std::size_t topK
Exact output count bound, configurable from one to256.
Definition search.hpp:40
Deterministic rank. Smaller tuple sorts first; source ordinal resolves equal scores.
Definition search.hpp:56
std::uint64_t sourceOrdinal
Stable order in this exact source pin.
Definition search.hpp:60
std::uint8_t edits
Zero or one normalized-grapheme edit.
Definition search.hpp:57
RowId row
Final tie break includes row generation.
Definition search.hpp:61
auto tuple() const noexcept
Definition search.hpp:64
std::size_t unmatched
Remaining normalized term graphemes.
Definition search.hpp:59
bool token
Full-label terms precede token-only matches.
Definition search.hpp:58
Immutable bounded search value, distinct from QueryPage<T> and source row count.
Definition search.hpp:125
SearchSourceIdentity source
Exact weak source identity; does not own the index.
Definition search.hpp:126
bool hasMore
One further distinct result was proven.
Definition search.hpp:130
std::vector< ModelRow< SearchItem > > rows
Ranked deduplicated top-K.
Definition search.hpp:129
std::string query
Owning original query bytes.
Definition search.hpp:127
std::size_t querySteps
Counted worker query work, independent of UI/frame time.
Definition search.hpp:131
std::uint64_t generation
Latest UI query intent, not a source/result revision.
Definition search.hpp:128
Exact source identity independent of a result model's publication revision.
Definition search.hpp:106
std::uint64_t session
Provider/projection instance; nonzero and never recycled.
Definition search.hpp:110
std::uint64_t normalizationVersion
Canonical-compose/full-casefold mapping algorithm version.
Definition search.hpp:111
WidthPolicy width
Complete text measurement policy.
Definition search.hpp:112
bool operator==(const SearchSourceIdentity &other) const noexcept
Definition search.hpp:117
const void * pin
Exact source snapshot address, compared together with owner identity.
Definition search.hpp:108
std::uint64_t revision
Domain source revision.
Definition search.hpp:109
std::weak_ptr< const void > owner
Control-block identity without retaining arbitrary source payload.
Definition search.hpp:107
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42