|
50 | 50 | describe('Manual', function() {
|
51 | 51 | describe('test', function() {
|
52 | 52 | it('run manual code samples',async function() {
|
53 |
| - |
| 53 | + var JSONbig = require('json-bigint'); |
54 | 54 | try {
|
55 | 55 | let res = await utilsApi.sql('DROP TABLE IF EXISTS movies');
|
56 | 56 | res = await utilsApi.sql("CREATE TABLE IF NOT EXISTS movies (title text, plot text, _year integer, rating float, cat string, code multi, type_vector float_vector knn_type='hnsw' knn_dims='3' hnsw_similarity='l2' )");
|
57 | 57 |
|
58 | 58 | let docs = [
|
59 |
| - {"insert": {"index" : "movies", "id" : 1, "doc" : {"title" : "Star Trek 2: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2002, "rating": 6.4, "cat": "R", "code": [1,2,3], "type_vector": [0.2, 1.4, -2.3]}}}, |
60 |
| - {"insert": {"index" : "movies", "id" : 2, "doc" : {"title" : "Star Trek 1: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2001, "rating": 6.5, "cat": "PG-13", "code": [1,12,3], "type_vector": [0.8, 0.4, 1.3]}}}, |
61 |
| - {"insert": {"index" : "movies", "id" : 3, "doc" : {"title" : "Star Trek 3: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.6, "cat": "R", "code": [11,2,3], "type_vector": [1.5, -1.0, 1.6]}}}, |
62 |
| - {"insert": {"index" : "movies", "id" : 4, "doc" : {"title" : "Star Trek 4: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.5, "cat": "R", "code": [1,2,4], "type_vector": [0.4, 2.4, 0.9]}}}, |
| 59 | + '{"insert": {"index" : "movies", "id" : 9223372036854775807, "doc" : {"title" : "Star Trek 2: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2002, "rating": 6.4, "cat": "R", "code": [1,2,3], "type_vector": [0.2, 1.4, -2.3]}}}', |
| 60 | + '{"insert": {"index" : "movies", "id" : 2, "doc" : {"title" : "Star Trek 1: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2001, "rating": 6.5, "cat": "PG-13", "code": [1,12,3], "type_vector": [0.8, 0.4, 1.3]}}}', |
| 61 | + '{"insert": {"index" : "movies", "id" : 3, "doc" : {"title" : "Star Trek 3: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.6, "cat": "R", "code": [11,2,3], "type_vector": [1.5, -1.0, 1.6]}}}', |
| 62 | + '{"insert": {"index" : "movies", "id" : 4, "doc" : {"title" : "Star Trek 4: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.5, "cat": "R", "code": [1,2,4], "type_vector": [0.4, 2.4, 0.9]}}}', |
63 | 63 | ];
|
64 |
| - res = await indexApi.bulk(docs.map(e=>JSON.stringify(e)).join('\n')); |
| 64 | + res = await indexApi.bulk(docs.map(e=>JSONbig.stringify(JSONbig.parse(e))).join('\n')); |
65 | 65 |
|
66 | 66 | let search_request = {"index":"movies"};
|
67 | 67 |
|
|
85 | 85 | let sort3 = new Manticoresearch.SortMVA('code', 'desc', 'max');
|
86 | 86 | search_request.sort.push(...[sort2,sort3]);
|
87 | 87 |
|
88 |
| - res = await searchApi.search(search_request); |
| 88 | + res = await searchApi.search(search_request); |
89 | 89 |
|
90 | 90 | search_request.expressions = {'expr': 'min(_year,2900)'};
|
91 | 91 | let expr2 = 'max(_year,2100)';
|
|
104 | 104 | agg2['terms'] = Manticoresearch.AggregationTerms.constructFromObject({field: 'rating'});
|
105 | 105 | search_request.aggs['agg2'] = agg2;
|
106 | 106 |
|
107 |
| - res = await searchApi.search(search_request); |
| 107 | + res = await searchApi.search(search_request); |
108 | 108 |
|
109 | 109 | let compAggTerms1 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: '_year'});
|
110 | 110 | let compAgg1 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms1})
|
|
118 | 118 | res = await searchApi.search(search_request);
|
119 | 119 |
|
120 | 120 | let highlight = new Manticoresearch.Highlight();
|
121 |
| - highlight.fieldnames = ['title']; |
122 |
| - highlight.post_tags = '</post_tag>'; |
| 121 | + highlight.fieldnames = ['title']; |
| 122 | + highlight.post_tags = '</post_tag>'; |
123 | 123 | highlight.encoder = 'default';
|
124 | 124 | highlight.snippet_boundary = 'sentence';
|
125 |
| - search_request.highlight = highlight; |
| 125 | + search_request.highlight = highlight; |
126 | 126 |
|
127 | 127 | res = await searchApi.search(search_request);
|
128 | 128 |
|
|
212 | 212 | res = await searchApi.search(search_request);
|
213 | 213 |
|
214 | 214 | search_request = {"index":"movies"};
|
215 |
| - search_request.knn = new Manticoresearch.KnnQueryByVector( |
216 |
| - "type_vector", |
217 |
| - [1.5, -1.0, 1.6], |
218 |
| - 5, |
219 |
| - ); |
220 |
| - res = await searchApi.search(search_request); |
| 215 | + search_request.knn = new Manticoresearch.KnnQueryByVector( |
| 216 | + "type_vector", |
| 217 | + [1.5, -1.0, 1.6], |
| 218 | + 5, |
| 219 | + ); |
| 220 | + res = await searchApi.search(search_request); |
221 | 221 |
|
222 | 222 | search_request.knn = new Manticoresearch.KnnQueryByDocId(
|
223 |
| - "type_vector", |
224 |
| - 2, |
225 |
| - 5, |
226 |
| - ); |
227 |
| - res = await searchApi.search(search_request); |
228 |
| - |
229 |
| - boolFilter = new Manticoresearch.BoolFilter(); |
230 |
| - boolFilter.must = [ new Manticoresearch.EqualsFilter('id', 3) ]; |
231 |
| - search_request.knn = new Manticoresearch.KnnQueryByVector( |
232 |
| - "type_vector", |
233 |
| - [1.5, -1.0, 1.6], |
234 |
| - 5, |
235 |
| - boolFilter |
236 |
| - ) |
237 |
| - res = await searchApi.search(search_request); |
238 |
| - |
239 |
| - search_request.knn = new Manticoresearch.KnnQueryByDocId( |
240 |
| - "type_vector", |
241 |
| - 2, |
242 |
| - 5, |
243 |
| - boolFilter |
244 |
| - ) |
245 |
| - res = await searchApi.search(search_request); |
| 223 | + "type_vector", |
| 224 | + 2, |
| 225 | + 5, |
| 226 | + ); |
| 227 | + res = await searchApi.search(search_request); |
| 228 | + |
| 229 | + boolFilter = new Manticoresearch.BoolFilter(); |
| 230 | + boolFilter.must = [ new Manticoresearch.EqualsFilter('id', 3) ]; |
| 231 | + search_request.knn = new Manticoresearch.KnnQueryByVector( |
| 232 | + "type_vector", |
| 233 | + [1.5, -1.0, 1.6], |
| 234 | + 5, |
| 235 | + boolFilter |
| 236 | + ); |
| 237 | + res = await searchApi.search(search_request); |
| 238 | + |
| 239 | + search_request.knn = new Manticoresearch.KnnQueryByDocId( |
| 240 | + "type_vector", |
| 241 | + 2, |
| 242 | + 5, |
| 243 | + boolFilter |
| 244 | + ); |
| 245 | + res = await searchApi.search(search_request); |
246 | 246 |
|
247 | 247 | console.log("\nSearch tests finished\n");
|
248 | 248 | } catch (e) {
|
|
0 commit comments