Skip to content

Commit 0abdacf

Browse files
authored
Merge pull request #912 from multiplex55/codex/implement-source-aggregated-omni-pipeline
Expand omni search to include notes and todos
2 parents 3738e3e + fd3d4cd commit 0abdacf

1 file changed

Lines changed: 64 additions & 5 deletions

File tree

src/plugins/omni_search.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ use crate::actions::Action;
22
use crate::plugin::Plugin;
33
use crate::plugins::bookmarks::BookmarksPlugin;
44
use crate::plugins::folders::FoldersPlugin;
5+
use crate::plugins::note::NotePlugin;
6+
use crate::plugins::todo::TodoPlugin;
57
use fst::{automaton::Subsequence, IntoStreamer, Map, MapBuilder, Streamer};
68
use std::collections::HashSet;
79
use std::sync::Arc;
810

9-
/// Combined search across folders, bookmarks, and launcher actions.
11+
/// Combined search across folders, bookmarks, notes, todos, and launcher
12+
/// actions.
1013
///
1114
/// The action list is provided as an [`Arc<Vec<Action>>`] so the plugin can
1215
/// participate in searches without holding its own copy. Cloning the `Arc`
@@ -15,6 +18,8 @@ use std::sync::Arc;
1518
pub struct OmniSearchPlugin {
1619
folders: FoldersPlugin,
1720
bookmarks: BookmarksPlugin,
21+
note: NotePlugin,
22+
todo: TodoPlugin,
1823
/// Shared list of launcher actions searched alongside folders and
1924
/// bookmarks. Cloning the `Arc` only clones the pointer so the underlying
2025
/// `Vec` remains shared.
@@ -74,6 +79,8 @@ impl OmniSearchPlugin {
7479
Self {
7580
folders: FoldersPlugin::default(),
7681
bookmarks: BookmarksPlugin::default(),
82+
note: NotePlugin::default(),
83+
todo: TodoPlugin::default(),
7784
actions,
7885
index,
7986
}
@@ -100,7 +107,7 @@ impl Plugin for OmniSearchPlugin {
100107
}
101108

102109
fn description(&self) -> &str {
103-
"Combined search for folders, bookmarks and apps (prefix: `o`)"
110+
"Combined search for folders, bookmarks, apps, notes and todos (prefix: `o`)"
104111
}
105112

106113
fn capabilities(&self) -> &[&str] {
@@ -132,12 +139,45 @@ impl Plugin for OmniSearchPlugin {
132139
impl OmniSearchPlugin {
133140
fn search_all(&self, rest: &str) -> Vec<Action> {
134141
let mut out = Vec::new();
135-
out.extend(self.folders.search(&format!("f {rest}")));
142+
out.extend(self.collect_folder_results(rest));
143+
out.extend(self.collect_bookmark_results(rest));
144+
out.extend(self.collect_app_results(rest));
145+
out.extend(self.collect_note_results(rest));
146+
out.extend(self.collect_todo_results(rest));
147+
148+
self.dedup_actions(out)
149+
}
150+
151+
fn collect_folder_results(&self, rest: &str) -> Vec<Action> {
152+
self.folders.search(&format!("f {rest}"))
153+
}
154+
155+
fn collect_bookmark_results(&self, rest: &str) -> Vec<Action> {
156+
if rest.trim().is_empty() {
157+
self.bookmarks.search("bm list")
158+
} else {
159+
self.bookmarks.search(&format!("bm {rest}"))
160+
}
161+
}
162+
163+
fn collect_note_results(&self, rest: &str) -> Vec<Action> {
164+
if rest.trim().is_empty() {
165+
self.note.search("note list")
166+
} else {
167+
self.note.search(&format!("note {rest}"))
168+
}
169+
}
170+
171+
fn collect_todo_results(&self, rest: &str) -> Vec<Action> {
136172
if rest.trim().is_empty() {
137-
out.extend(self.bookmarks.search("bm list"));
173+
self.todo.search("todo list")
138174
} else {
139-
out.extend(self.bookmarks.search(&format!("bm {rest}")));
175+
self.todo.search(&format!("todo {rest}"))
140176
}
177+
}
178+
179+
fn collect_app_results(&self, rest: &str) -> Vec<Action> {
180+
let mut out = Vec::new();
141181
let q = rest.trim();
142182
if q.is_empty() {
143183
out.extend(self.actions.iter().cloned());
@@ -164,6 +204,25 @@ impl OmniSearchPlugin {
164204
}
165205
}
166206
}
207+
208+
out
209+
}
210+
211+
fn dedup_actions(&self, actions: Vec<Action>) -> Vec<Action> {
212+
let mut out = Vec::new();
213+
let mut seen = HashSet::new();
214+
for action in actions {
215+
let normalized_label = action
216+
.label
217+
.split_whitespace()
218+
.collect::<Vec<_>>()
219+
.join(" ")
220+
.to_lowercase();
221+
let dedup_key = format!("{}\x1f{}", action.action, normalized_label);
222+
if seen.insert(dedup_key) {
223+
out.push(action);
224+
}
225+
}
167226
out
168227
}
169228
}

0 commit comments

Comments
 (0)