| 1566 | } |
| 1567 | |
| 1568 | pub(crate) fn print_code_result( |
| 1569 | result: &atomic_repository::ContentSearchResult, |
| 1570 | json: bool, |
| 1571 | ) -> CliResult<()> { |
| 1572 | if json { |
| 1573 | println!("{}", serde_json::to_string_pretty(&result).unwrap()); |
| 1574 | } else if result.matches.is_empty() { |
| 1575 | println!("No matches found."); |
| 1576 | } else { |
| 1577 | // Show matches |
| 1578 | let mut files = std::collections::HashSet::new(); |
| 1579 | for m in &result.matches { |
| 1580 | files.insert(m.path.as_str()); |
| 1581 | println!( |
| 1582 | "{}:{}: {}", |
| 1583 | m.path, |
| 1584 | m.line_number, |
| 1585 | m.line_content.trim_end() |
| 1586 | ); |
| 1587 | } |
| 1588 | |
| 1589 | // Summary |
| 1590 | println!( |
| 1591 | "\n{} match(es) in {} file(s).", |
| 1592 | result.matches.len(), |
| 1593 | files.len() |
| 1594 | ); |
| 1595 | |
| 1596 | // Show total and facets when results were truncated |
| 1597 | if result.total_matches > result.matches.len() { |
| 1598 | println!( |
| 1599 | " ({} total matches — showing top {}. Narrow with -g or -t.)\n", |
| 1600 | result.total_matches, |
| 1601 | result.matches.len() |
| 1602 | ); |
| 1603 | println!(" Top directories:"); |
| 1604 | for (dir, count) in &result.dir_facets { |
| 1605 | println!(" {:<40} {} matches", format!("-g \"{}\"", dir), count); |
| 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | Ok(()) |
| 1611 | } |
| 1612 | |
| 1613 | // --------------------------------------------------------------------------- |
| 1614 | // QueryIndex — build / rebuild the content search index |