//! `search_records` — the whole file, on the same engine as the app's Find //! screen. //! //! The RANKING half is //! [`cotton_core::rules::search_everything::search_everything_file`] — the //! same function the phone calls — so the assistant and the owner rank one //! file one way. What lives HERE is everything the engine deliberately does //! not know, because it is MCP vocabulary rather than search: //! //! THE NOTE/JOURNAL SPLIT. The engine folds a journal page into the note //! lane under a flag; both MCP kinds ride that one lane and the flag splits //! them again on the way out. //! //! THE WORDS FOR NAMELESS KINDS. `namelessTitle` is the server's analogue of //! the app's `hitTitle`, in the assistant's register. //! //! THE MEMORY `[slug]` LINE. An assistant cites entries by slug, so a memory //! row that reached one without its handle would be unusable as a reference. //! //! THE MEANING LANE'S ABSENCE. Four shapes, and every one of them is an //! ANSWER rather than a thrown error (spec D19/D20): a tool failure makes an //! assistant retry, and three of the four are settled states. The text lane's //! hits are never withheld because the second lane went dark. use std::collections::HashMap; use cotton_core::rules::search_everything::{ search_everything_file, EverythingHit, EverythingKind, EverythingLanes, EverythingSearchOptions, SearchDriver, SearchError, SearchRow, SemanticQuery, SqlParam, SqlValue as EngineValue, }; use cotton_store::driver::Driver; use cotton_store::protocol::js; use rusqlite::types::Value as SqlValue; use serde_json::{Map, Value}; use crate::mcp::dispatch::{Ctx, ToolResult}; use crate::mcp::handlers::common::{bounded_limit, fail, projects, require_string, Valid}; use crate::mcp::protocol::ToolFailure; // ── the vocabulary ────────────────────────────────────────────────────────── /// `SEARCH_KINDS` — the kinds `search_records` can FIND. /// /// Wider than the `get_record` vocabulary on purpose: a search hit's follow-up /// is not always `get_record` (a message opens with `read_message_thread`, a /// session with `list_sessions`, a goal with `list_goals`, a reader page has no /// expander yet). Held as a slice in the TypeScript's declared order, because /// the refusal sentence prints it and an assistant reads that list to correct /// itself. User-defined table ids use the same shared-format id grammar; /// the catalogue permits that grammar rather than a closed built-in enum. pub const SEARCH_KINDS: &[&str] = &[ "todo", "event", "note", "journal", "person", "document", "memory", "message", "thread", "email", "email_thread", "session", "transaction", "session_message", "photo", "video", "call", // A secret (v6 of the Rust ladder). The lane indexes the PLAIN columns — // name, site, username, service — and never the sealed payload, so a // person typing "gmail" finds their login and nobody finds a password. "secret", // Code hosting (v19). A pull request and an issue answer through their own // FTS index over title and body; a repository and a release through an // indexed LIKE scan over the key/tag and the name. `repo_comment` is // absent and stays absent: a comment is read in the timeline of the thing // it is on, and a workspace-wide index over review chatter would answer // every search with "looks good to me". "repository", "pull", "issue", "release", // A connection by its name, the number or address it reaches, or its // kind — a LIKE scan that reads neither its vault secret nor its config. // Not a record kind: `get_record_by_table` with table `connection` opens it. "connection", // gen-kind: search-kinds ]; /// The two lanes and the pair. pub const SEARCH_MODES: &[&str] = &["text", "meaning", "both"]; // ── the arguments ─────────────────────────────────────────────────────────── #[derive(Debug, Clone)] pub struct SearchArgs { pub query: String, pub kinds: Vec, pub limit: i64, /// Which lanes answer. ALWAYS set — absence defaults to `text`, and that /// is the whole compatibility story: a caller written before the meaning /// lane existed gets what it always got. pub mode: String, } /// `validateSearch`. pub fn validate_search(args: &Map) -> Valid { let Some(query) = require_string(args, "query") else { return fail("query is required"); }; let mut kinds: Vec = SEARCH_KINDS .iter() .map(|kind| (*kind).to_string()) .collect(); if let Some(raw) = args.get("kinds") { let Some(items) = raw.as_array() else { return fail("kinds must be an array"); }; if let Some(bad) = items.iter().find(|item| { !item .as_str() .is_some_and(cotton_core::definitions::is_valid_id) }) { return fail(format!( "invalid kind {}. Use a table id or one of: {}", js::json_stringify(bad), SEARCH_KINDS.join(", ") )); } // An explicit empty array means "search nothing", which is a mistake // the caller cannot have meant — read it as "search everything". if !items.is_empty() { kinds = items .iter() .filter_map(|item| item.as_str().map(str::to_string)) .collect(); } } let mut mode = "text".to_string(); if let Some(raw) = args.get("mode") { if !raw .as_str() .is_some_and(|value| SEARCH_MODES.contains(&value)) { return fail(format!( "unknown mode {}. Allowed: {}", js::json_stringify(raw), SEARCH_MODES.join(", ") )); } mode = raw.as_str().unwrap_or("text").to_string(); } Ok(SearchArgs { query, kinds, limit: bounded_limit(args, 20, 50), mode, }) } // ── the file, as the engine asks for it ───────────────────────────────────── /// The engine's [`SearchDriver`] over the store's own handle. /// /// The bridge the ledger's "the search API" note asks the server to write: no /// `rusqlite` type appears in any engine signature, so the translation lives on /// this side of the seam and nowhere else. /// /// **`pub` because the phone's `/find` read needs the same bridge** and a second /// copy of it in `cotton-ffi` would be a second answer to "how does a store row /// become an engine row" — forty lines of pure type translation, wrong the day /// the store grows a column type. The phone links this crate, so it takes the /// one that exists. `read.find` calls the ENGINE rather than the `search` /// handler because the tool is the assistant's register — it flattens to one /// array, splits journal out of the note lane and appends the memory slug line /// — while the app wants hits grouped per section with totals. pub struct FileSearchDriver<'a>(pub &'a Driver); /// The index this file's mail is searched through: the wide `fts_mail` once /// it is whole, `fts_emails` while it still fills in the background (v122, /// `cotton_store::fts_fill`). Both the phone's Find and `search_records` ask /// it, so the swap happens for both at the same moment. pub fn mail_index_of(db: &Driver) -> cotton_core::rules::search_everything::MailIndex { let filling = cotton_store::fts_fill::filling(db, "fts_mail").map_or(true, |fill| fill.is_some()); cotton_core::rules::search_everything::mail_index(filling) } fn to_engine_value(value: &SqlValue) -> EngineValue { match value { SqlValue::Null => EngineValue::Null, SqlValue::Integer(number) => EngineValue::Integer(*number), SqlValue::Real(number) => EngineValue::Real(*number), SqlValue::Text(text) => EngineValue::Text(text.clone()), SqlValue::Blob(bytes) => EngineValue::Blob(bytes.clone()), } } fn to_sql_value(value: &SqlParam) -> SqlValue { match value { EngineValue::Null => SqlValue::Null, EngineValue::Integer(number) => SqlValue::Integer(*number), EngineValue::Real(number) => SqlValue::Real(*number), EngineValue::Text(text) => SqlValue::Text(text.clone()), EngineValue::Blob(bytes) => SqlValue::Blob(bytes.clone()), } } fn to_engine_row(row: &cotton_store::driver::Row) -> SearchRow { SearchRow::new( row.columns() .iter() .map(|(name, value)| (name.clone(), to_engine_value(value))), ) } impl SearchDriver for FileSearchDriver<'_> { fn all(&self, sql: &str, params: &[SqlParam]) -> Result, SearchError> { let bound: Vec = params.iter().map(to_sql_value).collect(); self.0 .all(sql, &bound) .map(|rows| rows.iter().map(to_engine_row).collect()) .map_err(|error| SearchError::Driver(error.to_string())) } /// The binding's own single-row call, rather than materialising a result /// set to take its head — the reason the trait keeps `get` at all. fn get(&self, sql: &str, params: &[SqlParam]) -> Result, SearchError> { let bound: Vec = params.iter().map(to_sql_value).collect(); self.0 .get(sql, &bound) .map(|row| row.as_ref().map(to_engine_row)) .map_err(|error| SearchError::Driver(error.to_string())) } } // ── the meaning lane ──────────────────────────────────────────────────────── // THE MEANING LANE'S THREE SETTLED ANSWERS are read straight out of the file by // `crate::embed::query::resolve_meaning_lane_offline` — the switch, the two // server-local tables and the generation stamp, asked in the order the spec // gives them (D13, D14). They were a `mod embed_shim` here while `src/embed/` // did not exist; the module landed with the indexer and the shim MOVED into it // rather than being copied, because two copies of "is the switch on" is exactly // how the indexer and this lane would eventually stop agreeing about what a // person consented to. /// Why the meaning lane has nothing to say — `MeaningLaneAbsence`. #[derive(Debug, Clone, PartialEq, Eq)] enum LaneAbsence { /// The owner has not turned semantic search on. The default, and it stays /// the default. Off, /// On, but no vector has been written yet. Empty, /// The provider or the AI gate said no. Unreachable, } impl LaneAbsence { fn as_str(&self) -> &'static str { match self { LaneAbsence::Off => "off", LaneAbsence::Empty => "empty", LaneAbsence::Unreachable => "unreachable", } } } /// What the lane answered. #[derive(Debug, Clone)] enum MeaningLane { /// The embedded query, and the generation it must be scored against. /// /// OWNED, where the engine's own `SemanticQuery` borrows: the engine's /// options are built from these two fields at the point of use. Ready { vector: Vec, model: String }, Absent { reason: LaneAbsence, /// One sentence, for a person or an assistant to read. note: String, }, } /// Is this file ready to answer by meaning, and what does it compare against? /// /// Reads the switch first and creates nothing: a workspace that never turned /// this on has no `_embeddings` table, and being SEARCHED must not be what /// brings one into being — only the indexer creates. /// /// The generation compared against is `_embed_state.active_model`, never the /// model this server would index with today: during a model change the table /// holds two generations at once, and a query embedded at the new model scored /// against the old model's rows is comparing vectors from two different /// geometries — numbers come out, and every one of them is meaningless. /// /// FOUR ways it has nothing to say and every one of them is an ANSWER, never a /// thrown error (D20). Three are settled states, decided with no network call /// at all by `embed::query::resolve_meaning_lane_offline` — the same three /// reads `GET /v1/search/status` makes, in one place so the two surfaces cannot /// disagree. The fourth is a fault: the provider refused, or this server has no /// embedder. It is reported as an absence with its reason attached rather than /// as a silently shorter result list, which is the one thing a degraded search /// must never look like (D19). /// /// ON THIS BUILD `off` is the only reachable answer for a real file: /// `cotton_ai_access.semantic_search` is build-order step 6 of the spec and is /// not a column of the schema this build reads, so the switch is structurally /// off for every workspace. The rest of this function is exercised against a /// file that HAS the column, which is what the migration will produce. fn resolve_meaning_lane(ctx: &Ctx<'_>, query: &str) -> MeaningLane { let model = match crate::embed::query::resolve_meaning_lane_offline( ctx.db(), ctx.workspace_id, query, ) { Ok(model) => model, Err(absent) => return from_offline(absent), }; // The rail a dispatcher hands this call ANSWERS a vector it embedded // before it took the file (`meaning_query`); it never dials from here. let Some(rail) = ctx.services.embed_query.clone() else { return MeaningLane::Absent { reason: LaneAbsence::Unreachable, note: "Search by meaning could not run: this server has no embedding key.".to_string(), }; }; match rail(query.trim()) { Ok(vector) => MeaningLane::Ready { vector, model }, // The typed reason, not a swallowed one: a ceiling and a dead network // are different problems and the reader has to be able to tell. Err(reason) => MeaningLane::Absent { reason: LaneAbsence::Unreachable, note: format!("Search by meaning could not run: {reason}"), }, } } /// The question a `search_records` call will ask by meaning, as the handler /// reads it — `None` for a text search, or a call the handler would refuse. /// /// Embedding it is a round trip to a third party, and the handler runs inside /// the person's file. So a dispatcher asks this BEFORE it takes the file, /// settles the lane's offline half (`embed::query::resolve_meaning_lane_offline`) /// and embeds `query.trim()` with nothing held, then hands the call a rail /// that answers that vector (`crate::mcp::dispatch::before_the_file`). pub fn meaning_query(args: &Map) -> Option { validate_search(args) .ok() .filter(|args| args.mode != "text") .map(|args| args.query) } /// The three settled answers, in this module's own vocabulary. /// /// Two enums rather than one shared across the crate: `embed::query`'s is the /// LANE's, and this one is what `search_records` puts on the wire. They agree /// by this function, which is the one place a new absence has to be spelled /// twice — and Rust's exhaustiveness makes forgetting it a build failure. fn from_offline(absent: crate::embed::query::MeaningLane) -> MeaningLane { match absent { crate::embed::query::MeaningLane::Absent { reason, note } => MeaningLane::Absent { reason: match reason { crate::embed::query::MeaningLaneAbsence::Off => LaneAbsence::Off, crate::embed::query::MeaningLaneAbsence::Empty => LaneAbsence::Empty, crate::embed::query::MeaningLaneAbsence::Unreachable => LaneAbsence::Unreachable, }, note, }, // `resolve_meaning_lane_offline` answers `Ok(model)` when the file is // ready; it never hands back a `Ready` for this arm to unwrap. crate::embed::query::MeaningLane::Ready { .. } => MeaningLane::Absent { reason: LaneAbsence::Empty, note: "Search by meaning is on, but nothing has been indexed yet.".to_string(), }, } } // ── the tool ──────────────────────────────────────────────────────────────── pub fn search_records(ctx: &mut Ctx<'_>, args: &Map) -> ToolResult { let all_tables = args .get("kinds") .and_then(Value::as_array) .is_none_or(Vec::is_empty); let args = validate_search(args)?; // The parser accepts the table-id grammar; the file supplies the dynamic // vocabulary. Keep unknown-id refusals while accepting real synced tables, // including a newer definition this build will skip with a logged reason. if args.kinds.iter().any(|kind| !SEARCH_KINDS.contains(&kind.as_str())) { let defined = crate::definitions::definition_rows(ctx, None)?; if let Some(kind) = args.kinds.iter().find(|kind| { !SEARCH_KINDS.contains(&kind.as_str()) && !defined.iter().any(|row| row.id == **kind) }) { return fail(format!( "unknown kind {}. Allowed: {}; or a synced table id", js::json_stringify(&Value::from(kind.as_str())), SEARCH_KINDS.join(", ") )); } } // The engine folds journal into the note lane under a flag; both MCP kinds // ride that one lane and the flag splits them again below. let mut engine_kinds: Vec = Vec::new(); for kind in &args.kinds { let name = if kind == "journal" { "note" } else { kind }; if let Some(parsed) = EverythingKind::parse(name) { if !engine_kinds.contains(&parsed) { engine_kinds.push(parsed); } } } // The meaning lane, when it was asked for. A lane that cannot run is an // absence with a reason attached — the text hits below are not withheld // because the second lane went dark. let meaning = (args.mode != "text").then(|| resolve_meaning_lane(ctx, &args.query)); let lanes = match args.mode.as_str() { "meaning" => EverythingLanes::Meaning, "both" => EverythingLanes::Both, _ => EverythingLanes::Text, }; let options = EverythingSearchOptions { mail_index: Some(mail_index_of(ctx.db())), per_kind: Some(args.limit), kinds: Some(&engine_kinds), lanes: Some(lanes), // With `lanes` naming the meaning half and this absent, the engine's // meaning half is simply empty — the honest shape when the switch is // off, nothing is indexed, or the provider could not be reached. The // CALLER says why, and the envelope below does. meaning: match &meaning { Some(MeaningLane::Ready { vector, model }) => Some(SemanticQuery { vector, model, min_score: None, }), _ => None, }, offset: 0, as_sections: false, }; let read = search_everything_file(&FileSearchDriver(ctx.db()), &args.query, &options) .map_err(|error| ToolFailure::new(error.to_string()))?; let memory_meta = memory_meta_for(ctx, &read.hits)?; // A hit is answered only while a tool here draws its table — the rows of // a table no tool draws are read by no path (credentials included). let drawn: std::collections::BTreeSet = crate::definitions::definition_rows(ctx, None)? .into_iter() .filter(|row| { let built = cotton_core::definitions::builtin_table_definitions().iter().find(|table| table.id == row.id); !crate::definitions::retired_builtin(row, built) }) .map(|row| row.id) .collect(); let mut records: Vec = Vec::new(); for hit in &read.hits { // The engine's note lane answers for two MCP kinds; keep only the // one(s) the caller asked for. let kind = if hit.kind == EverythingKind::Note && hit.journal { "journal" } else { hit.kind.as_str() }; if !drawn.contains(super::record::kind_table(kind)) { continue; } if crate::home_arrangement::require_table(ctx.read.driver(), ctx.workspace_id, kind).is_err() { continue; } if !args.kinds.iter().any(|wanted| wanted == kind) { continue; } let mut row = Map::new(); row.insert("kind".to_string(), Value::from(kind)); row.insert("table".to_string(), Value::from(kind)); row.insert( "snippet".to_string(), Value::from(hit.snippet.clone().unwrap_or_default()), ); row.insert("id".to_string(), Value::from(hit.id.clone())); row.insert( "title".to_string(), Value::from(hit.title.clone().unwrap_or_else(|| nameless_title(hit))), ); // **A PULL, AN ISSUE AND A RELEASE ARE ADDRESSED BY THEIR REPOSITORY // PLUS THEIR OWN NUMBER OR TAG**, never by the uuid this row's `id` // carries — `get_pull` and `get_issue` take `(repositoryId, number)` // and refuse a uuid by name. So a hit that answered `id` alone was a // hit an assistant could not open: it had to `list_repositories`, then // `list_pulls` on each, and match on the title it had just been given. // The phone's Find carries the same three fields for the same reason. if matches!( hit.kind, EverythingKind::Pull | EverythingKind::Issue | EverythingKind::Release ) { if let Some(repo_id) = &hit.repo_id { row.insert("repositoryId".to_string(), Value::from(repo_id.clone())); } if let Some(number) = hit.number { row.insert("number".to_string(), Value::from(number)); } if let Some(tag) = &hit.tag { row.insert("tag".to_string(), Value::from(tag.clone())); } } if hit.kind == EverythingKind::Memory { if let Some(detail) = memory_meta.get(&hit.id) { row.insert("detail".to_string(), Value::from(detail.clone())); } } else if let Some(snippet) = &hit.snippet { row.insert("detail".to_string(), Value::from(snippet.clone())); } if let Some(when) = &hit.when { row.insert("when".to_string(), Value::from(when.clone())); } if hit.struck { row.insert("struck".to_string(), Value::Bool(true)); } if let Some(thread_id) = &hit.thread_id { row.insert("threadId".to_string(), Value::from(thread_id.clone())); } if let Some(sent_at) = &hit.sent_at { row.insert("sentAt".to_string(), Value::from(sent_at.clone())); } if let Some(page) = hit.page { row.insert("page".to_string(), Value::from(page)); } if hit.matched_by.is_some() { row.insert("matchedBy".to_string(), Value::from("meaning")); } if hit.archived { row.insert("archived".to_string(), Value::Bool(true)); } records.push(Value::Object(row)); } let mut totals = Map::new(); for (section, total) in read.totals.iter() { if !drawn.contains(super::record::kind_table(section.as_str())) { continue; } if crate::home_arrangement::require_table(ctx.read.driver(), ctx.workspace_id, section.as_str()).is_ok() { totals.insert(section.as_str().to_string(), Value::from(total)); } } let engine_count = records.len(); let mut skipped = Vec::new(); super::search_tables::append(ctx, &args, all_tables, &mut records, &mut totals, &mut skipped)?; let generic_tables: Vec = records[engine_count..] .iter() .filter_map(|row| row["table"].as_str().map(str::to_string)) .collect(); // Keep the existing table grouping and each engine's relevance order for // ties. A generic title hit ranks with engine title hits, before a match // only in text; meaning hits remain after the text lane. let mut groups: Vec<(String, Vec)> = Vec::new(); for row in records { let table = row["table"].as_str().unwrap_or_default().to_string(); if let Some((_, hits)) = groups.iter_mut().find(|(id, _)| *id == table) { hits.push(row); } else { groups.push((table, vec![row])); } } let query = args.query.to_lowercase(); let mut records = Vec::new(); for (table, mut hits) in groups { if generic_tables.contains(&table) { // Live before archived, then by how well the title matched. hits.sort_by_cached_key(|hit| { let title = hit["title"].as_str().unwrap_or_default().to_lowercase(); let archived = hit["archived"] == true; (archived, std::cmp::Reverse(if hit["matchedBy"] == "meaning" { 0 } else if title == query { 3 } else if title.contains(&query) { 2 } else { 1 })) }); // Preserve the engine's separate Related lane after the text cap. let related: Vec = hits .iter() .filter(|r| r["matchedBy"] == "meaning") .cloned() .collect(); hits.retain(|r| r["matchedBy"] != "meaning"); hits.truncate(args.limit as usize); hits.extend(related); } records.extend(hits); } let mut out = Map::new(); out.insert("records".to_string(), Value::Array(records)); out.insert("totals".to_string(), Value::Object(totals)); if !skipped.is_empty() { // The tables not searched, each with why: the rest still answered. out.insert("skipped".to_string(), Value::Array(skipped)); } if let Some(MeaningLane::Absent { reason, note }) = meaning { let mut envelope = Map::new(); envelope.insert("available".to_string(), Value::Bool(false)); envelope.insert("reason".to_string(), Value::from(reason.as_str())); envelope.insert("note".to_string(), Value::from(note)); out.insert("meaning".to_string(), Value::Object(envelope)); } Ok(Value::Object(out)) } /// One `[slug]` line per memory hit, batch-read: an assistant cites entries by /// slug, so a memory row without one is unusable as a reference. /// /// Schema v14 dropped `kind` and `layer`, so the detail line names what an /// assistant can still act on: whether the statement is about NOW (and so may /// have gone stale), where it briefs, and the `[slug]` to cite it by. fn memory_meta_for( ctx: &Ctx<'_>, hits: &[EverythingHit], ) -> Result, ToolFailure> { let mut out = HashMap::new(); let ids: Vec = hits .iter() .filter(|hit| hit.kind == EverythingKind::Memory) .map(|hit| hit.id.clone()) .collect(); if ids.is_empty() { return Ok(out); } let marks = vec!["?"; ids.len()].join(", "); let params: Vec = ids.iter().map(|id| SqlValue::Text(id.clone())).collect(); let rows = ctx .db() .all( &format!("SELECT id, slug, status FROM cotton_memories WHERE id IN ({marks})"), ¶ms, ) .map_err(|error| ToolFailure::new(error.to_string()))?; // Its homes: the link rows, not a column of its own. let links = ctx .db() .all( &format!( "SELECT record_id, project_id FROM cotton_project_links WHERE record_kind = 'memory' AND record_id IN ({marks})" ), ¶ms, ) .map_err(|error| ToolFailure::new(error.to_string()))?; let mut project_ids: HashMap> = HashMap::new(); for link in &links { let (Some(record_id), Some(project_id)) = (link.text("record_id"), link.text("project_id")) else { continue; }; project_ids .entry(record_id.to_string()) .or_default() .push(project_id.to_string()); } let slug_by_project: HashMap = if project_ids.is_empty() { HashMap::new() } else { projects(ctx)? .into_iter() .map(|project| (project.id, project.slug)) .collect() }; for row in &rows { let Some(id) = row.text("id") else { continue }; let mut parts: Vec = Vec::new(); let status = row.text("status").unwrap_or_default(); if status != "active" && !status.is_empty() { parts.push(status.to_string()); } let mut homes: Vec = project_ids .get(id) .map(|ids| { ids.iter() .filter_map(|project_id| slug_by_project.get(project_id).cloned()) .collect() }) .unwrap_or_default(); homes.sort(); parts.push(if homes.is_empty() { "no project".to_string() } else { homes.join(", ") }); parts.push(format!("[{}]", row.text("slug").unwrap_or_default())); out.insert(id.to_string(), parts.join(" · ")); } Ok(out) } /// The words for a hit whose record has no name of its own — the server's /// analogue of the app's `hitTitle`, in the assistant's register. fn nameless_title(hit: &EverythingHit) -> String { match hit.kind { // A journal page's identity IS its date. EverythingKind::Note => match (&hit.journal, &hit.when) { (true, Some(when)) => format!("Journal {}", when.chars().take(10).collect::()), _ => "(untitled)".to_string(), }, EverythingKind::Session => "(untitled session)".to_string(), EverythingKind::Transaction => "(transaction)".to_string(), // A repository always has a key and a release always has a tag, so // neither can be nameless — these are the words if one ever were, // rather than "(untitled)", which would read as a missing title on a // row whose title is its identity. EverythingKind::Repository => "(unnamed repository)".to_string(), EverythingKind::Release => "(untagged release)".to_string(), _ => "(untitled)".to_string(), } } #[cfg(test)] #[path = "search_tests.rs"] mod tests;