MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_search_results

Function parse_search_results

nodedb-client/src/native/response_parse.rs:12–37  ·  view source on GitHub ↗

Parse search results from a native response.

(
    resp: &nodedb_types::protocol::NativeResponse,
)

Source from the content-addressed store, hash-verified

10
11/// Parse search results from a native response.
12pub(crate) fn parse_search_results(
13 resp: &nodedb_types::protocol::NativeResponse,
14) -> NodeDbResult<Vec<SearchResult>> {
15 let rows = match &resp.rows {
16 Some(r) => r,
17 None => return Ok(Vec::new()),
18 };
19
20 let mut results = Vec::new();
21 for row in rows {
22 if let Some(text) = row.first().and_then(|v| v.as_str()) {
23 if let Ok(items) = sonic_rs::from_str::<Vec<serde_json::Value>>(text) {
24 for item in items {
25 if let Some(sr) = parse_single_search_result(&item) {
26 results.push(sr);
27 }
28 }
29 } else if let Ok(item) = sonic_rs::from_str::<serde_json::Value>(text)
30 && let Some(sr) = parse_single_search_result(&item)
31 {
32 results.push(sr);
33 }
34 }
35 }
36 Ok(results)
37}
38
39fn parse_single_search_result(v: &serde_json::Value) -> Option<SearchResult> {
40 let id = v.get("id")?.as_str()?.to_string();

Callers 1

vector_search_implMethod · 0.85

Calls 4

firstMethod · 0.80
as_strMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected