fastskill_core/search/
mod.rs1pub mod local;
11pub mod remote;
12
13use serde::Serialize;
14use std::fmt;
15
16#[derive(Debug, Clone, PartialEq)]
18pub enum SearchScope {
19 Local,
21 Remote,
23 RemoteRepo(String),
25}
26
27#[derive(Debug, Clone)]
29pub struct SearchQuery {
30 pub query: String,
32 pub scope: SearchScope,
34 pub limit: usize,
36 pub embedding: Option<bool>,
38}
39
40#[derive(Debug, Clone, Serialize)]
42pub struct SearchResultItem {
43 pub id: String,
45 pub name: String,
47 pub description: Option<String>,
49 pub source: String,
51 pub similarity: Option<f32>,
53 pub path: Option<String>,
55 pub repository: Option<String>,
57}
58
59impl fmt::Display for SearchResultItem {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 write!(
62 f,
63 "{}: {}",
64 self.name,
65 self.description.as_deref().unwrap_or("No description")
66 )
67 }
68}
69
70#[derive(Debug, thiserror::Error)]
72pub enum SearchError {
73 #[error("Configuration error: {0}")]
74 Config(String),
75 #[error("Validation error: {0}")]
76 Validation(String),
77 #[error("Service error: {0}")]
78 Service(#[from] crate::ServiceError),
79 #[error("Repository error: {0}")]
80 Repository(String),
81}
82
83pub async fn execute(
85 query: SearchQuery,
86 service: &crate::FastSkillService,
87) -> Result<Vec<SearchResultItem>, SearchError> {
88 let scope = query.scope.clone();
89 match scope {
90 SearchScope::Local => local::execute_local_search(query, service).await,
91 SearchScope::Remote => remote::execute_remote_search(query, None).await,
92 SearchScope::RemoteRepo(repo_name) => {
93 remote::execute_remote_search(query, Some(repo_name)).await
94 }
95 }
96}