Skip to content

Commit 776c901

Browse files
committed
return heavy results only in tests
1 parent 151776f commit 776c901

File tree

7 files changed

+63
-28
lines changed

7 files changed

+63
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ build/
4343
*.mdb/
4444
imdb.json
4545
imdb2.json
46+
bench/

cpp/itemsjs.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ std::string itemsjs::json_at(string json_path, int i) {
6060
/**
6161
* native version of faceted search
6262
*/
63-
std::tuple<std::string, std::optional<Roaring>, std::optional<Roaring>> itemsjs::search_facets(const char *&index_path, nlohmann::json input, nlohmann::json filters_array, nlohmann::json config, nlohmann::json facets_fields, std::optional<Roaring> query_ids) {
63+
std::tuple<std::string, std::optional<Roaring>, std::optional<Roaring>> itemsjs::search_facets(const char *&index_path, nlohmann::json input, nlohmann::json filters_array, nlohmann::json config, nlohmann::json facets_fields, std::optional<Roaring> query_ids, bool testing = false) {
6464

6565
// @TODO make unordered
6666
std::map<string, std::map<string, Roaring>> filters_indexes;
@@ -238,14 +238,11 @@ std::tuple<std::string, std::optional<Roaring>, std::optional<Roaring>> itemsjs:
238238
}
239239

240240

241-
output["counters"][sv][sv2] = ids.cardinality();
242-
243-
//nlohmann::json lista;
244-
//auto ans = new uint32_t[ids.cardinality()];
245-
//ids.toUint32Array(ans);
246-
241+
if (1) {
242+
output["counters"][sv][sv2] = ids.cardinality();
243+
}
247244

248-
if (true) {
245+
if (testing) {
249246

250247
output["data"][sv][sv2] = nlohmann::json::array();;
251248
for (auto bit_id: ids) {
@@ -998,8 +995,16 @@ Napi::Object itemsjs::SearchFacetsWrapped(const Napi::CallbackInfo& info) {
998995
string name_a(index_name.ToString());
999996
const char *index_path = name_a.c_str();
1000997

998+
999+
bool testing = false;
1000+
Napi::Value testing_value = first.Get("testing");
1001+
1002+
if (testing_value.IsBoolean() and (bool) testing_value.As<Napi::Boolean>() == true) {
1003+
testing = true;
1004+
}
1005+
10011006
Napi::Object obj = Napi::Object::New(env);
1002-
auto [result, ids, not_ids] = itemsjs::search_facets(index_path, input, filters_array, conf, facets_fields, query_ids);
1007+
auto [result, ids, not_ids] = itemsjs::search_facets(index_path, input, filters_array, conf, facets_fields, query_ids, testing);
10031008
obj.Set("raw", result);
10041009

10051010
if (ids) {

cpp/itemsjs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace itemsjs {
1212
std::string hello();
1313
//std::string index(std::string filename);
1414
std::string index(const char *&index_path, std::string json_path, const std::string& json_string, std::vector<std::string> &faceted_fields, std::vector<std::string> &sorting_fields, bool append);
15-
std::tuple<std::string, std::optional<Roaring>, std::optional<Roaring>> search_facets(const char *&index_path, nlohmann::json input, nlohmann::json filters_array, nlohmann::json conf, nlohmann::json facets_fields, std::optional<Roaring> query_ids);
15+
std::tuple<std::string, std::optional<Roaring>, std::optional<Roaring>> search_facets(const char *&index_path, nlohmann::json input, nlohmann::json filters_array, nlohmann::json conf, nlohmann::json facets_fields, std::optional<Roaring> query_ids, bool testing);
1616
std::vector<int> sort_index(const char *&index_path, const Roaring &ids, std::string field, std::string order, int offset, int limit);
1717
void load_sort_index(const char *&index_path, std::vector<std::string> &sorting_fields);
1818
void delete_item(const char *&index_path, int id);

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itemsjs-server-optimized",
3-
"version": "2.1.0",
3+
"version": "2.1.2",
44
"description": "ItemsJS on steroid",
55
"main": "lib/index.js",
66
"scripts": {

src/facets.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ Facets.prototype = {
326326
aggregations: aggregations,
327327
facets_fields, facets_fields,
328328
query_ids: query_ids,
329-
index_path: index_path
329+
index_path: index_path,
330+
testing: data.testing
330331
}
331332

332333
var result;

tests/facetsSpec.js

+43-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ describe('conjunctive search', function() {
5050
}
5151
}
5252

53-
var result = await facets.search_native(INDEX_PATH, input);
53+
var result = await facets.search_native(INDEX_PATH, input, {
54+
testing: true
55+
});
5456

5557
assert.deepEqual(result.data.tags.a, [1, 3, 4]);
5658
assert.deepEqual(result.data.tags.c, [1, 3, 4]);
@@ -72,7 +74,9 @@ describe('conjunctive search', function() {
7274
}
7375
}
7476

75-
var result = await facets.search_native(INDEX_PATH, input);
77+
var result = await facets.search_native(INDEX_PATH, input, {
78+
testing: true
79+
});
7680
assert.deepEqual(result.data.tags.a, [2]);
7781
assert.deepEqual(result.data.tags.e, [2]);
7882
})
@@ -84,7 +88,9 @@ describe('conjunctive search', function() {
8488
}
8589
}
8690

87-
var result = await facets.search_native(INDEX_PATH, input);
91+
var result = await facets.search_native(INDEX_PATH, input, {
92+
testing: true
93+
});
8894

8995
assert.deepEqual(result.data.tags.a, [1, 2, 3, 4]);
9096
assert.deepEqual(result.data.tags.e, [2]);
@@ -95,7 +101,9 @@ describe('conjunctive search', function() {
95101
}
96102
}
97103

98-
var result = await facets.search_native(INDEX_PATH, input);
104+
var result = await facets.search_native(INDEX_PATH, input, {
105+
testing: true
106+
});
99107

100108
assert.deepEqual(result.data.tags.a, [1, 2, 3, 4]);
101109
assert.deepEqual(result.data.tags.e, [2]);
@@ -109,7 +117,9 @@ describe('conjunctive search', function() {
109117
}
110118
}
111119

112-
var result = await facets.search_native(INDEX_PATH, input);
120+
var result = await facets.search_native(INDEX_PATH, input, {
121+
testing: true
122+
});
113123

114124
assert.deepEqual(result.data.tags.a, []);
115125
assert.deepEqual(result.data.tags.e, []);
@@ -124,7 +134,9 @@ describe('conjunctive search', function() {
124134
}
125135
}
126136

127-
var result = await facets.search_native(INDEX_PATH, input);
137+
var result = await facets.search_native(INDEX_PATH, input, {
138+
testing: true
139+
});
128140

129141
assert.deepEqual(result.data.tags.a, [1, 2]);
130142
assert.deepEqual(result.data.tags.e, [2]);
@@ -173,7 +185,9 @@ describe('disjunctive search', function() {
173185
}
174186
}
175187

176-
var result = await facets.search_native(INDEX_PATH, input);
188+
var result = await facets.search_native(INDEX_PATH, input, {
189+
testing: true
190+
});
177191

178192
assert.deepEqual(result.data.tags.a, [1, 2, 3, 4]);
179193
assert.deepEqual(result.data.tags.c, [1, 3, 4]);
@@ -189,7 +203,9 @@ describe('disjunctive search', function() {
189203
}
190204
}
191205

192-
var result = await facets.search_native(INDEX_PATH, input);
206+
var result = await facets.search_native(INDEX_PATH, input, {
207+
testing: true
208+
});
193209

194210
assert.deepEqual(result.data.tags.a, [1, 2, 3, 4]);
195211
assert.deepEqual(result.data.tags.c, [1, 3, 4]);
@@ -244,7 +260,9 @@ describe('disjunctive and conjunctive search', function() {
244260
}
245261
}
246262

247-
var result = await facets.search_native(INDEX_PATH, input);
263+
var result = await facets.search_native(INDEX_PATH, input, {
264+
testing: true
265+
});
248266

249267
assert.deepEqual(result.data.tags.a, [1, 3, 4]);
250268
assert.deepEqual(result.data.tags.e, []);
@@ -261,7 +279,9 @@ describe('disjunctive and conjunctive search', function() {
261279
}
262280
}
263281

264-
var result = await facets.search_native(INDEX_PATH, input);
282+
var result = await facets.search_native(INDEX_PATH, input, {
283+
testing: true
284+
});
265285

266286
assert.deepEqual(result.data.tags.a, [1, 4]);
267287
assert.deepEqual(result.data.tags.c, [1, 4]);
@@ -312,7 +332,9 @@ describe('generates facets crossed with query', function() {
312332
}
313333
}
314334

315-
var result = await facets.search_native(INDEX_PATH, input);
335+
var result = await facets.search_native(INDEX_PATH, input, {
336+
testing: true
337+
});
316338

317339
assert.deepEqual(result.data.tags.a, [1, 3, 4]);
318340
assert.deepEqual(result.data.tags.e, []);
@@ -327,7 +349,7 @@ describe('generates facets crossed with query', function() {
327349

328350
var result = await facets.search_native(INDEX_PATH, input, {
329351
query_ids: new RoaringBitmap32([1]),
330-
test: true
352+
testing: true
331353
});
332354

333355
assert.deepEqual(result.data.tags.a, [1]);
@@ -385,7 +407,9 @@ describe('negative filters', function() {
385407
}
386408
}
387409

388-
var result = await facets.search_native(INDEX_PATH, input);
410+
var result = await facets.search_native(INDEX_PATH, input, {
411+
testing: true
412+
});
389413

390414
assert.deepEqual(result.data.tags.a, [2]);
391415
assert.deepEqual(result.data.tags.c, []);
@@ -425,7 +449,9 @@ describe('small configuration', function() {
425449
}
426450
}
427451

428-
var result = await facets.search_native(INDEX_PATH, input);
452+
var result = await facets.search_native(INDEX_PATH, input, {
453+
testing: true
454+
});
429455
assert.deepEqual(result.data.category.comedy, [2, 3]);
430456
})
431457
})
@@ -454,7 +480,9 @@ describe('no configuration', function() {
454480
}
455481
}
456482

457-
var result = await facets.search_native(INDEX_PATH, input);
483+
var result = await facets.search_native(INDEX_PATH, input, {
484+
testing: true
485+
});
458486

459487
assert.deepEqual(result.data, {});
460488
assert.deepEqual(result.counters, {});

0 commit comments

Comments
 (0)