routee_compass/plugin/input/input_plugin.rs
1use std::sync::Arc;
2
3use crate::app::search::SearchApp;
4
5use super::InputPluginError;
6
7/// Performs some kind of pre-processing on a user query input. The input JSON is available
8/// to the plugin as a reference. The plugin produces a vector of zero to many JSON objects that will
9/// replace the input JSON.
10///
11/// A simple No-operation [`InputPlugin`] would simply clone the input and place it in a `Vec`.
12///
13/// # Default InputPlugins
14///
15/// The following default set of input plugin builders are found in the [`super::default`] module:
16///
17/// * [debug] - logs the (current) status of each query to the logging system
18/// * [grid search] - duplicates a query based on a list of user-defined values
19/// * [inject] - mechanism to inject values into the queries
20/// * [load balancer] - uses weighting heuristics to balance query loads across threads
21///
22/// [debug]: super::default::debug::debug_builder::DebugInputPluginBuilder
23/// [grid search]: super::default::grid_search::GridSearchBuilder
24/// [inject]: super::default::inject::inject_builder::InjectPluginBuilder
25/// [load balancer]: super::default::load_balancer::builder::LoadBalancerBuilder
26///
27pub trait InputPlugin: Send + Sync {
28 /// unique name for this plugin, used in logging and metrics.
29 fn name(&self) -> &str;
30
31 /// Applies this [`InputPlugin`] to a user query input, passing along a `Vec` of input
32 /// queries as a result which will replace the input.
33 ///
34 /// # Arguments
35 ///
36 /// * `input` - the user query input passed to this plugin
37 /// * `search_app` - a reference to the search app with all loaded assets
38 ///
39 /// # Returns
40 ///
41 /// A `Vec` of JSON values to replace the input JSON, or an error
42 fn process(
43 &self,
44 input: &mut serde_json::Value,
45 search_app: Arc<SearchApp>,
46 ) -> Result<(), InputPluginError>;
47}