| 242 | |
| 243 | impl RecordedContentSearch { |
| 244 | pub(crate) fn new<'path>( |
| 245 | paths: impl IntoIterator<Item = &'path str>, |
| 246 | pattern: &str, |
| 247 | opts: ContentSearchOptions, |
| 248 | ) -> Result<Self, ContentSearchError> { |
| 249 | // Compile even for empty scopes and zero display limits. |
| 250 | let re = regex::bytes::RegexBuilder::new(pattern) |
| 251 | .case_insensitive(opts.case_insensitive) |
| 252 | .size_limit(RECORDED_CONTENT_LIMIT) |
| 253 | .dfa_size_limit(RECORDED_CONTENT_LIMIT) |
| 254 | .build() |
| 255 | .map_err(|error| ContentSearchError::InvalidPattern(error.to_string()))?; |
| 256 | let mut paths: Vec<_> = paths.into_iter().map(std::path::PathBuf::from).collect(); |
| 257 | paths.sort(); |
| 258 | let index = syntext::path::PathIndex::build(&paths); |
| 259 | let filter = syntext::path::filter::build_filter( |
| 260 | &index, |
| 261 | opts.file_type.as_deref(), |
| 262 | opts.exclude_type.as_deref(), |
| 263 | opts.path_filter.as_deref(), |
| 264 | ); |
| 265 | let mut paths: Vec<_> = paths |
| 266 | .into_iter() |
| 267 | .enumerate() |
| 268 | .filter(|(id, _)| { |
| 269 | filter |
| 270 | .as_ref() |
| 271 | .is_none_or(|filter| filter.file_ids.contains(*id as u32)) |
| 272 | }) |
| 273 | .map(|(_, path)| path.to_string_lossy().into_owned()) |
| 274 | .collect(); |
| 275 | paths.sort_by(|a, b| recorded_path_order(a, b)); |
| 276 | Ok(Self { |
| 277 | re, |
| 278 | paths, |
| 279 | display_limit: opts.max_results.unwrap_or(50), |
| 280 | }) |
| 281 | } |
| 282 | |
| 283 | pub(crate) fn run<E>( |
| 284 | self, |