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:
Michael Aaron Murphy 2021-08-23 19:54:04 +02:00
parent 454ce19f08
commit 8987565a2a
4 changed files with 36 additions and 1 deletions

View file

@ -454,6 +454,24 @@ impl<O: Write> Service<O> {
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('~') {