MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / search_content

Function search_content

atomic-repository/src/content_search.rs:187–229  ·  view source on GitHub ↗

Search the content index. Returns matching lines with file paths, line numbers, and content. Supports path filtering, file type filtering, and case-insensitive search. Results are ranked: source files (`src/`, `lib/`, `pkg/`, `internal/`) are prioritized over config, test, build, and generated files. Within each tier, results follow path order and preserve the verifier's within-file order. The

(
    repo_root: &Path,
    pattern: &str,
    opts: ContentSearchOptions,
)

Source from the content-addressed store, hash-verified

185/// (capped to `max_results`) and the `total_matches` count so callers
186/// know how many were found before truncation.
187pub fn search_content(
188 repo_root: &Path,
189 pattern: &str,
190 opts: ContentSearchOptions,
191) -> Result<ContentSearchResult, ContentSearchError> {
192 let config = content_config(repo_root);
193 let index = Index::open(config)?;
194
195 let display_limit = opts.max_results.unwrap_or(50);
196
197 // Fetch a large candidate set so we can rank before truncating.
198 // We ask for 10x the display limit (capped at 2000) to get good
199 // coverage across the repo before applying our own ranking.
200 let fetch_limit = (display_limit * 10).min(2000);
201
202 let search_opts = SearchOptions {
203 path_filter: opts.path_filter,
204 file_type: opts.file_type,
205 exclude_type: opts.exclude_type,
206 max_results: Some(fetch_limit),
207 case_insensitive: opts.case_insensitive,
208 };
209
210 let raw_matches = index.search(pattern, &search_opts)?;
211
212 // Drop matches in ignored or Atomic-internal paths. syntext's index walk
213 // respects `.gitignore`/`.ignore` but NOT `.atomicignore`, and it descends
214 // into hidden dirs like `.atomic`/`.vault`, so build artifacts and
215 // dependencies excluded only by `.atomicignore` (plus Atomic internals)
216 // would otherwise surface here and, via the KG search's content-only file
217 // promotion, as `file:` results. Filter at this shared consumption point
218 // so both `query search` and `query code` stay clean regardless of what
219 // the index contains.
220 let ignore_rules = crate::ignore::IgnoreRules::load_for_enrichment(repo_root);
221 let raw_matches: Vec<syntext::SearchMatch> = raw_matches
222 .into_iter()
223 .filter(|m| {
224 !crate::ignore::is_enrichment_internal(&m.path)
225 && !ignore_rules.is_ignored(&m.path, false)
226 })
227 .collect();
228 Ok(rank_content_matches(raw_matches, display_limit))
229}
230
231/// Recorded-query byte and regex-automaton cutoff (10 MiB).
232pub(crate) const RECORDED_CONTENT_LIMIT: usize = 10 * 1024 * 1024;

Calls 7

content_configFunction · 0.85
openFunction · 0.85
is_enrichment_internalFunction · 0.85
rank_content_matchesFunction · 0.85
collectMethod · 0.45
into_iterMethod · 0.45
is_ignoredMethod · 0.45