MCPcopy Create free account
hub / github.com/douglance/devsql / search

Function search

crates/ccql/src/cli/commands.rs:320–415  ·  view source on GitHub ↗
(
    config: &Config,
    term: &str,
    scope: &str,
    case_sensitive: bool,
    is_regex: bool,
    _before_context: usize,
    _after_context: usize,
    format: OutputFormat,
)

Source from the content-addressed store, hash-verified

318
319#[allow(clippy::too_many_arguments)]
320pub async fn search(
321 config: &Config,
322 term: &str,
323 scope: &str,
324 case_sensitive: bool,
325 is_regex: bool,
326 _before_context: usize,
327 _after_context: usize,
328 format: OutputFormat,
329) -> Result<()> {
330 let engine = SearchEngine::new(term, case_sensitive, is_regex)?;
331
332 let mut results = Vec::new();
333
334 // Search in history
335 if scope == "all" || scope == "prompts" {
336 let history = HistoryDataSource::new(config.clone());
337 let entries = history.load_all().await?;
338
339 for entry in entries {
340 if engine.matches(&entry.display) {
341 results.push(serde_json::json!({
342 "source": "history",
343 "timestamp": entry.timestamp,
344 "project": entry.project,
345 "content": entry.display
346 }));
347 }
348 }
349 }
350
351 // Search in transcripts
352 if scope == "all" || scope == "transcripts" {
353 let transcripts = TranscriptDataSource::new(config.clone());
354 let sessions = transcripts.load_all_sessions().await?;
355
356 for (session_id, entries) in sessions {
357 for (idx, entry) in entries.iter().enumerate() {
358 if engine.find_in_json(entry) {
359 results.push(serde_json::json!({
360 "source": "transcript",
361 "session_id": session_id,
362 "entry_index": idx,
363 "content": entry
364 }));
365 }
366 }
367 }
368 }
369
370 let mut writer = OutputWriter::new(std::io::stdout(), format);
371
372 match format {
373 OutputFormat::Json => {
374 writer.write_json(&results)?;
375 }
376 OutputFormat::Raw | OutputFormat::Jsonl => {
377 for result in &results {

Callers 1

mainFunction · 0.85

Calls 9

create_tableFunction · 0.85
truncate_stringFunction · 0.85
matchesMethod · 0.80
load_all_sessionsMethod · 0.80
find_in_jsonMethod · 0.80
write_jsonMethod · 0.80
write_tableMethod · 0.80
writelnMethod · 0.80
load_allMethod · 0.45

Tested by

no test coverage detected