SuggestStore
open class SuggestStore:
SuggestStoreProtocol
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.
-
Declaration
Swift
required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer)
-
Creates a Suggest store.
Declaration
Swift
public convenience init(path: String, settingsConfig: RemoteSettingsConfig? = nil) throws
-
Removes all content from the database.
Declaration
Swift
open func clear() throws
-
Clear dismissed suggestions
Declaration
Swift
open func clearDismissedSuggestions() throws
-
Dismiss a suggestion
Dismissed suggestions will not be returned again
In the case of AMP suggestions this should be the raw URL.
Declaration
Swift
open func dismissSuggestion(suggestionUrl: String) throws
-
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. Whentrue
, names that start withquery
will match. When false, names that equalquery
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 infilter
, and regions can be restricted to those containing certain cities by including the cities infilter
. This is especially useful since city and region names are not unique.filter
is disjunctive: If any item infilter
matches a geoname, the geoname will be filtered in.The query can match a geoname in more than one way, for example both a full name and an abbreviation. The returned vec of [
GeonameMatch
] values will include all matches for a geoname, one match per geoname.Declaration
Swift
open func fetchGeonames(query: String, matchNamePrefix: Bool, geonameType: GeonameType?, filter: [Geoname]?) throws -> [GeonameMatch]
-
Returns global Suggest configuration data.
Declaration
Swift
open func fetchGlobalConfig() throws -> SuggestGlobalConfig
-
Returns per-provider Suggest configuration data.
Declaration
Swift
open func fetchProviderConfig(provider: SuggestionProvider) throws -> SuggestProviderConfig?
-
Ingests new suggestions from Remote Settings.
Declaration
Swift
open func ingest(constraints: SuggestIngestionConstraints) throws -> SuggestIngestionMetrics
-
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.
Declaration
Swift
open func interrupt(kind: InterruptKind? = nil)
-
Queries the database for suggestions.
Declaration
Swift
open func query(query: SuggestionQuery) throws -> [Suggestion]
-
Queries the database for suggestions.
Declaration
Swift
open func queryWithMetrics(query: SuggestionQuery) throws -> QueryWithMetricsResult