summavy/schema/
flags.rs

1use std::ops::BitOr;
2
3use crate::schema::{NumericOptions, TextOptions};
4use crate::DateOptions;
5
6#[derive(Clone)]
7pub struct StoredFlag;
8/// Flag to mark the field as stored.
9/// This flag can apply to any kind of field.
10///
11/// A stored fields of a document can be retrieved given its `DocId`.
12/// Stored field are stored together and compressed.
13/// Reading the stored fields of a document is relatively slow.
14/// (~ 100 microsecs)
15///
16/// It should not be used during scoring or collection.
17pub const STORED: SchemaFlagList<StoredFlag, ()> = SchemaFlagList {
18    head: StoredFlag,
19    tail: (),
20};
21
22#[derive(Clone)]
23pub struct IndexedFlag;
24/// Flag to mark the field as indexed. An indexed field is searchable and has a fieldnorm.
25///
26/// The `INDEXED` flag can only be used when building `NumericOptions` (`u64`, `i64`, `f64` and
27/// `bool` fields) Of course, text fields can also be indexed... But this is expressed by using
28/// either the `STRING` (untokenized) or `TEXT` (tokenized with the english tokenizer) flags.
29pub const INDEXED: SchemaFlagList<IndexedFlag, ()> = SchemaFlagList {
30    head: IndexedFlag,
31    tail: (),
32};
33
34#[derive(Clone)]
35pub struct FastFlag;
36/// Flag to mark the field as a fast field (similar to Lucene's DocValues)
37///
38/// Fast fields can be random-accessed rapidly. Fields useful for scoring, filtering
39/// or collection should be mark as fast fields.
40///
41/// See [fast fields](`crate::fastfield`).
42pub const FAST: SchemaFlagList<FastFlag, ()> = SchemaFlagList {
43    head: FastFlag,
44    tail: (),
45};
46
47impl<Head, OldHead, OldTail> BitOr<SchemaFlagList<Head, ()>> for SchemaFlagList<OldHead, OldTail>
48where
49    Head: Clone,
50    OldHead: Clone,
51    OldTail: Clone,
52{
53    type Output = SchemaFlagList<Head, SchemaFlagList<OldHead, OldTail>>;
54
55    fn bitor(self, head: SchemaFlagList<Head, ()>) -> Self::Output {
56        SchemaFlagList {
57            head: head.head,
58            tail: self,
59        }
60    }
61}
62
63impl<T: Clone + Into<NumericOptions>> BitOr<NumericOptions> for SchemaFlagList<T, ()> {
64    type Output = NumericOptions;
65
66    fn bitor(self, rhs: NumericOptions) -> Self::Output {
67        self.head.into() | rhs
68    }
69}
70
71impl<T: Clone + Into<DateOptions>> BitOr<DateOptions> for SchemaFlagList<T, ()> {
72    type Output = DateOptions;
73
74    fn bitor(self, rhs: DateOptions) -> Self::Output {
75        self.head.into() | rhs
76    }
77}
78
79impl<T: Clone + Into<TextOptions>> BitOr<TextOptions> for SchemaFlagList<T, ()> {
80    type Output = TextOptions;
81
82    fn bitor(self, rhs: TextOptions) -> Self::Output {
83        self.head.into() | rhs
84    }
85}
86
87#[derive(Clone)]
88pub struct SchemaFlagList<Head: Clone, Tail: Clone> {
89    pub head: Head,
90    pub tail: Tail,
91}