diff --git a/js/core/src/init.tsx b/js/core/src/init.tsx index 470d919..70d510f 100644 --- a/js/core/src/init.tsx +++ b/js/core/src/init.tsx @@ -213,7 +213,12 @@ async function runLoop() { break; } case "ReloadSearchIndex": { - await loadSearchIndex(); + try { + await runCommandGenerators(); + await loadSearchIndex(); + } catch (e) { + console.error("Error occurred when reloading search index", e) + } break; } } @@ -221,7 +226,6 @@ async function runLoop() { } await runCommandGenerators(); - await loadSearchIndex(); (async () => { diff --git a/rust/server/src/plugins/js.rs b/rust/server/src/plugins/js.rs index f46dca5..dfc6cbf 100644 --- a/rust/server/src/plugins/js.rs +++ b/rust/server/src/plugins/js.rs @@ -735,6 +735,7 @@ async fn get_command_generator_entrypoint_ids(state: Rc>) -> an let result = repository.get_entrypoints_by_plugin_id(&plugin_id.to_string()).await? .into_iter() + .filter(|entrypoint| entrypoint.enabled) .filter(|entrypoint| matches!(db_entrypoint_from_str(&entrypoint.entrypoint_type), DbPluginEntrypointType::CommandGenerator)) .map(|entrypoint| entrypoint.id) .collect::>(); diff --git a/rust/server/src/plugins/mod.rs b/rust/server/src/plugins/mod.rs index 2347488..8e0c0c5 100644 --- a/rust/server/src/plugins/mod.rs +++ b/rust/server/src/plugins/mod.rs @@ -212,7 +212,9 @@ impl ApplicationManager { } pub async fn remove_plugin(&self, plugin_id: PluginId) -> anyhow::Result<()> { - self.db_repository.remove_plugin(&plugin_id.to_string()).await + self.db_repository.remove_plugin(&plugin_id.to_string()).await?; + self.search_index.remove_for_plugin(plugin_id)?; + Ok(()) } pub fn handle_inline_view(&self, text: &str) { diff --git a/rust/server/src/search.rs b/rust/server/src/search.rs index 9582016..2f01b6f 100644 --- a/rust/server/src/search.rs +++ b/rust/server/src/search.rs @@ -27,10 +27,10 @@ impl SearchIndex { schema_builder.add_text_field("entrypoint_type", STORED); schema_builder.add_text_field("entrypoint_name", TEXT | STORED); - schema_builder.add_text_field("entrypoint_id", STORED); + schema_builder.add_text_field("entrypoint_id", STRING | STORED); schema_builder.add_text_field("entrypoint_icon_path", STORED); schema_builder.add_text_field("plugin_name", TEXT | STORED); - schema_builder.add_text_field("plugin_id", STORED); + schema_builder.add_text_field("plugin_id", STRING | STORED); schema_builder.build() }; @@ -65,7 +65,9 @@ impl SearchIndex { pub fn remove_for_plugin(&self, plugin_id: PluginId) -> tantivy::Result<()> { let mut index_writer = self.index.writer(5_000_000)?; - index_writer.delete_term(Term::from_field_text(self.plugin_id, &plugin_id.to_string())); + index_writer.delete_query(Box::new( + TermQuery::new(Term::from_field_text(self.plugin_id, &plugin_id.to_string()), IndexRecordOption::Basic) + ))?; index_writer.commit()?; Ok(()) @@ -79,7 +81,9 @@ impl SearchIndex { let mut index_writer = self.index.writer(3_000_000)?; - index_writer.delete_term(Term::from_field_text(self.plugin_id, &plugin_id.to_string())); + index_writer.delete_query(Box::new( + TermQuery::new(Term::from_field_text(self.plugin_id, &plugin_id.to_string()), IndexRecordOption::Basic) + ))?; for search_item in search_items { index_writer.add_document(doc!(