Struct rg::search::SearchWorker
source · pub struct SearchWorker<W> {
config: Config,
command_builder: CommandReaderBuilder,
decomp_builder: DecompressionReaderBuilder,
matcher: PatternMatcher,
searcher: Searcher,
printer: Printer<W>,
}
Expand description
A worker for executing searches.
It is intended for a single worker to execute many searches, and is generally intended to be used from a single thread. When searching using multiple threads, it is better to create a new worker for each thread.
Fields§
§config: Config
§command_builder: CommandReaderBuilder
§decomp_builder: DecompressionReaderBuilder
§matcher: PatternMatcher
§searcher: Searcher
§printer: Printer<W>
Implementations§
source§impl<W: WriteColor> SearchWorker<W>
impl<W: WriteColor> SearchWorker<W>
sourcepub fn search(&mut self, subject: &Subject) -> Result<SearchResult>
pub fn search(&mut self, subject: &Subject) -> Result<SearchResult>
Execute a search over the given subject.
sourcepub fn printer(&mut self) -> &mut Printer<W>
pub fn printer(&mut self) -> &mut Printer<W>
Return a mutable reference to the underlying printer.
sourcepub fn print_stats(
&mut self,
total_duration: Duration,
stats: &Stats
) -> Result<()>
pub fn print_stats( &mut self, total_duration: Duration, stats: &Stats ) -> Result<()>
Print the given statistics to the underlying writer in a way that is consistent with this searcher’s printer’s format.
While Stats
contains a duration itself, this only corresponds to the
time spent searching, where as total_duration
should roughly
approximate the lifespan of the ripgrep process itself.
sourcefn should_decompress(&self, path: &Path) -> bool
fn should_decompress(&self, path: &Path) -> bool
Returns true if and only if the given file path should be decompressed before searching.
sourcefn should_preprocess(&self, path: &Path) -> bool
fn should_preprocess(&self, path: &Path) -> bool
Returns true if and only if the given file path should be run through the preprocessor.
sourcefn search_preprocessor(&mut self, path: &Path) -> Result<SearchResult>
fn search_preprocessor(&mut self, path: &Path) -> Result<SearchResult>
Search the given file path by first asking the preprocessor for the data to search instead of opening the path directly.
sourcefn search_decompress(&mut self, path: &Path) -> Result<SearchResult>
fn search_decompress(&mut self, path: &Path) -> Result<SearchResult>
Attempt to decompress the data at the given file path and search the result. If the given file path isn’t recognized as a compressed file, then search it without doing any decompression.
sourcefn search_path(&mut self, path: &Path) -> Result<SearchResult>
fn search_path(&mut self, path: &Path) -> Result<SearchResult>
Search the contents of the given file path.
sourcefn search_reader<R: Read>(
&mut self,
path: &Path,
rdr: &mut R
) -> Result<SearchResult>
fn search_reader<R: Read>( &mut self, path: &Path, rdr: &mut R ) -> Result<SearchResult>
Executes a search on the given reader, which may or may not correspond directly to the contents of the given file path. Instead, the reader may actually cause something else to be searched (for example, when a preprocessor is set or when decompression is enabled). In those cases, the file path is used for visual purposes only.
Generally speaking, this method should only be used when there is no
other choice. Searching via search_path
provides more opportunities
for optimizations (such as memory maps).