Skip to main content

sift_core/search/request/
mod.rs

1use crate::Candidate;
2use crate::search::output::SearchOutput;
3use crate::search::output::style::SearchSeparators;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum LinkTraversal {
7    DoNotFollow,
8    Follow,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct WalkOptions {
13    pub links: LinkTraversal,
14    pub max_depth: Option<usize>,
15    pub max_filesize: Option<u64>,
16    pub one_file_system: bool,
17}
18
19impl Default for WalkOptions {
20    fn default() -> Self {
21        Self {
22            links: LinkTraversal::DoNotFollow,
23            max_depth: None,
24            max_filesize: None,
25            one_file_system: false,
26        }
27    }
28}
29
30#[derive(Clone)]
31pub struct SearchExecution<'a> {
32    pub candidates: Vec<Candidate>,
33    pub output: SearchOutput,
34    pub separators: &'a SearchSeparators,
35    pub collect: SearchCollection,
36}
37
38/// Optional artifacts gathered during search beyond primary output.
39#[must_use]
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub struct SearchCollection {
42    pub stats: bool,
43    pub hits: bool,
44}
45
46impl Default for SearchCollection {
47    fn default() -> Self {
48        Self::none()
49    }
50}
51
52impl SearchCollection {
53    pub const fn none() -> Self {
54        Self {
55            stats: false,
56            hits: false,
57        }
58    }
59
60    pub const fn stats() -> Self {
61        Self {
62            stats: true,
63            hits: false,
64        }
65    }
66
67    pub const fn hits() -> Self {
68        Self {
69            stats: false,
70            hits: true,
71        }
72    }
73
74    pub const fn stats_and_hits() -> Self {
75        Self {
76            stats: true,
77            hits: true,
78        }
79    }
80
81    pub const fn with_stats(self, stats: bool) -> Self {
82        Self {
83            stats,
84            hits: self.hits,
85        }
86    }
87
88    pub const fn with_hits(self, hits: bool) -> Self {
89        Self {
90            stats: self.stats,
91            hits,
92        }
93    }
94}