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 /// Applies this [`InputPlugin`] to a user query input, passing along a `Vec` of input
29 /// queries as a result which will replace the input.
30 ///
31 /// # Arguments
32 ///
33 /// * `input` - the user query input passed to this plugin
34 /// * `search_app` - a reference to the search app with all loaded assets
35 ///
36 /// # Returns
37 ///
38 /// A `Vec` of JSON values to replace the input JSON, or an error
39 fn process(
40 &self,
41 input: &mut serde_json::Value,
42 search_app: Arc<SearchApp>,
43 ) -> Result<(), InputPluginError>;
44}