feat(service): Add isolate_with plugin query config
This query parameter will isolate search results when the specific regex query is matched.
This commit is contained in:
parent
c330552c20
commit
e7e6007e26
4 changed files with 26 additions and 0 deletions
|
|
@ -211,9 +211,16 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
|
|||
|
||||
let init = std::sync::Arc::new(init);
|
||||
|
||||
let isolate_with = config
|
||||
.query
|
||||
.isolate_with
|
||||
.as_ref()
|
||||
.and_then(|expr| Regex::new(&*expr).ok());
|
||||
|
||||
entry.insert(PluginConnector::new(
|
||||
config,
|
||||
regex,
|
||||
isolate_with,
|
||||
Box::new(move || {
|
||||
let (request_tx, request_rx) = mpsc::channel(8);
|
||||
|
||||
|
|
@ -359,6 +366,13 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
|
|||
break;
|
||||
}
|
||||
|
||||
if let Some(regex) = plugin.isolate_regex.as_ref() {
|
||||
if regex.is_match(query) {
|
||||
isolated = Some(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
query_queue.push(key);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,13 @@ pub struct PluginQuery {
|
|||
#[serde(default)]
|
||||
pub isolate: bool,
|
||||
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::unwrap_or_skip"
|
||||
)]
|
||||
pub isolate_with: Option<Cow<'static, str>>,
|
||||
|
||||
#[serde(default)]
|
||||
pub no_sort: bool,
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub const CONFIG: PluginConfig = PluginConfig {
|
|||
query: PluginQuery {
|
||||
help: None,
|
||||
isolate: true,
|
||||
isolate_with: None,
|
||||
no_sort: true,
|
||||
persistent: false,
|
||||
priority: PluginPriority::Default,
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ pub struct PluginConnector {
|
|||
/// this plugin to spawn as a background service
|
||||
pub init: Box<dyn Fn() -> Sender<Request>>,
|
||||
|
||||
pub isolate_regex: Option<Regex>,
|
||||
|
||||
/// A compiled regular expression that a query must match
|
||||
/// for the launcher service to justify spawning and sending
|
||||
/// queries to this plugin
|
||||
|
|
@ -93,11 +95,13 @@ impl PluginConnector {
|
|||
pub fn new(
|
||||
config: PluginConfig,
|
||||
regex: Option<Regex>,
|
||||
isolate_regex: Option<Regex>,
|
||||
init: Box<dyn Fn() -> Sender<Request> + Send>,
|
||||
) -> Self {
|
||||
Self {
|
||||
config,
|
||||
init,
|
||||
isolate_regex,
|
||||
regex,
|
||||
sender: None,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue