Struct SurferBuilder

Source
pub struct SurferBuilder { /* private fields */ }
Expand description

Builder struct for Surfer

Implementations§

Source§

impl SurferBuilder

Provides access to Surfer

Source

pub fn resolve_schemas(&self) -> &HashMap<String, SurferSchema>

Surfer Schema

Source

pub fn set_home(&mut self, home: &str)

Set home location - default is indexes

Examples found in repository?
examples/03_fuzzy_user_name.rs (line 38)
33fn main() {
34    let home = ".store".to_string();
35    let name = "fuzzy".to_string();
36
37    let mut builder = SurferBuilder::default();
38    builder.set_home(&home);
39
40    let data = User::default();
41    builder.add_struct(name.clone(), &data);
42
43    let mut surfer = Surfer::try_from(builder).unwrap();
44
45    let first = "John".to_string();
46    let last = "Doe".to_string();
47    let john_doe = User::new(first, last);
48
49    let first = "Jane".to_string();
50    let last = "Doe".to_string();
51    let jane_doe = User::new(first, last);
52
53    let users = vec![john_doe.clone(), jane_doe.clone()];
54    let _ = surfer.insert_structs(&name, &users).unwrap();
55    println!("===========================");
56    println!("Insert: John & Jane Doe");
57    println!("---------------------------");
58    println!("{:#?}", users);
59    println!("---------------------------");
60
61    block_thread(2);
62
63    let query = "deo";
64    let mut computed = surfer.read_structs::<User>(&name, query, Some(100), None).unwrap().unwrap();
65    computed.sort();
66    let mut expected = vec![];
67    expected.sort();
68    assert_eq!(computed, expected);
69
70    println!("====================================");
71    println!("Incorrect Query: '{}' Select: None", query);
72    println!("------------------------------------");
73    println!("{:#?}", computed);
74    println!("------------------------------------");
75
76    let fuzz = FuzzyWord::default();
77    let mod_query = fuzz.lookup(query);
78    assert!(mod_query.is_some());
79    let adjusted = mod_query.unwrap();
80    assert!(adjusted.len() >= 1);
81    let adjusted = adjusted.get(0).unwrap();
82    let mut computed = surfer.read_structs::<User>(&name, adjusted, Some(100), None).unwrap().unwrap();
83    computed.sort();
84    let mut expected = vec![john_doe.clone(), jane_doe.clone()];
85    expected.sort();
86    assert_eq!(computed, expected);
87
88    println!("====================================");
89    println!("Adjusted Query: '{}' Select: Jane & John Doe", adjusted);
90    println!("------------------------------------");
91    println!("{:#?}", computed);
92    println!("------------------------------------");
93
94
95    // Clean-up
96    let path = surfer.which_index(&name).unwrap();
97    let _ = remove_dir_all(&path);
98    let _ = remove_dir_all(&home);
99}
More examples
Hide additional examples
examples/00_usage.rs (line 48)
40fn main() {
41    // Specify home location for indexes
42    let home = ".store".to_string();
43    // Specify index name
44    let index_name = "usage".to_string();
45
46    // Prepare builder
47    let mut builder = SurferBuilder::default();
48    builder.set_home(&home);
49
50    let data = UserInfo::default();
51    builder.add_struct(index_name.clone(), &data);
52
53    // Prepare Surf
54    let mut surf = Surf::try_from(builder).unwrap();
55
56    // Prepare data to insert & search
57
58    // User 1: John Doe
59    let first = "John".to_string();
60    let last = "Doe".to_string();
61    let age = 20u8;
62    let john_doe = UserInfo::new(first, last, age);
63
64    // User 2: Jane Doe
65    let first = "Jane".to_string();
66    let last = "Doe".to_string();
67    let age = 18u8;
68    let jane_doe = UserInfo::new(first, last, age);
69
70    // See examples for more options
71    let users = vec![john_doe.clone(), jane_doe.clone()];
72    let _ = surf.insert(&index_name, &users).unwrap();
73
74    block_thread(1);
75
76    // See examples for more options
77    // Similar to SELECT * FROM users WHERE (age = 20 AND last = "Doe") OR (first = "Jane")
78    let conditions = vec![
79        OrCondition::new(
80            // (age = 20 AND last = "Doe")
81            vec![
82                AndCondition::new("age".to_string(), "20".to_string()),
83                AndCondition::new("last".to_string(), "doe".to_string())
84            ]),
85        OrCondition::new(
86            // (first = "Jane")
87            vec![
88                AndCondition::new("first".to_string(), "jane".to_string())
89            ])
90    ];
91
92    // Validate John and Jane Doe
93    let mut computed = surf.select::<UserInfo>(&index_name, &conditions).unwrap().unwrap();
94    let mut expected = vec![john_doe.clone(), jane_doe.clone(), ];
95    expected.sort();
96    computed.sort();
97    assert_eq!(expected, computed);
98
99    // Validated John's record - Alternate shortcut for query using one field only
100    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
101    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
102    assert_eq!(vec![john_doe], computed);
103
104    // Delete John's record
105    let result = surf.delete(&index_name, "age", "20");
106    assert!(result.is_ok());
107
108    // John's was removed
109    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
110    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
111    assert!(computed.is_empty());
112
113
114    // Clean-up
115    let path = surf.which_index(&index_name).unwrap();
116    let _ = remove_dir_all(&path);
117    let _ = remove_dir_all(&home);
118}
examples/02_example_from_tantivy.rs (line 43)
33fn main() {
34    let home = ".store".to_string();
35    let name = "tantivy".to_string();
36
37    // Mostly empty but can be a real flat struct
38    let data = OldMan::default();
39
40    // Prepare the builder instance
41    let mut builder = SurferBuilder::default();
42    // By default everything goes to directory indexes
43    builder.set_home(&home);
44    builder.add_struct(name.clone(), &data);
45
46    // Make the Surfer
47    let mut surfer = Surfer::try_from(builder).unwrap();
48
49    // Prepare your data or get it from somewhere
50    let title = "The Old Man and the Sea".to_string();
51    let body = "He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish.".to_string();
52    let old_man = OldMan::new(title, body);
53
54    // Insert the data so that store as only one document
55    let _ = surfer.insert_struct(&name, &old_man).unwrap();
56    println!("Inserting document: 1");
57
58    // Give some time to indexing to complete
59    block_thread(2);
60
61    // Lets query our one document
62    let query = "sea whale";
63    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
64    // Check one document
65    println!("Total documents found: {}", computed.len());
66    assert_eq!(computed, vec![old_man.clone()]);
67
68    // Insert the data so that store as two document
69    let _ = surfer.insert_struct(&name, &old_man).unwrap();
70    println!("Inserting document: 1");
71
72    // Give some time to indexing to complete
73    block_thread(2);
74
75    // Lets query again for two documents
76    let query = "sea whale";
77    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
78    // Check two documents
79    println!("Total documents found: {}", computed.len());
80    assert_eq!(computed, vec![old_man.clone(), old_man.clone()]);
81
82    // Lets add 100 more documents
83    let mut i = 0;
84    let mut documents = Vec::with_capacity(50);
85    while i < 50 {
86        documents.push(old_man.clone());
87        i = i + 1;
88    };
89    let _ = surfer.insert_structs(&name, &documents).unwrap();
90    println!("Inserting document: 50");
91
92    // Give some time to indexing to complete
93    block_thread(3);
94
95    // Lets query again for to get first 10 only
96    let query = "sea whale";
97    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
98    // Check 10 documents
99    println!("Total documents found: {} due to default limit = 10", computed.len());
100    assert_eq!(computed.len(), 10);
101
102    // Lets query again for to get first 10 only
103    let query = "sea whale";
104    let computed = surfer.read_structs::<OldMan>(&name, query, Some(100), None).unwrap().unwrap();
105    // Check 10 documents
106    println!("Total documents found: {} with limit = 100", computed.len());
107    assert_eq!(computed.len(), 52);
108
109    // Clean-up
110    let path = surfer.which_index(&name).unwrap();
111    let _ = remove_dir_all(&path);
112    let _ = remove_dir_all(&home);
113}
examples/01_helloworld.rs (line 50)
42fn main() {
43    // Specify home location for indexes
44    let home = ".store".to_string();
45    // Specify index name
46    let index_name = "test_user_info".to_string();
47
48    // Prepare builder
49    let mut builder = SurferBuilder::default();
50    builder.set_home(&home);
51
52    let data = UserInfo::default();
53    builder.add_struct(index_name.clone(), &data);
54
55    // Prepare Surfer
56    let mut surfer = Surfer::try_from(builder).unwrap();
57
58    // Prepare data to insert & search
59
60    // User 1: John Doe
61    let first = "John".to_string();
62    let last = "Doe".to_string();
63    let age = 20u8;
64    let john_doe = UserInfo::new(first, last, age);
65
66    // User 2: Jane Doe
67    let first = "Jane".to_string();
68    let last = "Doe".to_string();
69    let age = 18u8;
70    let jane_doe = UserInfo::new(first, last, age);
71
72    // User 3: Jonny Doe
73    let first = "Jonny".to_string();
74    let last = "Doe".to_string();
75    let age = 10u8;
76    let jonny_doe = UserInfo::new(first, last, age);
77
78    // User 4: Jinny Doe
79    let first = "Jinny".to_string();
80    let last = "Doe".to_string();
81    let age = 10u8;
82    let jinny_doe = UserInfo::new(first, last, age);
83
84    // Writing structs
85
86    // Option 1: One struct at a time
87    let _ = surfer.insert_struct(&index_name, &john_doe).unwrap();
88    let _ = surfer.insert_struct(&index_name, &jane_doe).unwrap();
89
90    // Option 2: Write all structs together
91    let users = vec![jonny_doe.clone(), jinny_doe.clone()];
92    let _ = surfer.insert_structs(&index_name, &users).unwrap();
93
94    block_thread(1);
95
96    // Reading structs
97
98    // Option 1: Full text search
99    let expected = vec![john_doe.clone()];
100    let computed = surfer.read_all_structs::<UserInfo>(&index_name, "John").unwrap().unwrap();
101    assert_eq!(expected, computed);
102
103    let mut expected = vec![john_doe.clone(), jane_doe.clone(), jonny_doe.clone(), jinny_doe.clone()];
104    expected.sort();
105    let mut computed = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
106    computed.sort();
107    assert_eq!(expected, computed);
108
109    // Option 2: Term search
110    let mut expected = vec![jonny_doe.clone(), jinny_doe.clone()];
111    expected.sort();
112    let mut computed = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
113    computed.sort();
114    assert_eq!(expected, computed);
115
116    // Delete structs
117
118    // Option 1: Delete based on all text fields
119    // Before delete
120    let before = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
121    let before: HashSet<UserInfo> = HashSet::from_iter(before.into_iter());
122
123    // Delete any occurrence of John (Actual call to delete)
124    surfer.delete_structs(&index_name, "john").unwrap();
125
126    // After delete
127    let after = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
128    let after: HashSet<UserInfo> = HashSet::from_iter(after.into_iter());
129    // Check difference
130    let computed: Vec<UserInfo> = before.difference(&after).map(|e| e.clone()).collect();
131    // Only John should be deleted
132    let expected = vec![john_doe];
133    assert_eq!(expected, computed);
134
135    // Option 2: Delete based on a specific field
136    // Before delete
137    let before = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
138    let before: HashSet<UserInfo> = HashSet::from_iter(before.into_iter());
139
140    // Delete any occurrence where age = 10 (Actual call to delete)
141    surfer.delete_structs_by_field(&index_name, "age", "10").unwrap();
142
143    // After delete
144    let after = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
145    let after: HashSet<UserInfo> = HashSet::from_iter(after.into_iter());
146    // Check difference
147    let mut computed: Vec<UserInfo> = before.difference(&after).map(|e| e.clone()).collect();
148    computed.sort();
149    // Both Jonny & Jinny should be deleted
150    let mut expected = vec![jonny_doe, jinny_doe];
151    expected.sort();
152    assert_eq!(expected, computed);
153
154
155    // Clean-up
156    let path = surfer.which_index(&index_name).unwrap();
157    let _ = remove_dir_all(&path);
158    let _ = remove_dir_all(&home);
159}
Source

pub fn add_schema(&mut self, name: String, schema: SurferSchema)

Add a schema

Source

pub fn add_struct<T: Serialize>(&mut self, name: String, data: &T)

Add a serializable rust struct panics otherwise

Examples found in repository?
examples/03_fuzzy_user_name.rs (line 41)
33fn main() {
34    let home = ".store".to_string();
35    let name = "fuzzy".to_string();
36
37    let mut builder = SurferBuilder::default();
38    builder.set_home(&home);
39
40    let data = User::default();
41    builder.add_struct(name.clone(), &data);
42
43    let mut surfer = Surfer::try_from(builder).unwrap();
44
45    let first = "John".to_string();
46    let last = "Doe".to_string();
47    let john_doe = User::new(first, last);
48
49    let first = "Jane".to_string();
50    let last = "Doe".to_string();
51    let jane_doe = User::new(first, last);
52
53    let users = vec![john_doe.clone(), jane_doe.clone()];
54    let _ = surfer.insert_structs(&name, &users).unwrap();
55    println!("===========================");
56    println!("Insert: John & Jane Doe");
57    println!("---------------------------");
58    println!("{:#?}", users);
59    println!("---------------------------");
60
61    block_thread(2);
62
63    let query = "deo";
64    let mut computed = surfer.read_structs::<User>(&name, query, Some(100), None).unwrap().unwrap();
65    computed.sort();
66    let mut expected = vec![];
67    expected.sort();
68    assert_eq!(computed, expected);
69
70    println!("====================================");
71    println!("Incorrect Query: '{}' Select: None", query);
72    println!("------------------------------------");
73    println!("{:#?}", computed);
74    println!("------------------------------------");
75
76    let fuzz = FuzzyWord::default();
77    let mod_query = fuzz.lookup(query);
78    assert!(mod_query.is_some());
79    let adjusted = mod_query.unwrap();
80    assert!(adjusted.len() >= 1);
81    let adjusted = adjusted.get(0).unwrap();
82    let mut computed = surfer.read_structs::<User>(&name, adjusted, Some(100), None).unwrap().unwrap();
83    computed.sort();
84    let mut expected = vec![john_doe.clone(), jane_doe.clone()];
85    expected.sort();
86    assert_eq!(computed, expected);
87
88    println!("====================================");
89    println!("Adjusted Query: '{}' Select: Jane & John Doe", adjusted);
90    println!("------------------------------------");
91    println!("{:#?}", computed);
92    println!("------------------------------------");
93
94
95    // Clean-up
96    let path = surfer.which_index(&name).unwrap();
97    let _ = remove_dir_all(&path);
98    let _ = remove_dir_all(&home);
99}
More examples
Hide additional examples
examples/00_usage.rs (line 51)
40fn main() {
41    // Specify home location for indexes
42    let home = ".store".to_string();
43    // Specify index name
44    let index_name = "usage".to_string();
45
46    // Prepare builder
47    let mut builder = SurferBuilder::default();
48    builder.set_home(&home);
49
50    let data = UserInfo::default();
51    builder.add_struct(index_name.clone(), &data);
52
53    // Prepare Surf
54    let mut surf = Surf::try_from(builder).unwrap();
55
56    // Prepare data to insert & search
57
58    // User 1: John Doe
59    let first = "John".to_string();
60    let last = "Doe".to_string();
61    let age = 20u8;
62    let john_doe = UserInfo::new(first, last, age);
63
64    // User 2: Jane Doe
65    let first = "Jane".to_string();
66    let last = "Doe".to_string();
67    let age = 18u8;
68    let jane_doe = UserInfo::new(first, last, age);
69
70    // See examples for more options
71    let users = vec![john_doe.clone(), jane_doe.clone()];
72    let _ = surf.insert(&index_name, &users).unwrap();
73
74    block_thread(1);
75
76    // See examples for more options
77    // Similar to SELECT * FROM users WHERE (age = 20 AND last = "Doe") OR (first = "Jane")
78    let conditions = vec![
79        OrCondition::new(
80            // (age = 20 AND last = "Doe")
81            vec![
82                AndCondition::new("age".to_string(), "20".to_string()),
83                AndCondition::new("last".to_string(), "doe".to_string())
84            ]),
85        OrCondition::new(
86            // (first = "Jane")
87            vec![
88                AndCondition::new("first".to_string(), "jane".to_string())
89            ])
90    ];
91
92    // Validate John and Jane Doe
93    let mut computed = surf.select::<UserInfo>(&index_name, &conditions).unwrap().unwrap();
94    let mut expected = vec![john_doe.clone(), jane_doe.clone(), ];
95    expected.sort();
96    computed.sort();
97    assert_eq!(expected, computed);
98
99    // Validated John's record - Alternate shortcut for query using one field only
100    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
101    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
102    assert_eq!(vec![john_doe], computed);
103
104    // Delete John's record
105    let result = surf.delete(&index_name, "age", "20");
106    assert!(result.is_ok());
107
108    // John's was removed
109    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
110    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
111    assert!(computed.is_empty());
112
113
114    // Clean-up
115    let path = surf.which_index(&index_name).unwrap();
116    let _ = remove_dir_all(&path);
117    let _ = remove_dir_all(&home);
118}
examples/02_example_from_tantivy.rs (line 44)
33fn main() {
34    let home = ".store".to_string();
35    let name = "tantivy".to_string();
36
37    // Mostly empty but can be a real flat struct
38    let data = OldMan::default();
39
40    // Prepare the builder instance
41    let mut builder = SurferBuilder::default();
42    // By default everything goes to directory indexes
43    builder.set_home(&home);
44    builder.add_struct(name.clone(), &data);
45
46    // Make the Surfer
47    let mut surfer = Surfer::try_from(builder).unwrap();
48
49    // Prepare your data or get it from somewhere
50    let title = "The Old Man and the Sea".to_string();
51    let body = "He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish.".to_string();
52    let old_man = OldMan::new(title, body);
53
54    // Insert the data so that store as only one document
55    let _ = surfer.insert_struct(&name, &old_man).unwrap();
56    println!("Inserting document: 1");
57
58    // Give some time to indexing to complete
59    block_thread(2);
60
61    // Lets query our one document
62    let query = "sea whale";
63    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
64    // Check one document
65    println!("Total documents found: {}", computed.len());
66    assert_eq!(computed, vec![old_man.clone()]);
67
68    // Insert the data so that store as two document
69    let _ = surfer.insert_struct(&name, &old_man).unwrap();
70    println!("Inserting document: 1");
71
72    // Give some time to indexing to complete
73    block_thread(2);
74
75    // Lets query again for two documents
76    let query = "sea whale";
77    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
78    // Check two documents
79    println!("Total documents found: {}", computed.len());
80    assert_eq!(computed, vec![old_man.clone(), old_man.clone()]);
81
82    // Lets add 100 more documents
83    let mut i = 0;
84    let mut documents = Vec::with_capacity(50);
85    while i < 50 {
86        documents.push(old_man.clone());
87        i = i + 1;
88    };
89    let _ = surfer.insert_structs(&name, &documents).unwrap();
90    println!("Inserting document: 50");
91
92    // Give some time to indexing to complete
93    block_thread(3);
94
95    // Lets query again for to get first 10 only
96    let query = "sea whale";
97    let computed = surfer.read_structs::<OldMan>(&name, query, None, None).unwrap().unwrap();
98    // Check 10 documents
99    println!("Total documents found: {} due to default limit = 10", computed.len());
100    assert_eq!(computed.len(), 10);
101
102    // Lets query again for to get first 10 only
103    let query = "sea whale";
104    let computed = surfer.read_structs::<OldMan>(&name, query, Some(100), None).unwrap().unwrap();
105    // Check 10 documents
106    println!("Total documents found: {} with limit = 100", computed.len());
107    assert_eq!(computed.len(), 52);
108
109    // Clean-up
110    let path = surfer.which_index(&name).unwrap();
111    let _ = remove_dir_all(&path);
112    let _ = remove_dir_all(&home);
113}
examples/01_helloworld.rs (line 53)
42fn main() {
43    // Specify home location for indexes
44    let home = ".store".to_string();
45    // Specify index name
46    let index_name = "test_user_info".to_string();
47
48    // Prepare builder
49    let mut builder = SurferBuilder::default();
50    builder.set_home(&home);
51
52    let data = UserInfo::default();
53    builder.add_struct(index_name.clone(), &data);
54
55    // Prepare Surfer
56    let mut surfer = Surfer::try_from(builder).unwrap();
57
58    // Prepare data to insert & search
59
60    // User 1: John Doe
61    let first = "John".to_string();
62    let last = "Doe".to_string();
63    let age = 20u8;
64    let john_doe = UserInfo::new(first, last, age);
65
66    // User 2: Jane Doe
67    let first = "Jane".to_string();
68    let last = "Doe".to_string();
69    let age = 18u8;
70    let jane_doe = UserInfo::new(first, last, age);
71
72    // User 3: Jonny Doe
73    let first = "Jonny".to_string();
74    let last = "Doe".to_string();
75    let age = 10u8;
76    let jonny_doe = UserInfo::new(first, last, age);
77
78    // User 4: Jinny Doe
79    let first = "Jinny".to_string();
80    let last = "Doe".to_string();
81    let age = 10u8;
82    let jinny_doe = UserInfo::new(first, last, age);
83
84    // Writing structs
85
86    // Option 1: One struct at a time
87    let _ = surfer.insert_struct(&index_name, &john_doe).unwrap();
88    let _ = surfer.insert_struct(&index_name, &jane_doe).unwrap();
89
90    // Option 2: Write all structs together
91    let users = vec![jonny_doe.clone(), jinny_doe.clone()];
92    let _ = surfer.insert_structs(&index_name, &users).unwrap();
93
94    block_thread(1);
95
96    // Reading structs
97
98    // Option 1: Full text search
99    let expected = vec![john_doe.clone()];
100    let computed = surfer.read_all_structs::<UserInfo>(&index_name, "John").unwrap().unwrap();
101    assert_eq!(expected, computed);
102
103    let mut expected = vec![john_doe.clone(), jane_doe.clone(), jonny_doe.clone(), jinny_doe.clone()];
104    expected.sort();
105    let mut computed = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
106    computed.sort();
107    assert_eq!(expected, computed);
108
109    // Option 2: Term search
110    let mut expected = vec![jonny_doe.clone(), jinny_doe.clone()];
111    expected.sort();
112    let mut computed = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
113    computed.sort();
114    assert_eq!(expected, computed);
115
116    // Delete structs
117
118    // Option 1: Delete based on all text fields
119    // Before delete
120    let before = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
121    let before: HashSet<UserInfo> = HashSet::from_iter(before.into_iter());
122
123    // Delete any occurrence of John (Actual call to delete)
124    surfer.delete_structs(&index_name, "john").unwrap();
125
126    // After delete
127    let after = surfer.read_all_structs::<UserInfo>(&index_name, "doe").unwrap().unwrap();
128    let after: HashSet<UserInfo> = HashSet::from_iter(after.into_iter());
129    // Check difference
130    let computed: Vec<UserInfo> = before.difference(&after).map(|e| e.clone()).collect();
131    // Only John should be deleted
132    let expected = vec![john_doe];
133    assert_eq!(expected, computed);
134
135    // Option 2: Delete based on a specific field
136    // Before delete
137    let before = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
138    let before: HashSet<UserInfo> = HashSet::from_iter(before.into_iter());
139
140    // Delete any occurrence where age = 10 (Actual call to delete)
141    surfer.delete_structs_by_field(&index_name, "age", "10").unwrap();
142
143    // After delete
144    let after = surfer.read_all_structs_by_field::<UserInfo>(&index_name, "age", "10").unwrap().unwrap();
145    let after: HashSet<UserInfo> = HashSet::from_iter(after.into_iter());
146    // Check difference
147    let mut computed: Vec<UserInfo> = before.difference(&after).map(|e| e.clone()).collect();
148    computed.sort();
149    // Both Jonny & Jinny should be deleted
150    let mut expected = vec![jonny_doe, jinny_doe];
151    expected.sort();
152    assert_eq!(expected, computed);
153
154
155    // Clean-up
156    let path = surfer.which_index(&index_name).unwrap();
157    let _ = remove_dir_all(&path);
158    let _ = remove_dir_all(&home);
159}

Trait Implementations§

Source§

impl Clone for SurferBuilder

Source§

fn clone(&self) -> SurferBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SurferBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SurferBuilder

Default impl to get things going

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for SurferBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SurferBuilder

Source§

fn eq(&self, other: &SurferBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<SurferBuilder> for Surf

Source§

type Error = IndexError

The type returned in the event of a conversion error.
Source§

fn try_from(builder: SurferBuilder) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<SurferBuilder> for Surfer

Source§

type Error = IndexError

The type returned in the event of a conversion error.
Source§

fn try_from(builder: SurferBuilder) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for SurferBuilder

Source§

impl StructuralPartialEq for SurferBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Erased for T

Source§

impl<T> Fruit for T
where T: Send + Downcast,