Skip to content

Commit 778b699

Browse files
authored
Add suggest to search result (#617)
## What does this PR do? Add support for ES suggesters (`suggest` keyword) See also kuzzleio/kuzzle#2019 ### Other changes - reduce the bundle size by ignoring node packages for the web build `230KB => 137KB` (fix #616)
1 parent c86a490 commit 778b699

File tree

18 files changed

+374
-188
lines changed

18 files changed

+374
-188
lines changed

doc/7/core-classes/search-result/properties/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ order: 100
1111
| Property | Type | Description |
1212
|--- |--- |--- |
1313
| `aggregations` | <pre>object</pre> | Search aggregations (can be undefined) |
14+
| `fetched` | <pre>number</pre> | Number of retrieved items so far |
1415
| `hits` | <pre>object[]</pre> | Page results |
16+
| `suggest` | <pre>number</pre> | [Suggesters](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-suggesters.html) results <SinceBadge version="auto-version"/> |
1517
| `total` | <pre>number</pre> | Total number of items that _can_ be retrieved |
16-
| `fetched` | <pre>number</pre> | Number of retrieved items so far |
1718

1819
### hits
1920

package-lock.json

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:lint:ts:fix": "eslint ./src --ext .ts --config .eslintrc-ts.json --fix",
3030
"build": "npm run build-ts && node build.js",
3131
"build-ts": "tsc --build tsconfig.json",
32-
"clean": "npm run build-ts | grep TSFILE | cut -d' ' -f 2 | xargs rm",
32+
"clean": "touch index.ts && npm run build-ts | grep TSFILE | cut -d' ' -f 2 | xargs rm",
3333
"dev": "node -r ts-node/register ",
3434
"doc": "docker-compose -f doc/docker-compose.yml up",
3535
"doc-testing": "bash .ci/test-docs.sh",
@@ -77,7 +77,8 @@
7777
"ts-node": "^9.1.1",
7878
"typescript": "^4.1.3",
7979
"url": "^0.11.0",
80-
"webpack": "^5.18.0"
80+
"webpack": "^5.18.0",
81+
"webpack-cli": "^4.5.0"
8182
},
8283
"engines": {
8384
"node": ">= 10.13.0"

src/core/searchResult/Document.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export class DocumentSearchResult extends SearchResultBase<DocumentHit> {
66
* @param {Kuzzle} kuzzle
77
* @param {object} query
88
* @param {object} options
9-
* @param {object} response
9+
* @param {object} result
1010
*/
11-
constructor (kuzzle, query, options, response) {
12-
super(kuzzle, query, options, response);
11+
constructor (kuzzle, query, options, result) {
12+
super(kuzzle, query, options, result);
1313

1414
this._searchAction = 'search';
1515
this._scrollAction = 'scroll';

src/core/searchResult/Profile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Profile } from '../security/Profile';
22
import { SearchResultBase } from './SearchResultBase';
33

44
export class ProfileSearchResult extends SearchResultBase<Profile> {
5-
constructor (kuzzle, request, options, response) {
6-
super(kuzzle, request, options, response);
5+
constructor (kuzzle, request, options, result) {
6+
super(kuzzle, request, options, result);
77

88
this._searchAction = 'searchProfiles';
99
this._scrollAction = 'scrollProfiles';
10-
this.hits = response.hits.map(hit => (
10+
this.hits = result.hits.map(hit => (
1111
new Profile(this._kuzzle, hit._id, hit._source)
1212
));
1313
}
@@ -19,7 +19,7 @@ export class ProfileSearchResult extends SearchResultBase<Profile> {
1919
return null;
2020
}
2121

22-
nextSearchResult.hits = nextSearchResult._response.hits.map(hit => (
22+
nextSearchResult.hits = nextSearchResult._result.hits.map(hit => (
2323
new Profile(nextSearchResult._kuzzle, hit._id, hit._source)
2424
));
2525

src/core/searchResult/Role.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { SearchResultBase } from './SearchResultBase';
33

44
export class RoleSearchResult extends SearchResultBase<Role> {
55

6-
constructor (kuzzle, query, options, response) {
7-
super(kuzzle, query, options, response);
6+
constructor (kuzzle, query, options, result) {
7+
super(kuzzle, query, options, result);
88

99
this._searchAction = 'searchRoles';
1010
this._scrollAction = null; // scrollRoles action does not exists in Kuzzle API.
1111

12-
this.hits = this._response.hits.map(hit => (
12+
this.hits = this._result.hits.map(hit => (
1313
new Role(this._kuzzle, hit._id, hit._source.controllers)
1414
));
1515
}
@@ -27,7 +27,7 @@ export class RoleSearchResult extends SearchResultBase<Role> {
2727
return null;
2828
}
2929

30-
nextSearchResult.hits = nextSearchResult._response.hits.map(hit => (
30+
nextSearchResult.hits = nextSearchResult._result.hits.map(hit => (
3131
new Role(nextSearchResult._kuzzle, hit._id, hit._source.controllers)
3232
));
3333

0 commit comments

Comments
 (0)