1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate thiserror;
extern crate wapc_guest as guest;
use crate::{implement_ext_func, BitcodeContext};
use guest::CallResult;
use serde_json::{json, Value};
use std::str;
impl<'a> BitcodeContext {
/// new_index_builder Creates a new index builder
/// storing the resultant blob in a fabric part and returning the part hash in the body of an http response
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L85)
///
pub fn new_index_builder(&'a mut self, _v: serde_json::Value) -> CallResult {
let method = "NewIndexBuilder";
let vp = json!({});
let impl_result = self.call_function(method, vp, "search")?;
let id = self.request.id.clone();
self.make_success_bytes(&impl_result, &id)
}
/// archive_index_to_part Uses the index constructed in the fabric directory to form a compressed tar
/// storing the resultant blob in a fabric part and returning the part hash
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L121)
///
pub fn archive_index_to_part(&'a self, dir: &str) -> CallResult {
self.call_function("ArchiveIndexToPart", json!({ "directory": dir }), "search")
}
/// restore_index_from_part Extract the part using the supplied part hash restore an archived tantivy index locating the resultant
/// in a directory on the local node.
/// # Arguments
/// * `content_hash` : &str the content object hash
/// * `part_hash` : &str the part hash returned from [BitcodeContext::archive_index_to_part]
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L190)
///
pub fn restore_index_from_part(&'a self, content_hash: &str, part_hash: &str) -> CallResult {
self.call_function(
"RestoreIndexFromPart",
json!({"content-hash" : content_hash, "part-hash": part_hash}),
"search",
)
}
/// query_parser_parse_query Queries the index using the assoicated index query context
///
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/searcher.rs#L32)
///
pub fn query_parser_parse_query(&'a self, query: &str) -> CallResult {
self.call_function("QueryParserParseQuery", json!({ "query": query }), "search")
}
implement_ext_func!(
/// builder_add_text_field adds a new text field to a Tantivy index
/// # Arguments
/// * `v` : a JSON Value
/// ```
/// use serde_json::json;
///
///fn do_something<'s>(bcc: &'s elvwasm::BitcodeContext) -> wapc_guest::CallResult {
/// let v = json!({
/// "name": "title",
/// "type": 1,
/// "stored": true,
/// });
/// bcc.builder_add_text_field(Some(v))
/// }
/// ```
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L196)
///
builder_add_text_field,
"BuilderAddTextField",
"search"
);
implement_ext_func!(
/// builder_build builds the new Index
/// Arguments None
/// ```
/// use serde_json::json;
///
///
///fn do_something<'s>(bcc: &'s elvwasm::BitcodeContext) -> wapc_guest::CallResult {
/// bcc.builder_build(None)
/// }
/// ```
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L201)
///
builder_build,
"BuilderBuild",
"search"
);
implement_ext_func!(
/// builder_create_index create an index from an existing dir
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L202)
///
builder_create_index,
"BuilderCreateIndex",
"search"
);
implement_ext_func!(
/// document_create create a new document for a given Index
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L107)
///
document_create,
"DocumentCreate",
"search"
);
implement_ext_func!(
/// document_add_text add text to a given document
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L115)
///
document_add_text,
"DocumentAddText",
"search"
);
implement_ext_func!(
/// document_create_index creates an index given a set of documents
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L117)
///
document_create_index,
"DocumentCreateIndex",
"search"
);
implement_ext_func!(
/// index_create_writer creates an index writer
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L118)
///
index_create_writer,
"IndexCreateWriter",
"search"
);
implement_ext_func!(
/// index_add_document adds a document to the writer
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L119)
///
index_add_document,
"IndexWriterAddDocument",
"search"
);
implement_ext_func!(
/// index_writer_commit commits the index
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L120)
///
index_writer_commit,
"IndexWriterCommit",
"search"
);
implement_ext_func!(
/// index_reader_builder_create creates a new reader builder on an index
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L203)
///
index_reader_builder_create,
"IndexReaderBuilderCreate",
"search"
);
implement_ext_func!(
/// index_reader_searcher creates a new query parser for the index
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/lib.rs#L204)
///
index_reader_searcher,
"IndexReaderSearcher",
"search"
);
implement_ext_func!(
/// reader_builder_query_parser_create creates a ReaderBuilder from a QueryParser
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/searcher.rs#L28)
///
reader_builder_query_parser_create,
"ReaderBuilderQueryParserCreate",
"search"
);
implement_ext_func!(
/// query_parser_for_index executes ForIndex on the QueryParser
/// # Arguments
/// * `v` : a JSON Value
/// ```
/// fn do_something<'s>(bcc: &'s elvwasm::BitcodeContext) -> wapc_guest::CallResult {
/// let v = serde_json::from_str(r#"{
/// "fields" : ["field1", "field2"]
/// }
/// }"#).unwrap();
/// bcc.query_parser_for_index(v)
/// }
/// ```
/// # Returns
/// * slice of [u8]
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/searcher.rs#L30)
///
query_parser_for_index,
"QueryParserForIndex",
"search"
);
implement_ext_func!(
/// query_parser_search searches the given QueryParser for the term
///
/// [Example](https://github.com/eluv-io/elv-wasm/blob/d261ece2140e5fc498edc470c6495065d1643b14/samples/search/src/searcher.rs#L34)
///
query_parser_search,
"QueryParserSearch",
"search"
);
}