pub struct RemoteSettingsSuggester {
suggestions: Arc<DedupedMap<String, (), Suggestion>>,
metrics_client: StatsdClient,
resync_task: Option<(JoinHandle<()>, Sender<RemoteSettingsConfig>)>,
}
Expand description
Make suggestions based on data in Remote Settings
Fields
suggestions: Arc<DedupedMap<String, (), Suggestion>>
A map from keywords to suggestions that can be provided.
metrics_client: StatsdClient
The Statsd client used to record statistics.
resync_task: Option<(JoinHandle<()>, Sender<RemoteSettingsConfig>)>
The control handles for the background re-sync task used for reconfiguration.
Implementations
sourceimpl RemoteSettingsSuggester
impl RemoteSettingsSuggester
sourcepub async fn new_boxed(
settings: Settings,
config: RemoteSettingsConfig,
metrics_client: StatsdClient
) -> Result<Box<Self>, SetupError>
pub async fn new_boxed(
settings: Settings,
config: RemoteSettingsConfig,
metrics_client: StatsdClient
) -> Result<Box<Self>, SetupError>
Make and sync a new suggester.
Errors
Returns an error if the settings are invalid for this provider, or if the initial sync fails.
sourceasync fn create_rs_client(
settings: &RemoteSettingsGlobalSettings,
config: &RemoteSettingsConfig
) -> Result<Client, SetupError>
async fn create_rs_client(
settings: &RemoteSettingsGlobalSettings,
config: &RemoteSettingsConfig
) -> Result<Client, SetupError>
Creat a client to Remote Settings.
Error: a SetupError
is returned if the creation fails.
sourcefn parse_suggestion_score(score: f32) -> Result<Proportion, SetupError>
fn parse_suggestion_score(score: f32) -> Result<Proportion, SetupError>
Parses a Proportion
from the configuration source.
Error: a SetupError
is returned if the parsing fails.
sourcefn spawn_resync_task(
cron_interval: Duration,
rs_config: RemoteSettingsConfig,
suggestions: Arc<DedupedMap<String, (), Suggestion>>,
pool: Arc<ConnectionPool>
) -> (JoinHandle<()>, Sender<RemoteSettingsConfig>)
fn spawn_resync_task(
cron_interval: Duration,
rs_config: RemoteSettingsConfig,
suggestions: Arc<DedupedMap<String, (), Suggestion>>,
pool: Arc<ConnectionPool>
) -> (JoinHandle<()>, Sender<RemoteSettingsConfig>)
Spawns a new task for resyncing with Remote Settings. It also exposes a MPSC channel sender to support the provider reconfiguration.
Following tasks are done in this task:
- Resync with Remote Settings if needed. The resync interval is
configured by
rs_config.resync_interval
. - Retry if the regular resync fails.
- Receive the new configurations for provider reconfiguration.
sourcepub async fn sync(
connection_pool: Arc<ConnectionPool>,
suggestions: &DedupedMap<String, (), Suggestion>,
suggestion_score: Proportion
) -> Result<(), SetupError>
pub async fn sync(
connection_pool: Arc<ConnectionPool>,
suggestions: &DedupedMap<String, (), Suggestion>,
suggestion_score: Proportion
) -> Result<(), SetupError>
Download suggestions from Remote Settings
This must be called at least once before any suggestions will be provided
sourcefn get_full_keyword(partial_query: &str, all_keywords: &[String]) -> String
fn get_full_keyword(partial_query: &str, all_keywords: &[String]) -> String
Gets the “full keyword” (the suggested completion) for a query. The data from adM doesn’t include this data directly, so we make our own based on the available keywords.
- Filter out keywords that don’t start with the value of
partial_query
. - Find the first keyword phrase that has more words than the query. Use
its first
query_num_words
words as the full keyword. e.g., if the query is"moz"
andall_keywords
is["moz", "mozi", "mozil", "mozill", "mozilla", "mozilla firefox"]
, pick"mozilla firefox"
, pop off the"firefox"
and use"mozilla"
as the full keyword. - If there isn’t any keyword phrase with more words, then pick the
longest phrase. e.g., pick
"
mozilla“ in the previous example (assuming the"mozilla firefox"
phrase isn’t there). That might be the query itself.
Trait Implementations
sourceimpl SuggestionProvider for RemoteSettingsSuggester
impl SuggestionProvider for RemoteSettingsSuggester
sourcefn reconfigure<'life0, 'life1, 'async_trait>(
&'life0 mut self,
new_config: Value,
_make_fresh: &'life1 MakeFreshType
) -> Pin<Box<dyn Future<Output = Result<(), SetupError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn reconfigure<'life0, 'life1, 'async_trait>(
&'life0 mut self,
new_config: Value,
_make_fresh: &'life1 MakeFreshType
) -> Pin<Box<dyn Future<Output = Result<(), SetupError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Reconfigure the Remote Settings provider.
It only supports reconfiguring the resync_interval
and suggestion_score
now. As updating the other fields on the fly doesn’t seem useful in practice.
Also note that it will not issue a sync to Remote Settings during the reconfiguration for the performance concerns as reconfigurations will prevent Merino from serving incoming requests due to the exclusive lock held on the provider state. Excessive reconfigurations could make Merino completely irresponsive. Until we find a better way to handle that, let’s make these reconfigurations call run as fast as possible.
sourcefn cache_inputs(
&self,
req: &SuggestionRequest,
cache_inputs: &mut dyn CacheInputs
)
fn cache_inputs(
&self,
req: &SuggestionRequest,
cache_inputs: &mut dyn CacheInputs
)
Generate a set of cache inputs for a given query specific to this provider. Any property of the query that affects how suggestions are generated should be included. Read more
sourcefn suggest<'life0, 'async_trait>(
&'life0 self,
request: SuggestionRequest
) -> Pin<Box<dyn Future<Output = Result<SuggestionResponse, SuggestError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn suggest<'life0, 'async_trait>(
&'life0 self,
request: SuggestionRequest
) -> Pin<Box<dyn Future<Output = Result<SuggestionResponse, SuggestError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Provide suggested results for query
.
sourcefn is_null(&self) -> bool
fn is_null(&self) -> bool
Return if this provider is null and can be ignored. Providers that set this to true should be ignored in any place where suggestions are needed. Providers with this set to true likely only serve as a blank space where we may need a provider but can’t otherwise supply one. Read more
sourcefn cache_key(&self, req: &SuggestionRequest) -> String
fn cache_key(&self, req: &SuggestionRequest) -> String
Use Self::cache_inputs
to generate a single cache key. This function
should not normally be overridden by provider implementations. Read more
Auto Trait Implementations
impl !RefUnwindSafe for RemoteSettingsSuggester
impl Send for RemoteSettingsSuggester
impl Sync for RemoteSettingsSuggester
impl Unpin for RemoteSettingsSuggester
impl !UnwindSafe for RemoteSettingsSuggester
Blanket Implementations
sourceimpl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
sourceimpl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more