Skip to main content

SearchProvider

Trait SearchProvider 

pub trait SearchProvider {
    // Required methods
    fn name(&self) -> &str;
    fn search(&self, query: &str) -> Vec<SearchResult>;

    // Provided methods
    fn action_directory_generation(&self) -> Option<u64> { ... }
    fn action_directory_invocation_domain(
        &self,
    ) -> ActionDirectoryInvocationDomain { ... }
    fn action_directory_cursor_is_current(&self, _cursor: &SearchCursor) -> bool { ... }
    fn search_limited(&self, query: &str, limit: usize) -> Vec<SearchResult> { ... }
    fn search_page(
        &self,
        query: &SearchQuery,
        cursor: Option<&SearchCursor>,
        work_budget: usize,
        result_limit: usize,
    ) -> SearchPage { ... }
    fn poll_page(&self, _token: &PendingToken) -> PagePoll { ... }
    fn facets(&self) -> Vec<Facet> { ... }
    fn search_scopes(&self) -> Vec<ScopeDecl> { ... }
    fn resolve_action_resource(
        &self,
        _address: &ActionAddress,
    ) -> Option<Resource> { ... }
}
Expand description

A source of search results — implemented by an app for each searchable type it exposes (its contacts, its open files, its commands, …).

A provider filters to plausible matches; the SearchRegistry ranks across providers by relevance. Return everything you consider a match (a contact whose phone number matches even though the title is a name, say) — the registry floats the strongest title matches without discarding your field-aware hits.

Required Methods§

fn name(&self) -> &str

The kind label this provider produces, used for diagnostics and as the default group header. Individual results may still carry a different SearchResult::kind.

fn search(&self, query: &str) -> Vec<SearchResult>

Return the matching results for query. An empty query conventionally returns a provider’s “browse” set (recents / favourites / all), or an empty vec if browsing makes no sense for the source.

Provided Methods§

fn action_directory_generation(&self) -> Option<u64>

Monotonic retained-index generation for the broker pull directory. None means the provider has not proved that a continuation cursor is safe across mutation, so remote directory discovery must omit it rather than silently advertise mutable rows as revision-stable. Providers backed by SearchCatalog should return Some(catalog.stats().generation).

fn action_directory_invocation_domain(&self) -> ActionDirectoryInvocationDomain

Versions this actual provider’s complete lazy invocation domain, including hidden targets and argument/handler semantics omitted from search rows.

fn action_directory_cursor_is_current(&self, _cursor: &SearchCursor) -> bool

Validate a continuation token before it is used by a remote pull directory. The conservative default refuses it: only providers that expose a retained generation may claim continuation safety.

fn search_limited(&self, query: &str, limit: usize) -> Vec<SearchResult>

Query with a materialisation budget. App providers must override this and stop constructing hits once limit is reached. The fallback exists only for tiny/test providers outside apps/; the repository contract checker rejects app implementations that inherit it.

fn search_page( &self, query: &SearchQuery, cursor: Option<&SearchCursor>, work_budget: usize, result_limit: usize, ) -> SearchPage

Return one bounded continuation page for an interactive search.

query carries the free text, the facet filters the platform parsed out of it or the user picked as chips, and the resource scope the search is narrowed to. A provider that cannot apply a filter or the scope ignores it; the palette still drops hits outside the scope.

Providers backed by a durable namespace should override this method so callers can eventually reach every exact match without scanning the whole corpus on the UI thread. Tiny providers remain a single page: a non-empty cursor therefore means they are exhausted.

A provider whose source answers slowly (a mail server, a web service) returns what it has now with SearchPage::pending and answers the rest from poll_page. It never blocks here.

fn poll_page(&self, _token: &PendingToken) -> PagePoll

The page a SearchPage::pending token stands for, once its source has answered. Called on later frames, never in a loop; return PagePoll::Pending until the answer is in. A token the provider no longer knows (the query moved on) answers an empty ready page.

fn facets(&self) -> Vec<Facet>

The dimensions this provider filters by. The palette offers their values as chips and parses typed key:value tokens for them into SearchQuery::filters.

fn search_scopes(&self) -> Vec<ScopeDecl>

The parts of the app this provider’s hits can be narrowed to (see ScopeDecl). An unscoped palette offers each as a “Search in” row that narrows the search to it.

fn resolve_action_resource(&self, _address: &ActionAddress) -> Option<Resource>

Lazily resolve a canonical search address that is intentionally absent from the small open-resource snapshot.

Implementors§