suggest

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, settings_config: Option<RemoteSettingsConfig>, ) -> SuggestApiResult<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_suggestion(&self, suggestion_url: String) -> SuggestApiResult<()>

Dismiss a suggestion

Dismissed suggestions will not be returned again

In the case of AMP suggestions this should be the raw URL.

source

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

Clear dismissed suggestions

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, geoname_type: Option<GeonameType>, filter: Option<Vec<Geoname>>, ) -> SuggestApiResult<Vec<GeonameMatch>>

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

query is a string that will be matched directly against geoname names. It is not a query string in the usual Suggest sense. match_name_prefix determines whether prefix matching is performed on names excluding abbreviations and airport codes. When true, names that start with query will match. When false, names that equal query will match.

geoname_type restricts returned geonames to a GeonameType.

filter restricts returned geonames to certain cities or regions. Cities can be restricted to regions by including the regions in filter, and regions can be restricted to those containing certain cities by including the cities in filter. This is especially useful since city and region names are not unique. filter is disjunctive: If any item in filter matches a geoname, the geoname will be filtered in.

The query can match a single geoname in more than one way. For example, it can match both a full name and an abbreviation. The returned vec of GeonameMatch values will include all matches for a geoname, one match per match_type per geoname. In other words, a matched geoname can map to more than one GeonameMatch.

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