Struct SuggestStore

Source
pub struct SuggestStore { /* private fields */ }
Expand description

The store is the entry point to the Suggest component. It incrementally downloads suggestions from the Remote Settings service, stores them in a local database, and returns them in response to user queries.

Your application should create a single store, and manage it as a singleton. The store is thread-safe, and supports concurrent queries and ingests. We expect that your application will call SuggestStore::query() to show suggestions as the user types into the address bar, and periodically call SuggestStore::ingest() in the background to update the database with new suggestions from Remote Settings.

For responsiveness, we recommend always calling query() on a worker thread. When the user types new input into the address bar, call SuggestStore::interrupt() on the main thread to cancel the query for the old input, and unblock the worker thread for the new query.

The store keeps track of the state needed to support incremental ingestion, but doesn’t schedule the ingestion work itself, or decide how many suggestions to ingest at once. This is for two reasons:

  1. The primitives for scheduling background work vary between platforms, and aren’t available to the lower-level Rust layer. You might use an idle timer on Desktop, WorkManager on Android, or BGTaskScheduler on iOS.
  2. Ingestion constraints can change, depending on the platform and the needs of your application. A mobile device on a metered connection might want to request a small subset of the Suggest data and download the rest later, while a desktop on a fast link might download the entire dataset on the first launch.

Implementations§

Source§

impl SuggestStore

Source

pub fn new( path: &str, remote_settings_service: Arc<RemoteSettingsService>, ) -> Self

Creates a Suggest store.

Source

pub fn query(&self, query: SuggestionQuery) -> SuggestApiResult<Vec<Suggestion>>

Queries the database for suggestions.

Source

pub fn query_with_metrics( &self, query: SuggestionQuery, ) -> SuggestApiResult<QueryWithMetricsResult>

Queries the database for suggestions.

Source

pub fn dismiss_by_suggestion( &self, suggestion: &Suggestion, ) -> SuggestApiResult<()>

Dismiss a suggestion.

Dismissed suggestions cannot be fetched again.

Source

pub fn dismiss_by_key(&self, key: &str) -> SuggestApiResult<()>

Dismiss a suggestion by its dismissal key.

Dismissed suggestions cannot be fetched again.

Prefer SuggestStore::dismiss_by_suggestion if you have a crate::Suggestion. This method is intended for cases where a suggestion originates outside this component.

Source

pub fn dismiss_suggestion(&self, suggestion_url: String) -> SuggestApiResult<()>

Deprecated, use SuggestStore::dismiss_by_suggestion or SuggestStore::dismiss_by_key instead.

Dismiss a suggestion

Dismissed suggestions will not be returned again

Source

pub fn clear_dismissed_suggestions(&self) -> SuggestApiResult<()>

Clear dismissed suggestions

Source

pub fn is_dismissed_by_suggestion( &self, suggestion: &Suggestion, ) -> SuggestApiResult<bool>

Return whether a suggestion has been dismissed.

SuggestStore::query will never return dismissed suggestions, so normally you never need to know whether a Suggestion has been dismissed, but this method can be used to do so.

Source

pub fn is_dismissed_by_key(&self, key: &str) -> SuggestApiResult<bool>

Return whether a suggestion has been dismissed given its dismissal key.

SuggestStore::query will never return dismissed suggestions, so normally you never need to know whether a suggestion has been dismissed. This method is intended for cases where a dismissal key originates outside this component.

Source

pub fn any_dismissed_suggestions(&self) -> SuggestApiResult<bool>

Return whether any suggestions have been dismissed.

Source

pub fn interrupt(&self, kind: Option<InterruptKind>)

Interrupts any ongoing queries.

This should be called when the user types new input into the address bar, to ensure that they see fresh suggestions as they type. This method does not interrupt any ongoing ingests.

Source

pub fn ingest( &self, constraints: SuggestIngestionConstraints, ) -> SuggestApiResult<SuggestIngestionMetrics>

Ingests new suggestions from Remote Settings.

Source

pub fn clear(&self) -> SuggestApiResult<()>

Removes all content from the database.

Source

pub fn fetch_global_config(&self) -> SuggestApiResult<SuggestGlobalConfig>

Returns global Suggest configuration data.

Source

pub fn fetch_provider_config( &self, provider: SuggestionProvider, ) -> SuggestApiResult<Option<SuggestProviderConfig>>

Returns per-provider Suggest configuration data.

Source

pub fn fetch_geonames( &self, query: &str, match_name_prefix: bool, filter: Option<Vec<Geoname>>, ) -> SuggestApiResult<Vec<GeonameMatch>>

Fetches geonames stored in the database. A geoname represents a geographic place.

See fetch_geonames in geoname.rs for documentation.

Source

pub fn fetch_geoname_alternates( &self, geoname: &Geoname, ) -> SuggestApiResult<GeonameAlternates>

Fetches a geoname’s names stored in the database.

See fetch_geoname_alternates in geoname.rs for documentation.

Source§

impl SuggestStore

Source

pub fn force_reingest(&self)

Source§

impl SuggestStore

Source

pub fn checkpoint(&self)

Creates a WAL checkpoint. This will cause changes in the write-ahead log to be written to the DB. See: https://sqlite.org/pragma.html#pragma_wal_checkpoint

Trait Implementations§

Source§

impl<UT> LiftRef<UT> for SuggestStore

Source§

impl<UT> LowerError<UT> for SuggestStore

Source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
Source§

impl<UT> LowerReturn<UT> for SuggestStore

Source§

type ReturnType = <Arc<SuggestStore> as LowerReturn<UniFfiTag>>::ReturnType

The type that should be returned by scaffolding functions for this type. Read more
Source§

fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
Source§

impl<UT> TypeId<UT> for SuggestStore

Source§

const TYPE_ID_META: MetadataBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T