binarydata/
04_binary_data.rs1use serde_value;
2use serde::{Serialize, Deserialize};
3use tantivy::schema::Schema;
4use tantivy::schema::FieldEntry;
5use tantivy::schema::TextOptions;
6
7
8#[derive(Serialize, Debug, Deserialize, PartialEq, PartialOrd, Clone)]
9struct Container {
10 buffer: Vec<u8>,
11 labels: String,
12}
13
14impl Default for Container {
15 fn default() -> Self {
16 let buffer = "HelloWorld".to_string().into_bytes();
17 let labels = "Tantivy Rocks".to_string();
18 Self{
19 buffer,
20 labels,
21 }
22 }
23}
24
25fn main() {
26 println!("This example is here to demonstrate that Tantivy does not support stored bytes yet");
27 let data = Container::default();
29 let value = serde_value::to_value(data).expect("[Cough]");
30 let json_doc = serde_json::to_string(&value).expect("[Cough Again]");
31 println!("Json: {}", json_doc);
32
33 let mut builder = Schema::builder();
35 let field_name = "buffer".to_string();
38 let entry = FieldEntry::new_bytes(field_name);
39 let _ = builder.add_field(entry);
40
41 let text_options = TextOptions::default();
42 let field_name = "labels".to_string();
43 let entry = FieldEntry::new_text(field_name, text_options);
44 let _ = builder.add_field(entry);
45
46 let schema = builder.build();
47 let document = schema.parse_document(&json_doc).expect("[Dies Coughing]");
48 println!("Document: {:#?}", document);
49}