1use scc_api::QueryRequest;
7
8pub struct QueryHit {
10 pub entities: Vec<scc_core::Entity>,
11 pub symbols: Vec<(String, String, String, String, u32)>,
13}
14
15pub fn query(store: &scc_store::Store, req: &QueryRequest) -> crate::Result<QueryHit> {
17 let limit = req.limit.max(1);
18 let entities = store.search_entities(&req.query, limit)?;
19 let symbols = store.search_symbols(&req.query, limit)?;
20 let (entities, symbols) = if entities.is_empty() && symbols.is_empty() {
21 (
22 store.search_entities_like(&req.query, limit)?,
23 store.search_symbols_like(&req.query, limit)?,
24 )
25 } else {
26 (entities, symbols)
27 };
28 Ok(QueryHit { entities, symbols })
29}
30
31pub fn components(store: &scc_store::Store) -> crate::Result<Vec<scc_core::Entity>> {
33 Ok(store.components()?)
34}
35
36pub fn flows(store: &scc_store::Store) -> crate::Result<Vec<scc_core::Flow>> {
38 Ok(store.flows()?)
39}
40
41pub fn relationships(
43 store: &scc_store::Store,
44 subject: Option<&str>,
45 predicate: Option<&str>,
46 limit: usize,
47) -> crate::Result<Vec<scc_core::Relationship>> {
48 let mut out = if let Some(s) = subject {
49 store.relationships_for(s)?
50 } else {
51 store.all_relationships()?
52 };
53 if let Some(p) = predicate {
54 out.retain(|r| r.predicate == p);
55 }
56 out.truncate(limit.max(1));
57 Ok(out)
58}