pub fn generate_with_config(config: &TokenSearchConfig) -> Self {
        let filtered_results: Vec<_> = config
            .tokens
            .iter()
            .filter(|t| config.filter_token(t) && config.filter_language(t))
            .collect();

        let tokens: Vec<_> = filtered_results.iter().map(|r| &r.token).collect();
        let ac = AhoCorasickBuilder::new()
            .match_kind(MatchKind::LeftmostLongest)
            .build(tokens);

        let res = config
            .files
            .par_iter()
            .progress_with(config.toggleable_progress_bar(&"🤔 Working...", config.files.len()))
            .fold(HashMap::new, |mut results, f| {
                if let Ok(contents) = Self::read_file(&f) {
                    for (key, res) in ac
                        .find_iter(&contents)
                        .map(|v| v.pattern())
                        .into_iter()
                        .sorted_by_key(|&v| v)
                        .group_by(|&v| v)
                        .into_iter()
                        .map(|(idx, res)| (idx, res.count()))
                        .collect::<Vec<(usize, usize)>>()
                    {
                        let file_with_occurrences = results.entry(key).or_insert(HashMap::new());

                        file_with_occurrences.insert(f.clone(), res);
                    }
                }

                results
            })
            .reduce(HashMap::new, |m1, m2| {
                m2.into_iter().fold(m1, |mut acc, (k, v)| {
                    let res = acc.entry(k).or_insert(HashMap::new());
                    res.extend(v);
                    acc
                })
            });

        let final_results = res
            .into_iter()
            .map(|(idx, occurrences)| TokenSearchResult {
                token: filtered_results[idx].clone(),
                occurrences,
            })
            .collect();

        std::thread::spawn(move || drop(ac));

        TokenSearchResults(final_results)
    }
/// Generate results based on provided search config
Generate results based on provided search config
Generate results based on provided search config
pub fn generate_with_config(config: &TokenSearchConfig) -> Self {
        let filtered_results: Vec<_> = config
            .tokens
            .iter()
            .filter(|t| config.filter_token(t) && config.filter_language(t))
            .collect();
        let tokens: Vec<_> = filtered_results.iter().map(|r| &r.token).collect();
        let ac = AhoCorasickBuilder::new()
            .match_kind(MatchKind::LeftmostLongest)
            .build(tokens);
        let res = config
            .files
            .par_iter()
            .progress_with(config.toggleable_progress_bar(&"🤔 Working...", config.files.len()))
            .fold(HashMap::new, |mut results, f| {
                if let Ok(contents) = Self::read_file(&f) {
                    for (key, res) in ac
                        .find_iter(&contents)
                        .map(|v| v.pattern())
                        .into_iter()
                        .sorted_by_key(|&v| v)
                        .group_by(|&v| v)
                        .into_iter()
                        .map(|(idx, res)| (idx, res.count()))
                        .collect::<Vec<(usize, usize)>>()
                    {
                        let file_with_occurrences = results.entry(key).or_insert(HashMap::new());
                        file_with_occurrences.insert(f.clone(), res);
                    }
                }
                results
            })
            .reduce(HashMap::new, |m1, m2| {
                m2.into_iter().fold(m1, |mut acc, (k, v)| {
                    let res = acc.entry(k).or_insert(HashMap::new());
                    res.extend(v);
                    acc
                })
            });
        let final_results = res
            .into_iter()
            .map(|(idx, occurrences)| TokenSearchResult {
                token: filtered_results[idx].clone(),
                occurrences,
            })
            .collect();
        std::thread::spawn(move || drop(ac));
        TokenSearchResults(final_results)
    }
pub fn generate_with_config ( config : & TokenSearchConfig ) -> Self { let filtered_results : Vec < _ > = config . tokens . iter ( ) . filter ( | t | config . filter_token ( t ) && config . filter_language ( t ) ) . collect ( ) ; let tokens : Vec < _ > = filtered_results . iter ( ) . map ( | r | & r . token ) . collect ( ) ; let ac = AhoCorasickBuilder :: new ( ) . match_kind ( MatchKind :: LeftmostLongest ) . build ( tokens ) ; let res = config . files . par_iter ( ) . progress_with ( config . toggleable_progress_bar ( & " c o fig.fi l es.le n ()) ) . fold ( HashMap :: new , | mut results , f | { if let Ok ( contents ) = Self :: read_file ( & f ) { for ( key , res ) in ac . find_iter ( & contents ) . map ( | v | v . pattern ( ) ) . into_iter ( ) . sorted_by_key ( | & v | v ) . group_by ( | & v | v ) . into_iter ( ) . map ( | ( idx , res ) | ( idx , res . count ( ) ) ) . collect :: < Vec < ( usize , usize ) > > ( ) { let file_with_occurrences = results . entry ( key ) . or_insert ( HashMap :: new ( ) ) ; file_with_occurrences . insert ( f . clone ( ) , res ) ; } } results } ) . reduce ( HashMap :: new , | m1 , m2 | { m2 . into_iter ( ) . fold ( m1 , | mut acc , ( k , v ) | { let res = acc . entry ( k ) . or_insert ( HashMap :: new ( ) ) ; res . extend ( v ) ; acc } ) } ) ; let final_results = res . into_iter ( ) . map ( | ( idx , occurrences ) | TokenSearchResult { token : filtered_results [ idx ] . clone ( ) , occurrences , } ) . collect ( ) ; std :: thread :: spawn ( move | | drop ( ac ) ) ; TokenSearchResults ( final_results ) }
Generate results based on provided search config
Generate results based on provided search config
config
&TokenSearchConfig
config
&TokenSearchConfig