Skip to content

Commit

Permalink
Fixed the support for bigints
Browse files Browse the repository at this point in the history
  • Loading branch information
nick committed May 9, 2024
1 parent 2ce6dc0 commit 974d1dd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"dependencies": {
"superagent": "5.1.0",
"json-bigint": "1.0.0"
"json-bigint": "0.4.0"
},
"devDependencies": {
"inherits": "^2.0.4",
Expand Down
12 changes: 5 additions & 7 deletions src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
});
};

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

/**
* Deserializes an HTTP response body into a value of the specified type.
Expand All @@ -353,11 +353,9 @@
// Use json-bigint for parsing json responses otherwise rely on SuperAgent
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
var data;
if (returnType === Object || typeof returnType === 'object') {
data = exports.JSONbig.parse(response.text);
} else {
data = response.body;
}

data = exports.JSONbig.parse(response.text);

if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) {
// SuperAgent does not always produce a body; use the unparsed response as a fallback
data = response.text;
Expand Down Expand Up @@ -465,7 +463,7 @@
if (!request.header['Content-Type']) {
request.type('application/json');
}
request.send(bodyParam);
request.send(typeof bodyParam === 'object' ? exports.JSONbig.stringify(bodyParam) : bodyParam);
}

var accept = this.jsonPreferredMime(accepts);
Expand Down
4 changes: 2 additions & 2 deletions src/api/SearchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @param {module:model/PercolateRequest} percolateRequest
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SearchResponse} and HTTP response
*/
this.percolateWithHttpInfo = function(index, percolateRequest) {
this.percolateWithHtstringtpInfo = function(index, percolateRequest) {
var postBody = JSON.parse(JSON.stringify(percolateRequest));


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


// verify the required parameter 'searchRequest' is set
Expand Down
80 changes: 40 additions & 40 deletions test/api/Manual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@
describe('Manual', function() {
describe('test', function() {
it('run manual code samples',async function() {

var JSONbig = require('json-bigint');
try {
let res = await utilsApi.sql('DROP TABLE IF EXISTS movies');
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' )");

let docs = [
{"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]}}},
{"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]}}},
{"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]}}},
{"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]}}},
'{"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]}}}',
'{"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]}}}',
'{"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]}}}',
'{"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]}}}',
];
res = await indexApi.bulk(docs.map(e=>JSON.stringify(e)).join('\n'));
res = await indexApi.bulk(docs.map(e=>JSONbig.stringify(JSONbig.parse(e))).join('\n'));

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

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

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

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

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

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

let highlight = new Manticoresearch.Highlight();
highlight.fieldnames = ['title'];
highlight.post_tags = '</post_tag>';
highlight.fieldnames = ['title'];
highlight.post_tags = '</post_tag>';
highlight.encoder = 'default';
highlight.snippet_boundary = 'sentence';
search_request.highlight = highlight;
search_request.highlight = highlight;

res = await searchApi.search(search_request);

Expand Down Expand Up @@ -212,37 +212,37 @@
res = await searchApi.search(search_request);

search_request = {"index":"movies"};
search_request.knn = new Manticoresearch.KnnQueryByVector(
"type_vector",
[1.5, -1.0, 1.6],
5,
);
res = await searchApi.search(search_request);
search_request.knn = new Manticoresearch.KnnQueryByVector(
"type_vector",
[1.5, -1.0, 1.6],
5,
);
res = await searchApi.search(search_request);

search_request.knn = new Manticoresearch.KnnQueryByDocId(
"type_vector",
2,
5,
);
res = await searchApi.search(search_request);

boolFilter = new Manticoresearch.BoolFilter();
boolFilter.must = [ new Manticoresearch.EqualsFilter('id', 3) ];
search_request.knn = new Manticoresearch.KnnQueryByVector(
"type_vector",
[1.5, -1.0, 1.6],
5,
boolFilter
)
res = await searchApi.search(search_request);

search_request.knn = new Manticoresearch.KnnQueryByDocId(
"type_vector",
2,
5,
boolFilter
)
res = await searchApi.search(search_request);
"type_vector",
2,
5,
);
res = await searchApi.search(search_request);
boolFilter = new Manticoresearch.BoolFilter();
boolFilter.must = [ new Manticoresearch.EqualsFilter('id', 3) ];
search_request.knn = new Manticoresearch.KnnQueryByVector(
"type_vector",
[1.5, -1.0, 1.6],
5,
boolFilter
);
res = await searchApi.search(search_request);
search_request.knn = new Manticoresearch.KnnQueryByDocId(
"type_vector",
2,
5,
boolFilter
);
res = await searchApi.search(search_request);

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

0 comments on commit 974d1dd

Please sign in to comment.