Skip to content

Commit 974d1dd

Browse files
committed
Fixed the support for bigints
1 parent 2ce6dc0 commit 974d1dd

File tree

4 files changed

+48
-50
lines changed

4 files changed

+48
-50
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"dependencies": {
2121
"superagent": "5.1.0",
22-
"json-bigint": "1.0.0"
22+
"json-bigint": "0.4.0"
2323
},
2424
"devDependencies": {
2525
"inherits": "^2.0.4",

src/ApiClient.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
});
336336
};
337337

338-
exports.JSONbig = require('json-bigint')({ storeAsString: true });
338+
exports.JSONbig = require('json-bigint');
339339

340340
/**
341341
* Deserializes an HTTP response body into a value of the specified type.
@@ -353,11 +353,9 @@
353353
// Use json-bigint for parsing json responses otherwise rely on SuperAgent
354354
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
355355
var data;
356-
if (returnType === Object || typeof returnType === 'object') {
357-
data = exports.JSONbig.parse(response.text);
358-
} else {
359-
data = response.body;
360-
}
356+
357+
data = exports.JSONbig.parse(response.text);
358+
361359
if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) {
362360
// SuperAgent does not always produce a body; use the unparsed response as a fallback
363361
data = response.text;
@@ -465,7 +463,7 @@
465463
if (!request.header['Content-Type']) {
466464
request.type('application/json');
467465
}
468-
request.send(bodyParam);
466+
request.send(typeof bodyParam === 'object' ? exports.JSONbig.stringify(bodyParam) : bodyParam);
469467
}
470468

471469
var accept = this.jsonPreferredMime(accepts);

src/api/SearchApi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* @param {module:model/PercolateRequest} percolateRequest
4848
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SearchResponse} and HTTP response
4949
*/
50-
this.percolateWithHttpInfo = function(index, percolateRequest) {
50+
this.percolateWithHtstringtpInfo = function(index, percolateRequest) {
5151
var postBody = JSON.parse(JSON.stringify(percolateRequest));
5252

5353

@@ -107,7 +107,7 @@
107107
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SearchResponse} and HTTP response
108108
*/
109109
this.searchWithHttpInfo = function(searchRequest) {
110-
var postBody = JSON.parse(JSON.stringify(searchRequest));
110+
var postBody = ApiClient.JSONbig.parse(ApiClient.JSONbig.stringify(searchRequest));
111111

112112

113113
// verify the required parameter 'searchRequest' is set

test/api/Manual.spec.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@
5050
describe('Manual', function() {
5151
describe('test', function() {
5252
it('run manual code samples',async function() {
53-
53+
var JSONbig = require('json-bigint');
5454
try {
5555
let res = await utilsApi.sql('DROP TABLE IF EXISTS movies');
5656
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' )");
5757

5858
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]}}}',
6363
];
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'));
6565

6666
let search_request = {"index":"movies"};
6767

@@ -85,7 +85,7 @@
8585
let sort3 = new Manticoresearch.SortMVA('code', 'desc', 'max');
8686
search_request.sort.push(...[sort2,sort3]);
8787

88-
res = await searchApi.search(search_request);
88+
res = await searchApi.search(search_request);
8989

9090
search_request.expressions = {'expr': 'min(_year,2900)'};
9191
let expr2 = 'max(_year,2100)';
@@ -104,7 +104,7 @@
104104
agg2['terms'] = Manticoresearch.AggregationTerms.constructFromObject({field: 'rating'});
105105
search_request.aggs['agg2'] = agg2;
106106

107-
res = await searchApi.search(search_request);
107+
res = await searchApi.search(search_request);
108108

109109
let compAggTerms1 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: '_year'});
110110
let compAgg1 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms1})
@@ -118,11 +118,11 @@
118118
res = await searchApi.search(search_request);
119119

120120
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>';
123123
highlight.encoder = 'default';
124124
highlight.snippet_boundary = 'sentence';
125-
search_request.highlight = highlight;
125+
search_request.highlight = highlight;
126126

127127
res = await searchApi.search(search_request);
128128

@@ -212,37 +212,37 @@
212212
res = await searchApi.search(search_request);
213213

214214
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);
221221

222222
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);
246246

247247
console.log("\nSearch tests finished\n");
248248
} catch (e) {

0 commit comments

Comments
 (0)