1use tantivy::schema::{
2 Field, IndexRecordOption, Schema, TextFieldIndexing, TextOptions, FAST, STORED, STRING,
3};
4
5#[derive(Clone)]
6pub struct IndexSchema {
7 pub schema: Schema,
8 pub id: Field,
9 pub path: Field,
10 pub content: Field,
11 pub symbol_name: Field,
12 pub symbol_type: Field,
13 pub start_line: Field,
14 pub end_line: Field,
15 pub language: Field,
16 pub file_hash: Field,
17}
18
19impl IndexSchema {
20 pub fn new() -> Self {
21 let mut builder = Schema::builder();
22
23 let id = builder.add_text_field("id", STRING | STORED);
25
26 let path = builder.add_text_field("path", STRING | STORED);
28
29 let content_opts = TextOptions::default()
31 .set_indexing_options(
32 TextFieldIndexing::default()
33 .set_tokenizer("default")
34 .set_index_option(IndexRecordOption::WithFreqsAndPositions),
35 )
36 .set_stored();
37 let content = builder.add_text_field("content", content_opts);
38
39 let symbol_opts = TextOptions::default()
41 .set_indexing_options(
42 TextFieldIndexing::default()
43 .set_tokenizer("default")
44 .set_index_option(IndexRecordOption::WithFreqs),
45 )
46 .set_stored();
47 let symbol_name = builder.add_text_field("symbol_name", symbol_opts);
48
49 let symbol_type = builder.add_text_field("symbol_type", STRING | STORED);
51
52 let start_line = builder.add_u64_field("start_line", FAST | STORED);
54 let end_line = builder.add_u64_field("end_line", FAST | STORED);
55
56 let language = builder.add_text_field("language", STRING | STORED);
58
59 let file_hash = builder.add_text_field("file_hash", STRING | STORED);
61
62 Self {
63 schema: builder.build(),
64 id,
65 path,
66 content,
67 symbol_name,
68 symbol_type,
69 start_line,
70 end_line,
71 language,
72 file_hash,
73 }
74 }
75}
76
77impl Default for IndexSchema {
78 fn default() -> Self {
79 Self::new()
80 }
81}