text_search_core/
struct_info.rs1use tantivy::schema::Schema;
2
3use crate::FieldInfo;
4
5pub struct StructInfo {
6 pub struct_name: String,
7 pub fields: Vec<FieldInfo>,
8}
9
10impl StructInfo {
11 pub fn new(name: String) -> Self {
12 Self {
13 struct_name: name,
14 fields: vec![],
15 }
16 }
17
18 pub fn add_field(&mut self, field: FieldInfo) {
19 self.fields.push(field);
20 }
21
22 pub fn generate_schema(&self) -> Schema {
23 let mut schema_builder = Schema::builder();
24 for field in self.fields.iter() {
25 field.add_to_schema(&mut schema_builder);
26 }
27 schema_builder.build()
28 }
29
30 pub fn get_id_field(&self) -> &FieldInfo {
31 return self.fields.iter().find(|x| x.is_id).expect("Missing id field.");
32 }
33}