(
self,
mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>,
)
| 328 | } |
| 329 | |
| 330 | pub(crate) fn run<E>( |
| 331 | self, |
| 332 | mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>, |
| 333 | ) -> Result<ContentSearchResult, E> { |
| 334 | let mut matches = Vec::new(); |
| 335 | let mut total_matches = 0; |
| 336 | let mut directories = std::collections::BTreeMap::<String, usize>::new(); |
| 337 | for path in self.paths { |
| 338 | let Some(content) = retrieve(&path)? else { |
| 339 | continue; |
| 340 | }; |
| 341 | if content.len() > RECORDED_CONTENT_LIMIT || syntext::index::is_binary(&content) { |
| 342 | continue; |
| 343 | } |
| 344 | let mut line_start = 0; |
| 345 | let mut file_count = 0; |
| 346 | // This borrowed-line adapter implements syntext 1.4's verifier |
| 347 | // contract: first match per line, CR stripped only before LF, no |
| 348 | // artificial trailing empty line, and file-level binary detection. |
| 349 | // Differential tests below keep it pinned to verify_regex, including |
| 350 | // NULs beyond the first 8192 bytes. No dependency fork is required. |
| 351 | for (index, raw_line) in content.split_inclusive(|byte| *byte == b'\n').enumerate() { |
| 352 | let line = raw_line |
| 353 | .strip_suffix(b"\n") |
| 354 | .map(|line| line.strip_suffix(b"\r").unwrap_or(line)) |
| 355 | .unwrap_or(raw_line); |
| 356 | if let Some(found) = self.re.find(line) { |
| 357 | file_count += 1; |
| 358 | if matches.len() < self.display_limit { |
| 359 | matches.push(ContentMatch { |
| 360 | path: path.clone(), |
| 361 | line_number: (index + 1) as u32, |
| 362 | line_content: String::from_utf8_lossy(line).into_owned(), |
| 363 | byte_offset: (line_start + found.start()) as u64, |
| 364 | submatch_start: found.start(), |
| 365 | submatch_end: found.end(), |
| 366 | }); |
| 367 | #[cfg(any(test, feature = "query-test-instrumentation"))] |
| 368 | crate::query_diagnostics::retained(matches.len()); |
| 369 | } |
| 370 | } |
| 371 | line_start += raw_line.len(); |
| 372 | } |
| 373 | if file_count > 0 { |
| 374 | total_matches += file_count; |
| 375 | *directories.entry(directory_bucket(&path)).or_default() += file_count; |
| 376 | } |
| 377 | } |
| 378 | Ok(ContentSearchResult { |
| 379 | matches, |
| 380 | total_matches, |
| 381 | dir_facets: directory_facets(directories), |
| 382 | }) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | fn recorded_path_order(a: &str, b: &str) -> std::cmp::Ordering { |
nothing calls this directly
no test coverage detected