| 289 | Ok(result) |
| 290 | } |
| 291 | pub(crate) fn new<'path>( |
| 292 | paths: impl IntoIterator<Item = &'path str>, |
| 293 | pattern: &str, |
| 294 | opts: ContentSearchOptions, |
| 295 | ) -> Result<Self, ContentSearchError> { |
| 296 | // Compile even for empty scopes and zero display limits. |
| 297 | let re = regex::bytes::RegexBuilder::new(pattern) |
| 298 | .case_insensitive(opts.case_insensitive) |
| 299 | .size_limit(RECORDED_CONTENT_LIMIT) |
| 300 | .dfa_size_limit(RECORDED_CONTENT_LIMIT) |
| 301 | .build() |
| 302 | .map_err(|error| ContentSearchError::InvalidPattern(error.to_string()))?; |
| 303 | let mut paths: Vec<_> = paths.into_iter().map(std::path::PathBuf::from).collect(); |
| 304 | paths.sort(); |
| 305 | let index = syntext::path::PathIndex::build(&paths); |
| 306 | let filter = syntext::path::filter::build_filter( |
| 307 | &index, |
| 308 | opts.file_type.as_deref(), |
| 309 | opts.exclude_type.as_deref(), |
| 310 | opts.path_filter.as_deref(), |
| 311 | ); |
| 312 | let mut paths: Vec<_> = paths |
| 313 | .into_iter() |
| 314 | .enumerate() |
| 315 | .filter(|(id, _)| { |
| 316 | filter |
| 317 | .as_ref() |
| 318 | .is_none_or(|filter| filter.file_ids.contains(*id as u32)) |
| 319 | }) |
| 320 | .map(|(_, path)| path.to_string_lossy().into_owned()) |
| 321 | .collect(); |
| 322 | paths.sort_by(|a, b| recorded_path_order(a, b)); |
| 323 | Ok(Self { |
| 324 | re, |
| 325 | paths, |
| 326 | display_limit: opts.max_results.unwrap_or(50), |
| 327 | }) |
| 328 | } |
| 329 | |
| 330 | pub(crate) fn run<E>( |
| 331 | self, |