Build the `GRAPH ALGO PAGERANK …` DSL statement. Emits optional `ITERATIONS`, `DAMPING`, and `PERSONALIZATION {…}` clauses. The personalization map is serialized as a JSON `node_id → weight` object literal, which the server tokenizer captures as a single object token.
(
collection: &str,
personalization: Option<&HashMap<String, f64>>,
damping: Option<f64>,
max_iterations: Option<u32>,
)
| 19 | /// The personalization map is serialized as a JSON `node_id → weight` object |
| 20 | /// literal, which the server tokenizer captures as a single object token. |
| 21 | pub(crate) fn build_pagerank_sql( |
| 22 | collection: &str, |
| 23 | personalization: Option<&HashMap<String, f64>>, |
| 24 | damping: Option<f64>, |
| 25 | max_iterations: Option<u32>, |
| 26 | ) -> NodeDbResult<String> { |
| 27 | let mut sql = format!( |
| 28 | "GRAPH ALGO PAGERANK ON {}", |
| 29 | quote_string_literal(collection) |
| 30 | ); |
| 31 | if let Some(iters) = max_iterations { |
| 32 | sql.push_str(&format!(" ITERATIONS {iters}")); |
| 33 | } |
| 34 | if let Some(d) = damping { |
| 35 | sql.push_str(&format!(" DAMPING {d}")); |
| 36 | } |
| 37 | if let Some(p) = personalization.filter(|p| !p.is_empty()) { |
| 38 | let json = sonic_rs::to_string(p) |
| 39 | .map_err(|e| NodeDbError::storage(format!("personalization serialization: {e}")))?; |
| 40 | sql.push_str(&format!(" PERSONALIZATION {json}")); |
| 41 | } |
| 42 | Ok(sql) |
| 43 | } |
| 44 | |
| 45 | /// Parse a `(columns, rows)` PageRank result into `(node_id, rank)` pairs. |
| 46 | /// |