1 use super::*;
2 use lazy_static::lazy_static;
3 use spawning::SpawningFileAdapter;
4 use std::process::Command;
5 
6 static EXTENSIONS: &[&str] = &["jpg", "png"];
7 
8 lazy_static! {
9     static ref METADATA: AdapterMeta = AdapterMeta {
10         name: "tesseract".to_owned(),
11         version: 1,
12         description: "Uses tesseract to run OCR on images to make them searchable. May need -j1 to prevent overloading the system. Make sure you have tesseract installed.".to_owned(),
13         recurses: false,
14         fast_matchers: EXTENSIONS
15             .iter()
16             .map(|s| FastMatcher::FileExtension(s.to_string()))
17             .collect(),
18         slow_matchers: None
19     };
20 }
21 #[derive(Default)]
22 pub struct TesseractAdapter {}
23 
24 impl TesseractAdapter {
new() -> TesseractAdapter25     pub fn new() -> TesseractAdapter {
26         TesseractAdapter {}
27     }
28 }
29 
30 impl GetMetadata for TesseractAdapter {
metadata(&self) -> &AdapterMeta31     fn metadata(&self) -> &AdapterMeta {
32         &METADATA
33     }
34 }
35 impl SpawningFileAdapter for TesseractAdapter {
get_exe(&self) -> &str36     fn get_exe(&self) -> &str {
37         "tesseract"
38     }
command(&self, _filepath_hint: &Path, mut cmd: Command) -> Command39     fn command(&self, _filepath_hint: &Path, mut cmd: Command) -> Command {
40         // rg already does threading
41         cmd.env("OMP_THREAD_LIMIT", "1").arg("-").arg("-");
42         cmd
43     }
44 }
45