feat(service): Plugins may define a priority for their results
Adds an additional parameter for prioritizing the search results from a specific plugin. The plugin may define a priority which will sort results after the initial pattern search. The web plugin will be the first plugin to utilize this feature
This commit is contained in:
parent
454ce19f08
commit
8987565a2a
4 changed files with 36 additions and 1 deletions
|
|
@ -454,6 +454,24 @@ impl<O: Write> Service<O> {
|
||||||
other => other,
|
other => other,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
active_search.sort_by(|a, b| {
|
||||||
|
let plug1 = match plugins.get(a.0) {
|
||||||
|
Some(plug) => plug,
|
||||||
|
None => return Ordering::Greater,
|
||||||
|
};
|
||||||
|
|
||||||
|
let plug2 = match plugins.get(b.0) {
|
||||||
|
Some(plug) => plug,
|
||||||
|
None => return Ordering::Less,
|
||||||
|
};
|
||||||
|
|
||||||
|
plug1
|
||||||
|
.config
|
||||||
|
.query
|
||||||
|
.priority
|
||||||
|
.cmp(&plug2.config.query.priority)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let take = if last_query.starts_with('/') | last_query.starts_with('~') {
|
let take = if last_query.starts_with('/') | last_query.starts_with('~') {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,9 @@ pub struct PluginQuery {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub persistent: bool,
|
pub persistent: bool,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub priority: PluginPriority,
|
||||||
|
|
||||||
#[serde(
|
#[serde(
|
||||||
default,
|
default,
|
||||||
skip_serializing_if = "Option::is_none",
|
skip_serializing_if = "Option::is_none",
|
||||||
|
|
@ -60,6 +63,19 @@ pub struct PluginQuery {
|
||||||
pub regex: Option<Cow<'static, str>>,
|
pub regex: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||||
|
pub enum PluginPriority {
|
||||||
|
High = 0,
|
||||||
|
Default = 1,
|
||||||
|
Low = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PluginPriority {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load(source: &Path, config_path: &Path) -> Option<(PathBuf, PluginConfig, Option<Regex>)> {
|
pub fn load(source: &Path, config_path: &Path) -> Option<(PathBuf, PluginConfig, Option<Regex>)> {
|
||||||
if let Ok(config_bytes) = std::fs::read_to_string(&config_path) {
|
if let Ok(config_bytes) = std::fs::read_to_string(&config_path) {
|
||||||
let config = match ron::from_str::<PluginConfig>(&config_bytes) {
|
let config = match ron::from_str::<PluginConfig>(&config_bytes) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub const CONFIG: PluginConfig = PluginConfig {
|
||||||
isolate: true,
|
isolate: true,
|
||||||
no_sort: true,
|
no_sort: true,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
priority: PluginPriority::Default,
|
||||||
regex: None,
|
regex: None,
|
||||||
},
|
},
|
||||||
icon: Some(IconSource::Name(Cow::Borrowed("system-help-symbolic"))),
|
icon: Some(IconSource::Name(Cow::Borrowed("system-help-symbolic"))),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ mod config;
|
||||||
pub(crate) mod external;
|
pub(crate) mod external;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
|
|
||||||
pub use self::config::{PluginBinary, PluginConfig, PluginQuery};
|
pub use self::config::{PluginBinary, PluginConfig, PluginPriority, PluginQuery};
|
||||||
pub use self::external::ExternalPlugin;
|
pub use self::external::ExternalPlugin;
|
||||||
pub use self::help::HelpPlugin;
|
pub use self::help::HelpPlugin;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue