@miso.ai/client-sdk-ui 1.12.3 → 1.12.4

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.
Files changed (37) hide show
  1. package/dist/cjs/actor/data.js +15 -11
  2. package/dist/cjs/defaults/ask/controls.js +3 -6
  3. package/dist/cjs/defaults/ask/templates.js +1 -0
  4. package/dist/cjs/defaults/common/templates.js +4 -2
  5. package/dist/cjs/element/container/miso-ask.js +48 -6
  6. package/dist/cjs/element/container/miso-container.js +2 -0
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/cjs/workflow/answer-based.js +2 -88
  9. package/dist/cjs/workflow/ask.js +13 -9
  10. package/dist/cjs/workflow/asks.js +36 -1
  11. package/dist/cjs/workflow/base.js +14 -9
  12. package/dist/cjs/workflow/hybrid-search-answer.js +40 -68
  13. package/dist/cjs/workflow/hybrid-search-views.js +12 -11
  14. package/dist/cjs/workflow/hybrid-search.js +99 -46
  15. package/dist/cjs/workflow/options/auto-query.js +31 -0
  16. package/dist/cjs/workflow/processors.js +107 -0
  17. package/dist/cjs/workflow/search-based.js +16 -30
  18. package/package.json +2 -2
  19. package/src/actor/data.js +10 -7
  20. package/src/defaults/ask/controls.js +3 -6
  21. package/src/defaults/ask/templates.js +1 -1
  22. package/src/defaults/common/templates.js +2 -2
  23. package/src/element/container/miso-ask.js +53 -5
  24. package/src/element/container/miso-container.js +3 -0
  25. package/src/version.js +1 -1
  26. package/src/workflow/answer-based.js +4 -83
  27. package/src/workflow/ask.js +11 -10
  28. package/src/workflow/asks.js +39 -2
  29. package/src/workflow/base.js +13 -9
  30. package/src/workflow/hybrid-search-answer.js +25 -62
  31. package/src/workflow/hybrid-search-views.js +14 -12
  32. package/src/workflow/hybrid-search.js +93 -47
  33. package/src/workflow/options/auto-query.js +36 -2
  34. package/src/workflow/processors.js +86 -2
  35. package/src/workflow/search-based.js +14 -27
  36. package/dist/cjs/workflow/hybrid-search-results.js +0 -87
  37. package/src/workflow/hybrid-search-results.js +0 -91
@@ -1,15 +1,18 @@
1
1
  import { API } from '@miso.ai/commons';
2
- import Workflow from './base.js';
3
2
  import SearchBasedWorkflow from './search-based.js';
4
3
  import AnswerBasedWorkflow from './answer-based.js';
5
4
  import { ROLE, WORKFLOW_CONFIGURABLE } from '../constants.js';
6
5
  import { SearchBoxLayout, TextLayout, HorizontalLayout } from '../layout/index.js';
7
6
  import { compactArticle, compactArticleInfoBlock } from '../layout/templates.js';
8
7
  import HybridSearchAnswer from './hybrid-search-answer.js';
9
- import HybridSearchResults from './hybrid-search-results.js';
10
8
  import HybridSearchViewsActor from './hybrid-search-views.js';
11
9
  import { makeConfigurable } from './options/index.js';
12
10
 
11
+ import { mergeApiPayloads } from '@miso.ai/commons';
12
+ import { STATUS, REQUEST_TYPE } from '../constants.js';
13
+ import { writeMisoIdToSession, writeQuestionSourceToPayload, disableAnswerForNonQueryRequest, carryOverQuestionIdToData, writeAnswerInfoToInteraction } from './processors.js';
14
+ import { makeAutocompletable } from './autocompletable.js';
15
+
13
16
  const DEFAULT_API_OPTIONS = Object.freeze({
14
17
  group: API.GROUP.ASK,
15
18
  name: API.NAME.SEARCH,
@@ -88,7 +91,13 @@ const ROLES_OPTIONS = Object.freeze({
88
91
  }),
89
92
  });
90
93
 
91
- export default class HybridSearch extends Workflow {
94
+ const EXTRA_OPTIONS = Object.freeze({
95
+ api: Object.freeze({
96
+ polling: false,
97
+ }),
98
+ });
99
+
100
+ export default class HybridSearch extends SearchBasedWorkflow {
92
101
 
93
102
  constructor(plugin, client) {
94
103
  super({
@@ -97,41 +106,29 @@ export default class HybridSearch extends Workflow {
97
106
  client,
98
107
  roles: ROLES_OPTIONS,
99
108
  defaults: DEFAULT_OPTIONS,
109
+ extraOptions: EXTRA_OPTIONS,
100
110
  });
101
111
  }
102
112
 
103
113
  _initProperties(args) {
104
114
  super._initProperties(args);
105
- this._subworkflows = [
106
- this._answer = new HybridSearchAnswer(this),
107
- this._results = new HybridSearchResults(this),
108
- ];
115
+ this._initAutocomplete(args);
116
+ this._answer = new HybridSearchAnswer(this);
109
117
  }
110
118
 
111
- _getSubworkflow(name) {
112
- switch (name) {
113
- case 'answer':
114
- return this._answer;
115
- case 'results':
116
- return this._results;
117
- default:
118
- throw new Error(`Invalid subworkflow: ${name}`);
119
- }
120
- }
121
-
122
- _initActors() {
123
- this._views = new HybridSearchViewsActor(this);
124
- }
125
-
126
- _initSession() {
127
- this._results._sessions.restart();
128
- this._answer._sessions.restart();
119
+ _initActors(args) {
120
+ super._initActors(args);
121
+ this._views = new HybridSearchViewsActor({
122
+ results: this._views,
123
+ answer: this._answer._views,
124
+ });
129
125
  }
130
126
 
131
- // configuration //
132
- useLink(fn, options) {
133
- this._answer.useLink(fn, options);
134
- return this;
127
+ restart({ type } = {}) {
128
+ super.restart();
129
+ if (!type || type === REQUEST_TYPE.QUERY) {
130
+ this._answer.restart();
131
+ }
135
132
  }
136
133
 
137
134
  // properties //
@@ -139,46 +136,95 @@ export default class HybridSearch extends Workflow {
139
136
  return this._answer;
140
137
  }
141
138
 
142
- get results() {
143
- return this._results;
144
- }
145
-
146
139
  get questionId() {
147
140
  return this._answer.questionId;
148
141
  }
149
142
 
150
- get filters() {
151
- return this._results._views.filters;
143
+ // query //
144
+ _buildPayload(payload, type) {
145
+ payload = super._buildPayload(payload, type);
146
+ // borrow the work from the sibling
147
+ payload = disableAnswerForNonQueryRequest(payload, type);
148
+ payload = writeQuestionSourceToPayload(payload);
149
+ payload = this._writeQuestionIdToPayload(payload, type);
150
+ if (payload.answer !== false) {
151
+ // uses autoQuery params, so we want to apply to this workflow
152
+ payload = AnswerBasedWorkflow.prototype._writeWikiLinkTemplateToPayload.call(this, payload);
153
+ }
154
+ return payload;
152
155
  }
153
156
 
154
- get autocomplete() {
155
- return this._answer.autocomplete;
157
+ _buildOrderBy(sort) {
158
+ if (!sort) {
159
+ return undefined;
160
+ }
161
+ // works differently than search
162
+ return sort.field;
156
163
  }
157
164
 
158
- // query //
159
- autoQuery(options) {
160
- this._answer.autoQuery(options);
165
+ _writeQuestionIdToPayload(payload, type) {
166
+ if (type === REQUEST_TYPE.QUERY) {
167
+ return payload;
168
+ }
169
+ const question_id = this._answer.questionId;
170
+ if (!question_id) {
171
+ return payload;
172
+ }
173
+ return mergeApiPayloads(payload, {
174
+ metadata: {
175
+ question_id,
176
+ },
177
+ });
178
+ }
179
+
180
+ // data //
181
+ _defaultProcessData(data, oldData) {
182
+ data = super._defaultProcessData(data, oldData);
183
+ writeMisoIdToSession(data);
184
+ return data;
161
185
  }
162
186
 
163
- query(args) {
164
- this._answer.query(args);
187
+ _updateDataInHub(data, oldData) {
188
+ this._dispatchDataToAnswerWorkflow(data);
189
+ data = carryOverQuestionIdToData(data, oldData); // TODO: may as well move to process data
190
+ super._updateDataInHub(data, oldData);
191
+ }
192
+
193
+ _dispatchDataToAnswerWorkflow(data) {
194
+ const { request } = data;
195
+ if (!request) {
196
+ return;
197
+ }
198
+ const { type, payload } = request;
199
+ if (type !== REQUEST_TYPE.QUERY || !payload || payload.answer === false) {
200
+ return;
201
+ }
202
+ switch (data.status) {
203
+ case STATUS.LOADING:
204
+ // share the loading status with its sibling
205
+ this._answer._doLoading(data);
206
+ break;
207
+ case STATUS.READY:
208
+ // start a query with retrieved question ID, if any
209
+ this._answer._queryWithQuestionId(data);
210
+ break;
211
+ }
165
212
  }
166
213
 
167
214
  // interactions //
168
215
  _defaultProcessInteraction(payload, args) {
169
- payload = this._answer._defaultProcessInteraction0(payload, args);
170
- payload = this._results._defaultProcessInteraction0(payload, args);
216
+ payload = super._defaultProcessInteraction(payload, args);
217
+ payload = writeAnswerInfoToInteraction(payload, args);
171
218
  return payload;
172
219
  }
173
220
 
174
221
  // destroy //
175
222
  _destroy() {
176
- for (const subworkflow of this._subworkflows) {
177
- subworkflow.destroy();
178
- }
223
+ this._answer.destroy();
179
224
  super._destroy();
180
225
  }
181
226
 
182
227
  }
183
228
 
184
229
  makeConfigurable(HybridSearch.prototype, [WORKFLOW_CONFIGURABLE.PAGINATION, WORKFLOW_CONFIGURABLE.FILTERS]);
230
+ makeAutocompletable(HybridSearch.prototype);
@@ -1,10 +1,17 @@
1
1
  import { trimObj } from '@miso.ai/commons';
2
- import { ROLE } from '../../constants.js';
2
+ import { ROLE, QUESTION_SOURCE } from '../../constants.js';
3
3
 
4
4
  export const DEFAULT_AUTO_QUERY_PARAM = 'q';
5
5
  export const DEFAULT_AUTO_QUERY_SOURCE_PARAM = 'qs';
6
6
 
7
- export function normalizeAutoQueryOptions({ setValue = true, focus = true, updateUrl = true, param = DEFAULT_AUTO_QUERY_PARAM, sourceParam = DEFAULT_AUTO_QUERY_SOURCE_PARAM, ...options } = {}) {
7
+ export function normalizeAutoQueryOptions({
8
+ setValue = true,
9
+ focus = true,
10
+ updateUrl = true,
11
+ param = DEFAULT_AUTO_QUERY_PARAM,
12
+ sourceParam = DEFAULT_AUTO_QUERY_SOURCE_PARAM,
13
+ ...options
14
+ } = {}) {
8
15
  return { setValue, focus, updateUrl, param, sourceParam, ...options };
9
16
  }
10
17
 
@@ -27,3 +34,30 @@ export function autoQuery(options = {}) {
27
34
  this.query(trimObj({ q, qs }));
28
35
  }
29
36
  }
37
+
38
+ export function updateQueryParametersInUrl({ value, request }) {
39
+ if (!this._autoQuery || !this._autoQuery.updateUrl) {
40
+ return;
41
+ }
42
+ const { param, sourceParam } = this._autoQuery;
43
+ const query = (value && (value.question || value.keyword)) || (request && request.payload && (request.payload.question || request.payload.q));
44
+ const querySource = request && request.payload && request.payload.metadata && request.payload.metadata.question_source;
45
+
46
+ if (!query) {
47
+ return; // at initial phase
48
+ }
49
+
50
+ const url = new URL(window.location);
51
+ const currentQuery = url.searchParams.get(param);
52
+ const currentQuerySource = url.searchParams.get(sourceParam) || QUESTION_SOURCE.ORGANIC;
53
+ if (query === currentQuery && querySource === currentQuerySource) {
54
+ return;
55
+ }
56
+ url.searchParams.set(param, query);
57
+ if (querySource === QUESTION_SOURCE.ORGANIC) {
58
+ url.searchParams.delete(sourceParam);
59
+ } else {
60
+ url.searchParams.set(sourceParam, querySource);
61
+ }
62
+ window.history.replaceState({}, '', url);
63
+ }
@@ -1,5 +1,5 @@
1
- import { trimObj, mergeInteractions } from '@miso.ai/commons';
2
- import { STATUS, ROLE, EVENT_TYPE, REQUEST_TYPE, isPerformanceEventType, isProductRole } from '../constants.js';
1
+ import { trimObj, mergeApiPayloads, mergeInteractions } from '@miso.ai/commons';
2
+ import { STATUS, ROLE, EVENT_TYPE, REQUEST_TYPE, QUESTION_SOURCE, isPerformanceEventType, isProductRole } from '../constants.js';
3
3
  import { fields } from '../actor/index.js';
4
4
 
5
5
  // role mappings //
@@ -62,6 +62,14 @@ export function mappingFollowUpQuestionsData(data) {
62
62
  }
63
63
 
64
64
  // payload //
65
+ export function writeQuestionSourceToPayload({ qs, ...payload } = {}) {
66
+ return mergeApiPayloads(payload, {
67
+ metadata: {
68
+ question_source: qs || QUESTION_SOURCE.ORGANIC, // might be null, not undefined
69
+ },
70
+ });
71
+ }
72
+
65
73
  export function disableAnswerForNonQueryRequest(payload, type) {
66
74
  if (type === REQUEST_TYPE.QUERY) {
67
75
  return payload;
@@ -278,6 +286,20 @@ export function writeExhaustionToData(data, { role = ROLE.PRODUCTS } = {}) {
278
286
  };
279
287
  }
280
288
 
289
+ export function carryOverQuestionIdToData(data, oldData) {
290
+ const { question_id } = (oldData && oldData.value) || {};
291
+ if (!question_id) {
292
+ return data;
293
+ }
294
+ return {
295
+ ...data,
296
+ value: {
297
+ ...data.value,
298
+ question_id,
299
+ },
300
+ };
301
+ }
302
+
281
303
  // interactions //
282
304
  export function buildBaseInteraction(args) {
283
305
  const { role, type, items } = args;
@@ -332,6 +354,27 @@ export function writeRequestMetadataToInteraction(payload, args) {
332
354
  });
333
355
  }
334
356
 
357
+ export function writeRequestInfoToInteraction(payload, args) {
358
+ const { data } = args;
359
+ if (!data) {
360
+ return payload;
361
+ }
362
+ const requestPayload = data.request && data.request.payload;
363
+ if (!requestPayload) {
364
+ return payload;
365
+ }
366
+ const { question, q, fq } = requestPayload;
367
+ return mergeInteractions(payload, {
368
+ context: {
369
+ custom_context: {
370
+ question,
371
+ q,
372
+ fq,
373
+ },
374
+ },
375
+ });
376
+ }
377
+
335
378
  export function writeAffiliationInfoToInteraction(payload, args) {
336
379
  if (args.role !== ROLE.AFFILIATION) {
337
380
  return payload;
@@ -349,6 +392,47 @@ export function writeAffiliationInfoToInteraction(payload, args) {
349
392
  });
350
393
  }
351
394
 
395
+ export function writeAnswerInfoToInteraction(payload, args) {
396
+ payload = writeQuestionInfoToInteraction(payload, args);
397
+ payload = writeAnswerClickInfoToInteraction(payload, args);
398
+ payload = writeEventTargetToInteraction(payload, args);
399
+ return payload;
400
+ }
401
+
402
+ export function writeQuestionInfoToInteraction(payload = {}, { data } = {}) {
403
+ if (!data) {
404
+ return payload;
405
+ }
406
+ const { request = {}, value = {} } = data;
407
+ const { question_source } = request.payload && request.payload.metadata || {};
408
+ const { question_id } = value;
409
+ return mergeInteractions(payload, {
410
+ context: {
411
+ custom_context: {
412
+ question_source,
413
+ question_id,
414
+ },
415
+ },
416
+ });
417
+ }
418
+
419
+ export function writeAnswerClickInfoToInteraction(payload, args) {
420
+ if (args.role !== ROLE.ANSWER) {
421
+ return payload;
422
+ }
423
+ const { items = [] } = args;
424
+ return mergeInteractions(payload, {
425
+ context: {
426
+ custom_context: {
427
+ urls: items.map(item => item.url),
428
+ texts: items.map(item => item.text),
429
+ class_names: items.map(item => item.className),
430
+ attributes: items.map(item => item.attributes),
431
+ },
432
+ },
433
+ });
434
+ }
435
+
352
436
  export function writeEventTargetToInteraction(payload, { event_target } = {}) {
353
437
  if (!event_target) {
354
438
  return payload;
@@ -4,7 +4,7 @@ import { fields } from '../actor/index.js';
4
4
  import { STATUS, ROLE, WORKFLOW_CONFIGURABLE, REQUEST_TYPE } from '../constants.js';
5
5
  import { SearchBoxLayout, ListLayout, TextLayout, FacetsLayout, SelectLayout, MoreButtonLayout } from '../layout/index.js';
6
6
  import { mappingSortData, writeKeywordsToData, retainFacetCountsInData, writeExhaustionToData, writeMisoIdAsRootMisoId, concatItemsFromMoreResponse } from './processors.js';
7
- import { mergeRolesOptions, autoQuery as autoQueryFn, makeConfigurable, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
7
+ import { mergeRolesOptions, autoQuery as autoQueryFn, updateQueryParametersInUrl, makeConfigurable, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
8
8
 
9
9
  const DEFAULT_ROWS = 10;
10
10
  const DEFAULT_PAGE_LIMIT = 10;
@@ -99,29 +99,31 @@ export default class SearchBasedWorkflow extends Workflow {
99
99
  }
100
100
 
101
101
  _query(args) {
102
+ const type = REQUEST_TYPE.QUERY;
103
+
102
104
  // reset filters view
103
105
  this._views.filters.reset({ silent: true });
104
106
 
105
107
  // start a new session
106
- this.restart();
108
+ this.restart({ type });
107
109
 
108
110
  // payload
109
- const type = REQUEST_TYPE.QUERY;
110
111
  const payload = this._buildPayload(args, type);
111
112
 
112
113
  this._request({ payload, type });
113
114
  }
114
115
 
115
116
  _refine() {
117
+ const type = REQUEST_TYPE.REFINE;
118
+
116
119
  // remember current facet_counts
117
120
  const { facet_counts } = this._hub.states[fields.data()].value || {};
118
121
  this._currentFacetCounts = facet_counts;
119
122
 
120
123
  // start a new session
121
- this.restart();
124
+ this.restart({ type });
122
125
 
123
126
  // payload
124
- const type = REQUEST_TYPE.REFINE;
125
127
  const query = this._getQuery();
126
128
  const payload = this._buildPayload(query, type);
127
129
 
@@ -234,9 +236,14 @@ export default class SearchBasedWorkflow extends Workflow {
234
236
  return data;
235
237
  }
236
238
 
237
- _updateDataInHub(data) {
239
+ _updateData(data) {
240
+ super._updateData(data);
241
+ updateQueryParametersInUrl.call(this, data);
242
+ }
243
+
244
+ _updateDataInHub(data, oldData) {
238
245
  data = this._appendResultsFromMoreRequest(data);
239
- super._updateDataInHub(data);
246
+ super._updateDataInHub(data, oldData);
240
247
  }
241
248
 
242
249
  _appendResultsFromMoreRequest(data) {
@@ -269,26 +276,6 @@ export default class SearchBasedWorkflow extends Workflow {
269
276
  return payload;
270
277
  }
271
278
 
272
- _writeRequestInfoToInteraction(payload, args) {
273
- const { data } = args;
274
- if (!data) {
275
- return payload;
276
- }
277
- const requestPayload = data.request && data.request.payload;
278
- if (!requestPayload) {
279
- return payload;
280
- }
281
- const { q, fq } = requestPayload;
282
- return mergeInteractions(payload, {
283
- context: {
284
- custom_context: {
285
- q,
286
- fq,
287
- },
288
- },
289
- });
290
- }
291
-
292
279
  _writeRootMisoIdToInteraction(payload) {
293
280
  const data = this._hub.states[fields.data()];
294
281
  const { root_miso_id } = (data && data.value) || {};
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _commons = require("@miso.ai/commons");
8
- var _searchBased = _interopRequireDefault(require("./search-based.js"));
9
- var _index = require("../actor/index.js");
10
- var _constants = require("../constants.js");
11
- var _processors = require("./processors.js");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- // we want to override members, not adding to it
14
- const ROLES_OPTIONS = Object.assign({}, _searchBased.default.ROLES_OPTIONS, {
15
- members: [_constants.ROLE.PRODUCTS, _constants.ROLE.KEYWORDS, _constants.ROLE.TOTAL, _constants.ROLE.FACETS, _constants.ROLE.SORT, _constants.ROLE.MORE, _constants.ROLE.ERROR]
16
- });
17
- class HybridSearchResults extends _searchBased.default {
18
- constructor(superworkflow) {
19
- super({
20
- name: 'hybrid-search/results',
21
- plugin: superworkflow._plugin,
22
- client: superworkflow._client,
23
- options: superworkflow._options,
24
- defaults: superworkflow._defaults,
25
- roles: ROLES_OPTIONS,
26
- superworkflow
27
- });
28
- }
29
- _initProperties(args) {
30
- super._initProperties(args);
31
- this._superworkflow = args.superworkflow;
32
- }
33
- _initSession() {} // no reset here, will manually reset later
34
-
35
- // lifecycle //
36
- _emitLifecycleEvent(name, event) {
37
- super._emitLifecycleEvent(name, event);
38
- this._superworkflow._emitLifecycleEvent(name, event);
39
- }
40
-
41
- // query //
42
- _getQuery() {
43
- // get stored query from sibling
44
- return this._superworkflow._answer._hub.states[_index.fields.query()];
45
- }
46
- _buildPayload(payload, type) {
47
- payload = super._buildPayload(payload, type);
48
- // borrow the work from the sibling
49
- payload = this._superworkflow._answer._writeQuestionSourceToPayload(payload);
50
- payload = this._writeQuestionIdToPayload(payload);
51
- payload = (0, _processors.disableAnswerForNonQueryRequest)(payload, type);
52
- return payload;
53
- }
54
- _buildOrderBy(sort) {
55
- if (!sort) {
56
- return undefined;
57
- }
58
- // works differently than search
59
- return sort.field;
60
- }
61
- _writeQuestionIdToPayload(payload) {
62
- return (0, _commons.mergeApiPayloads)(payload, {
63
- metadata: {
64
- question_id: this._superworkflow._answer.questionId
65
- }
66
- });
67
- }
68
-
69
- // data //
70
- _defaultProcessData(data, oldData) {
71
- data = super._defaultProcessData(data, oldData);
72
- (0, _processors.writeMisoIdToSession)(data);
73
- return data;
74
- }
75
-
76
- // interactions //
77
- _defaultProcessInteraction(payload, args) {
78
- return this._superworkflow._defaultProcessInteraction(payload, args);
79
- }
80
- _defaultProcessInteraction0(payload, args) {
81
- return super._defaultProcessInteraction(payload, args);
82
- }
83
- }
84
- exports.default = HybridSearchResults;
85
- Object.assign(HybridSearchResults, {
86
- ROLES_OPTIONS
87
- });
@@ -1,91 +0,0 @@
1
- import { mergeApiPayloads } from '@miso.ai/commons';
2
- import SearchBasedWorkflow from './search-based.js';
3
- import { fields } from '../actor/index.js';
4
- import { ROLE } from '../constants.js';
5
- import { writeMisoIdToSession, disableAnswerForNonQueryRequest } from './processors.js';
6
-
7
- // we want to override members, not adding to it
8
- const ROLES_OPTIONS = {
9
- ...SearchBasedWorkflow.ROLES_OPTIONS,
10
- members: [ROLE.PRODUCTS, ROLE.KEYWORDS, ROLE.TOTAL, ROLE.FACETS, ROLE.SORT, ROLE.MORE, ROLE.ERROR],
11
- };
12
-
13
- export default class HybridSearchResults extends SearchBasedWorkflow {
14
-
15
- constructor(superworkflow) {
16
- super({
17
- name: 'hybrid-search/results',
18
- plugin: superworkflow._plugin,
19
- client: superworkflow._client,
20
- options: superworkflow._options,
21
- defaults: superworkflow._defaults,
22
- roles: ROLES_OPTIONS,
23
- superworkflow,
24
- });
25
- }
26
-
27
- _initProperties(args) {
28
- super._initProperties(args);
29
- this._superworkflow = args.superworkflow;
30
- }
31
-
32
- _initSession() {} // no reset here, will manually reset later
33
-
34
- // lifecycle //
35
- _emitLifecycleEvent(name, event) {
36
- super._emitLifecycleEvent(name, event);
37
- this._superworkflow._emitLifecycleEvent(name, event);
38
- }
39
-
40
- // query //
41
- _getQuery() {
42
- // get stored query from sibling
43
- return this._superworkflow._answer._hub.states[fields.query()];
44
- }
45
-
46
- _buildPayload(payload, type) {
47
- payload = super._buildPayload(payload, type);
48
- // borrow the work from the sibling
49
- payload = this._superworkflow._answer._writeQuestionSourceToPayload(payload);
50
- payload = this._writeQuestionIdToPayload(payload);
51
- payload = disableAnswerForNonQueryRequest(payload, type);
52
- return payload;
53
- }
54
-
55
- _buildOrderBy(sort) {
56
- if (!sort) {
57
- return undefined;
58
- }
59
- // works differently than search
60
- return sort.field;
61
- }
62
-
63
- _writeQuestionIdToPayload(payload) {
64
- return mergeApiPayloads(payload, {
65
- metadata: {
66
- question_id: this._superworkflow._answer.questionId,
67
- },
68
- });
69
- }
70
-
71
- // data //
72
- _defaultProcessData(data, oldData) {
73
- data = super._defaultProcessData(data, oldData);
74
- writeMisoIdToSession(data);
75
- return data;
76
- }
77
-
78
- // interactions //
79
- _defaultProcessInteraction(payload, args) {
80
- return this._superworkflow._defaultProcessInteraction(payload, args);
81
- }
82
-
83
- _defaultProcessInteraction0(payload, args) {
84
- return super._defaultProcessInteraction(payload, args);
85
- }
86
-
87
- }
88
-
89
- Object.assign(HybridSearchResults, {
90
- ROLES_OPTIONS,
91
- });