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:
- 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, orBGTaskScheduler
on iOS. - 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
impl SuggestStore
sourcepub fn new(
path: &str,
settings_config: Option<RemoteSettingsConfig>,
) -> SuggestApiResult<Self>
pub fn new( path: &str, settings_config: Option<RemoteSettingsConfig>, ) -> SuggestApiResult<Self>
Creates a Suggest store.
sourcepub fn query(&self, query: SuggestionQuery) -> SuggestApiResult<Vec<Suggestion>>
pub fn query(&self, query: SuggestionQuery) -> SuggestApiResult<Vec<Suggestion>>
Queries the database for suggestions.
sourcepub fn query_with_metrics(
&self,
query: SuggestionQuery,
) -> SuggestApiResult<QueryWithMetricsResult>
pub fn query_with_metrics( &self, query: SuggestionQuery, ) -> SuggestApiResult<QueryWithMetricsResult>
Queries the database for suggestions.
sourcepub fn dismiss_suggestion(&self, suggestion_url: String) -> SuggestApiResult<()>
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.
sourcepub fn clear_dismissed_suggestions(&self) -> SuggestApiResult<()>
pub fn clear_dismissed_suggestions(&self) -> SuggestApiResult<()>
Clear dismissed suggestions
sourcepub fn interrupt(&self, kind: Option<InterruptKind>)
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.
sourcepub fn ingest(
&self,
constraints: SuggestIngestionConstraints,
) -> SuggestApiResult<SuggestIngestionMetrics>
pub fn ingest( &self, constraints: SuggestIngestionConstraints, ) -> SuggestApiResult<SuggestIngestionMetrics>
Ingests new suggestions from Remote Settings.
sourcepub fn clear(&self) -> SuggestApiResult<()>
pub fn clear(&self) -> SuggestApiResult<()>
Removes all content from the database.
sourcepub fn fetch_global_config(&self) -> SuggestApiResult<SuggestGlobalConfig>
pub fn fetch_global_config(&self) -> SuggestApiResult<SuggestGlobalConfig>
Returns global Suggest configuration data.
sourcepub fn fetch_provider_config(
&self,
provider: SuggestionProvider,
) -> SuggestApiResult<Option<SuggestProviderConfig>>
pub fn fetch_provider_config( &self, provider: SuggestionProvider, ) -> SuggestApiResult<Option<SuggestProviderConfig>>
Returns per-provider Suggest configuration data.
sourcepub fn fetch_geonames(
&self,
query: &str,
match_name_prefix: bool,
geoname_type: Option<GeonameType>,
filter: Option<Vec<Geoname>>,
) -> SuggestApiResult<Vec<GeonameMatch>>
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
impl SuggestStore
pub fn force_reingest(&self)
source§impl SuggestStore
impl SuggestStore
sourcepub fn checkpoint(&self)
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
impl<UT> LiftRef<UT> for SuggestStore
type LiftType = Arc<SuggestStore>
source§impl<UT> LowerError<UT> for SuggestStore
impl<UT> LowerError<UT> for SuggestStore
source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
source§impl<UT> LowerReturn<UT> for SuggestStore
impl<UT> LowerReturn<UT> for SuggestStore
source§type ReturnType = <Arc<SuggestStore> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<SuggestStore> as LowerReturn<UniFfiTag>>::ReturnType
source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
source§impl<UT> TypeId<UT> for SuggestStore
impl<UT> TypeId<UT> for SuggestStore
const TYPE_ID_META: MetadataBuffer = _
Auto Trait Implementations§
impl !Freeze for SuggestStore
impl !RefUnwindSafe for SuggestStore
impl Send for SuggestStore
impl Sync for SuggestStore
impl Unpin for SuggestStore
impl !UnwindSafe for SuggestStore
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Read more