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:
Michael Aaron Murphy 2021-10-20 21:39:01 +02:00
parent c330552c20
commit e7e6007e26
4 changed files with 26 additions and 0 deletions

View file

@ -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);
}