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 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(
|
entry.insert(PluginConnector::new(
|
||||||
config,
|
config,
|
||||||
regex,
|
regex,
|
||||||
|
isolate_with,
|
||||||
Box::new(move || {
|
Box::new(move || {
|
||||||
let (request_tx, request_rx) = mpsc::channel(8);
|
let (request_tx, request_rx) = mpsc::channel(8);
|
||||||
|
|
||||||
|
|
@ -359,6 +366,13 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(regex) = plugin.isolate_regex.as_ref() {
|
||||||
|
if regex.is_match(query) {
|
||||||
|
isolated = Some(key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
query_queue.push(key);
|
query_queue.push(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,13 @@ pub struct PluginQuery {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub isolate: bool,
|
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)]
|
#[serde(default)]
|
||||||
pub no_sort: bool,
|
pub no_sort: bool,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub const CONFIG: PluginConfig = PluginConfig {
|
||||||
query: PluginQuery {
|
query: PluginQuery {
|
||||||
help: None,
|
help: None,
|
||||||
isolate: true,
|
isolate: true,
|
||||||
|
isolate_with: None,
|
||||||
no_sort: true,
|
no_sort: true,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
priority: PluginPriority::Default,
|
priority: PluginPriority::Default,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,8 @@ pub struct PluginConnector {
|
||||||
/// this plugin to spawn as a background service
|
/// this plugin to spawn as a background service
|
||||||
pub init: Box<dyn Fn() -> Sender<Request>>,
|
pub init: Box<dyn Fn() -> Sender<Request>>,
|
||||||
|
|
||||||
|
pub isolate_regex: Option<Regex>,
|
||||||
|
|
||||||
/// A compiled regular expression that a query must match
|
/// A compiled regular expression that a query must match
|
||||||
/// for the launcher service to justify spawning and sending
|
/// for the launcher service to justify spawning and sending
|
||||||
/// queries to this plugin
|
/// queries to this plugin
|
||||||
|
|
@ -93,11 +95,13 @@ impl PluginConnector {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
config: PluginConfig,
|
config: PluginConfig,
|
||||||
regex: Option<Regex>,
|
regex: Option<Regex>,
|
||||||
|
isolate_regex: Option<Regex>,
|
||||||
init: Box<dyn Fn() -> Sender<Request> + Send>,
|
init: Box<dyn Fn() -> Sender<Request> + Send>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
init,
|
init,
|
||||||
|
isolate_regex,
|
||||||
regex,
|
regex,
|
||||||
sender: None,
|
sender: None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue