@outliant/sunrise-utils 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/helpers/searchFilter.js +28 -18
- package/lib/projectPipeline.js +18 -9
- package/package.json +1 -1
- package/test/lib/projectPipeline.spec.js +91 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [1.3.6](https://github.com/outliant/sunrise-utils/compare/1.3.5...1.3.6)
|
|
8
|
+
|
|
9
|
+
- chore: update project global search #86b428rnf [`#45`](https://github.com/outliant/sunrise-utils/pull/45)
|
|
10
|
+
|
|
11
|
+
#### [1.3.5](https://github.com/outliant/sunrise-utils/compare/1.3.4...1.3.5)
|
|
12
|
+
|
|
13
|
+
> 14 March 2025
|
|
14
|
+
|
|
15
|
+
- chore: global search updates #86b428rnf [`#44`](https://github.com/outliant/sunrise-utils/pull/44)
|
|
16
|
+
- chore(release): 1.3.5 [`18aa190`](https://github.com/outliant/sunrise-utils/commit/18aa190de0982257a215fa3060f1158b47269fed)
|
|
17
|
+
|
|
7
18
|
#### [1.3.4](https://github.com/outliant/sunrise-utils/compare/1.3.3...1.3.4)
|
|
8
19
|
|
|
20
|
+
> 12 March 2025
|
|
21
|
+
|
|
22
|
+
- chore(release): 1.3.4 [`d54041f`](https://github.com/outliant/sunrise-utils/commit/d54041fd7a9818598f29c9e1e1a04465d4ac8f89)
|
|
9
23
|
- chore: minor change [`d76dce2`](https://github.com/outliant/sunrise-utils/commit/d76dce28e644091321aef72bd68cc853a6e1b1e4)
|
|
10
24
|
|
|
11
25
|
#### [1.3.3](https://github.com/outliant/sunrise-utils/compare/1.3.2...1.3.3)
|
package/helpers/searchFilter.js
CHANGED
|
@@ -2,7 +2,7 @@ const { validate: isUuid } = require('uuid');
|
|
|
2
2
|
const { escapeElasticQuery } = require('./es');
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
|
|
5
|
-
module.exports = (query = {}, searchFields = []) => {
|
|
5
|
+
module.exports = (query = {}, searchFields = [], isGlobalSearch = false) => {
|
|
6
6
|
const search = query.search;
|
|
7
7
|
let searchString = search.trim();
|
|
8
8
|
|
|
@@ -19,27 +19,37 @@ module.exports = (query = {}, searchFields = []) => {
|
|
|
19
19
|
const localFields = searchFields.filter((x) => x !== '_id' && !isUuid(x));
|
|
20
20
|
|
|
21
21
|
if (searchFields.includes('_id')) {
|
|
22
|
-
should.push(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
should.push(
|
|
23
|
+
isGlobalSearch
|
|
24
|
+
? {
|
|
25
|
+
terms: {
|
|
26
|
+
_id: _.split(searchString, ' ') || []
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
: {
|
|
30
|
+
term: {
|
|
31
|
+
_id: {
|
|
32
|
+
value: searchString
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (!isGlobalSearch) {
|
|
40
|
+
/**
|
|
41
|
+
* For case insensitive id search with hyphen
|
|
42
|
+
*/
|
|
43
|
+
_.split(search, '-').forEach(keyword => {
|
|
44
|
+
should.push({
|
|
45
|
+
wildcard: {
|
|
46
|
+
id: {
|
|
47
|
+
value: `*${keyword}*`
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
|
-
}
|
|
50
|
+
});
|
|
41
51
|
});
|
|
42
|
-
}
|
|
52
|
+
}
|
|
43
53
|
|
|
44
54
|
if (localFields.length > 0) {
|
|
45
55
|
if (isQueryQuoteWrapped) {
|
package/lib/projectPipeline.js
CHANGED
|
@@ -17,7 +17,8 @@ class ProjectPipeline {
|
|
|
17
17
|
departmentId,
|
|
18
18
|
filters = [],
|
|
19
19
|
query = {},
|
|
20
|
-
searchFields = []
|
|
20
|
+
searchFields = [],
|
|
21
|
+
isGlobalSearch = false
|
|
21
22
|
) {
|
|
22
23
|
const mustQuery = [
|
|
23
24
|
{
|
|
@@ -30,17 +31,25 @@ class ProjectPipeline {
|
|
|
30
31
|
];
|
|
31
32
|
|
|
32
33
|
if (departmentId) {
|
|
33
|
-
mustQuery.push(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
mustQuery.push(
|
|
35
|
+
Array.isArray(departmentId)
|
|
36
|
+
? {
|
|
37
|
+
terms: {
|
|
38
|
+
department_id: departmentId
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
: {
|
|
42
|
+
term: {
|
|
43
|
+
department_id: {
|
|
44
|
+
value: departmentId
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
if (query.search && query.search.length > 0) {
|
|
43
|
-
const should = searchFilter(query, searchFields);
|
|
52
|
+
const should = searchFilter(query, searchFields, isGlobalSearch);
|
|
44
53
|
|
|
45
54
|
if (should.length > 0) {
|
|
46
55
|
mustQuery.push({
|
package/package.json
CHANGED
|
@@ -6,9 +6,10 @@ const { expect } = require('chai');
|
|
|
6
6
|
const projectPipeline = require('../../lib/projectPipeline');
|
|
7
7
|
|
|
8
8
|
describe('projectPipeline', function () {
|
|
9
|
+
const ORG_ID = 'orgId';
|
|
10
|
+
const DEPARTMENT_ID = 'department_id';
|
|
11
|
+
|
|
9
12
|
describe('buildFiltersQuery', () => {
|
|
10
|
-
const ORG_ID = 'orgId';
|
|
11
|
-
const DEPARTMENT_ID = 'department_id';
|
|
12
13
|
const entries = [
|
|
13
14
|
{
|
|
14
15
|
search: 'COM-41853',
|
|
@@ -168,7 +169,7 @@ describe('projectPipeline', function () {
|
|
|
168
169
|
];
|
|
169
170
|
|
|
170
171
|
entries.forEach((entry) => {
|
|
171
|
-
it(`it should search Project ID correctly for ${entry.search}`, (
|
|
172
|
+
it(`it should search Project ID correctly for ${entry.search}`, () => {
|
|
172
173
|
const query = {
|
|
173
174
|
search: entry.search
|
|
174
175
|
};
|
|
@@ -178,12 +179,10 @@ describe('projectPipeline', function () {
|
|
|
178
179
|
DEPARTMENT_ID,
|
|
179
180
|
[],
|
|
180
181
|
query,
|
|
181
|
-
['project_id']
|
|
182
|
+
['project_id'],
|
|
182
183
|
);
|
|
183
184
|
|
|
184
185
|
expect(result).to.deep.equal(entry.expected);
|
|
185
|
-
|
|
186
|
-
done();
|
|
187
186
|
});
|
|
188
187
|
});
|
|
189
188
|
});
|
|
@@ -272,5 +271,91 @@ describe('projectPipeline', function () {
|
|
|
272
271
|
}
|
|
273
272
|
});
|
|
274
273
|
});
|
|
274
|
+
|
|
275
|
+
it('should generate es query source params for global search', () => {
|
|
276
|
+
const params = {
|
|
277
|
+
search: '41853 SER-69 COM-69',
|
|
278
|
+
projectSearchFields: [
|
|
279
|
+
'name',
|
|
280
|
+
'id',
|
|
281
|
+
'_id',
|
|
282
|
+
'4ef2760a-083a-466b-b761-667856aeb5ee'
|
|
283
|
+
]
|
|
284
|
+
};
|
|
285
|
+
const query = {
|
|
286
|
+
search: params.search
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const result = projectPipeline.buildFiltersQuery(
|
|
290
|
+
ORG_ID,
|
|
291
|
+
DEPARTMENT_ID,
|
|
292
|
+
[],
|
|
293
|
+
query,
|
|
294
|
+
params.projectSearchFields,
|
|
295
|
+
true
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
expect(result).to.be.deep.equal({
|
|
299
|
+
bool: {
|
|
300
|
+
must: [
|
|
301
|
+
{ term: { organization_id: { value: ORG_ID } } },
|
|
302
|
+
{ term: { department_id: { value: DEPARTMENT_ID } } },
|
|
303
|
+
{
|
|
304
|
+
bool: {
|
|
305
|
+
should: [
|
|
306
|
+
{ terms: { _id: params.search.split(' ') } },
|
|
307
|
+
{ multi_match: { query: params.search, fields: ['name^5', 'id^5'] } },
|
|
308
|
+
{ match_phrase_prefix: { name: params.search } },
|
|
309
|
+
{
|
|
310
|
+
function_score: {
|
|
311
|
+
query: {
|
|
312
|
+
nested: {
|
|
313
|
+
path: 'fields',
|
|
314
|
+
query: {
|
|
315
|
+
bool: {
|
|
316
|
+
must: [
|
|
317
|
+
{ term: { 'fields.id': { value: params.projectSearchFields[3] } } },
|
|
318
|
+
{ match: { 'fields.text.analyzed': { query: params.search, operator: 'or' } } }
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
min_score: 15
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
bool: {
|
|
329
|
+
must: [
|
|
330
|
+
{
|
|
331
|
+
nested: {
|
|
332
|
+
path: 'fields',
|
|
333
|
+
query: {
|
|
334
|
+
bool: {
|
|
335
|
+
must: [
|
|
336
|
+
{ term: { 'fields.id': { value: params.projectSearchFields[3] } } },
|
|
337
|
+
{
|
|
338
|
+
bool: {
|
|
339
|
+
should: [
|
|
340
|
+
{ match: { 'fields.text.analyzed': { query: params.search, operator: 'and' } } },
|
|
341
|
+
{ match_phrase_prefix: { 'fields.text.analyzed': params.search } }
|
|
342
|
+
]
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
275
360
|
});
|
|
276
361
|
});
|