@miso.ai/client-sdk-ui 1.11.0-beta.5 → 1.11.0-beta.7

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.
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.sources = exports.showMore = exports.showLess = exports.question = exports.keywords = exports.hits = void 0;
7
7
  /**
8
- * The phrase displayed right before <miso-question>
8
+ * The phrase to display <miso-question>
9
9
  */
10
- const question = exports.question = 'You asked...';
10
+ const question = exports.question = 'You asked “${value}”';
11
11
 
12
12
  /**
13
13
  * The phrase displayed right before <miso-sources>
@@ -31,6 +31,15 @@ class Sections extends _templates.Sections {
31
31
  classes: [`${classPrefix}__answer-box-inner`]
32
32
  }, this.answerGroup(options)), this.answerBoxToggle(options)]);
33
33
  }
34
+ question(options) {
35
+ const {
36
+ phrase
37
+ } = this._helpers;
38
+ return phrase(options, {
39
+ name: 'question',
40
+ tag: 'h3'
41
+ }).replaceAll('${value}', '<miso-question></miso-question>');
42
+ }
34
43
  answerBoxToggle(options) {
35
44
  const {
36
45
  element
@@ -51,7 +60,7 @@ class Sections extends _templates.Sections {
51
60
  } = this._helpers;
52
61
  return container(options, {
53
62
  name: 'search-results',
54
- visibleWhen: 'ready'
63
+ visibleWhen: 'loading ready'
55
64
  }, [this.searchResultsInfoGroup(options), this.searchResultsFilters(options), '<miso-products></miso-products>']);
56
65
  }
57
66
  searchResultsInfoGroup(options) {
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.11.0-beta.5';
7
+ var _default = exports.default = '1.11.0-beta.7';
@@ -57,7 +57,8 @@ const DEFAULT_LAYOUTS = Object.freeze({
57
57
  });
58
58
  const DEFAULT_TRACKERS = Object.freeze({
59
59
  [_constants.ROLE.SOURCES]: {},
60
- [_constants.ROLE.AFFILIATION]: {}
60
+ [_constants.ROLE.AFFILIATION]: {},
61
+ [_constants.ROLE.PRODUCTS]: {}
61
62
  });
62
63
  const DEFAULT_OPTIONS = Object.freeze({
63
64
  api: DEFAULT_API_OPTIONS,
@@ -204,6 +205,9 @@ class AnswerBasedWorkflow extends _base.default {
204
205
  return;
205
206
  }
206
207
  super._updateData(data);
208
+
209
+ // update URL if autoQuery.updateUrl is not false
210
+ this._updateUrlIfNecessary(data);
207
211
  }
208
212
  _handleHeadResponse(data) {
209
213
  // capture question ID and register at context
@@ -211,13 +215,9 @@ class AnswerBasedWorkflow extends _base.default {
211
215
  }
212
216
  _defaultProcessData(data) {
213
217
  data = super._defaultProcessData(data);
214
-
215
- // update URL if autoQuery.updateUrl is not false
216
- this._updateUrlIfNecessary(data);
217
-
218
- // affiliation
219
218
  data = (0, _index3.processData)(data);
220
- return (0, _processors.writeAnswerStageToMeta)(data);
219
+ data = (0, _processors.writeAnswerStageToMeta)(data);
220
+ return data;
221
221
  }
222
222
  _writeQuestionIdFromData(_ref) {
223
223
  let {
@@ -178,15 +178,19 @@ class Workflow extends _commons.Component {
178
178
  _updateData(data) {
179
179
  this._sessions.start(); // in case session not started yet
180
180
 
181
- data = (0, _processors.writeDataStatus)(data);
182
181
  data = this._defaultProcessData(data);
183
182
  for (const process of this._options.resolved.dataProcessor) {
184
183
  data = process(data);
185
184
  }
186
- this._hub.update(_index.fields.data(), data);
185
+ this._updateDataInHub(data);
187
186
  }
188
187
  _defaultProcessData(data) {
189
- return (0, _processors.writeMisoIdToMeta)(data);
188
+ data = (0, _processors.writeDataStatus)(data);
189
+ data = (0, _processors.writeMisoIdToMeta)(data);
190
+ return data;
191
+ }
192
+ _updateDataInHub(data) {
193
+ this._hub.update(_index.fields.data(), data);
190
194
  }
191
195
 
192
196
  /*
@@ -26,7 +26,6 @@ class HybridSearchAnswer extends _answerBased.default {
26
26
  rolesConfig: ROLES_CONFIG,
27
27
  superworkflow
28
28
  });
29
- this.useInteractions(false);
30
29
  }
31
30
  _initProperties(args) {
32
31
  super._initProperties(args);
@@ -38,6 +37,7 @@ class HybridSearchAnswer extends _answerBased.default {
38
37
  super.restart();
39
38
  // cascade restart to the sibling
40
39
  const results = this._superworkflow._results;
40
+ results._views.filters.reset();
41
41
  results.restart();
42
42
  this._resultsSession = results.session; // keep track of the session
43
43
  }
@@ -60,9 +60,12 @@ class HybridSearchAnswer extends _answerBased.default {
60
60
  }
61
61
 
62
62
  // data //
63
- _updateData(data) {
64
- // we want this to be available everywhere
63
+ _defaultProcessData(data) {
64
+ data = super._defaultProcessData(data);
65
65
  data = (0, _processors.writeKeywordsToData)(data);
66
+ return data;
67
+ }
68
+ _updateDataInHub(data) {
66
69
  switch (data.status) {
67
70
  case _constants.STATUS.INITIAL:
68
71
  case _constants.STATUS.LOADING:
@@ -70,7 +73,7 @@ class HybridSearchAnswer extends _answerBased.default {
70
73
  this._dispatchDataToSibling(data);
71
74
  break;
72
75
  }
73
- super._updateData(data);
76
+ super._updateDataInHub(data);
74
77
  }
75
78
  _handleHeadResponse(data) {
76
79
  super._handleHeadResponse(data);
@@ -78,7 +81,7 @@ class HybridSearchAnswer extends _answerBased.default {
78
81
  this._dispatchDataToSibling(data);
79
82
  }
80
83
  _dispatchDataToSibling(data) {
81
- this._superworkflow._results.updateData(Object.assign({}, data, {
84
+ this._resultsSession && this._superworkflow._results.updateData(Object.assign({}, data, {
82
85
  session: this._resultsSession
83
86
  }));
84
87
  }
@@ -30,7 +30,6 @@ class HybridSearchResults extends _base.default {
30
30
  rolesConfig: ROLES_CONFIG,
31
31
  superworkflow
32
32
  });
33
- this.useInteractions(false);
34
33
  }
35
34
  _initProperties(args) {
36
35
  super._initProperties(args);
@@ -44,6 +43,12 @@ class HybridSearchResults extends _base.default {
44
43
 
45
44
  // query //
46
45
  _refine(filters) {
46
+ // remember current facet_counts
47
+ const {
48
+ facet_counts
49
+ } = this._hub.states[_index.fields.data()].value || {};
50
+ this._previousFacetCounts = facet_counts;
51
+
47
52
  // start a new session
48
53
  this.restart();
49
54
 
@@ -69,7 +74,7 @@ class HybridSearchResults extends _base.default {
69
74
  payload = _objectWithoutPropertiesLoose(_ref, _excluded);
70
75
  // borrow the work from the sibling
71
76
  payload = this._superworkflow._answer._buildPayload(payload);
72
- payload = this._writeFqToPayload(Object.assign({}, payload, {
77
+ payload = this._writeFiltersToPayload(Object.assign({}, payload, {
73
78
  filters
74
79
  }));
75
80
  payload = this._writeQuestionIdToPayload(payload);
@@ -77,16 +82,13 @@ class HybridSearchResults extends _base.default {
77
82
  answer: false
78
83
  });
79
84
  }
80
- _writeFqToPayload() {
85
+ _writeFiltersToPayload() {
81
86
  let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
82
87
  let {
83
88
  filters
84
89
  } = _ref2,
85
90
  payload = _objectWithoutPropertiesLoose(_ref2, _excluded2);
86
- const fq = (0, _processors.composeFq)(filters); // TODO: combine with fq in payload?
87
- return (0, _commons.trimObj)(Object.assign({}, payload, {
88
- fq
89
- }));
91
+ return (0, _commons.trimObj)(Object.assign({}, payload, (0, _processors.composeFiltersPayload)(filters)));
90
92
  }
91
93
  _writeQuestionIdToPayload(payload) {
92
94
  return Object.assign({}, payload, {
@@ -103,7 +105,32 @@ class HybridSearchResults extends _base.default {
103
105
  _defaultProcessData(data) {
104
106
  data = super._defaultProcessData(data);
105
107
  data = (0, _processors.writeKeywordsToData)(data);
108
+ data = this._retainFacetCounts(data);
106
109
  return data;
107
110
  }
111
+ _retainFacetCounts(data) {
112
+ if (!this._previousFacetCounts) {
113
+ return data;
114
+ }
115
+ const {
116
+ status,
117
+ value
118
+ } = data;
119
+ switch (status) {
120
+ case _constants.STATUS.INITIAL:
121
+ case _constants.STATUS.LOADING:
122
+ break;
123
+ default:
124
+ return data;
125
+ }
126
+ if (value && value.facet_counts) {
127
+ return data;
128
+ }
129
+ return Object.assign({}, data, {
130
+ value: Object.assign({}, value, {
131
+ facet_counts: this._previousFacetCounts
132
+ })
133
+ });
134
+ }
108
135
  }
109
136
  exports.default = HybridSearchResults;
@@ -16,10 +16,17 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
16
16
  const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS, {
17
17
  name: _commons.API.NAME.SEARCH,
18
18
  payload: Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS.payload, {
19
- fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at']
19
+ source_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title'],
20
+ fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title']
20
21
  })
21
22
  }));
22
23
  const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_LAYOUTS, {
24
+ [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
25
+ placeholder: ''
26
+ }],
27
+ [_constants.ROLE.QUESTION]: [_index2.TextLayout.type, {
28
+ raw: true
29
+ }],
23
30
  [_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
24
31
  itemType: 'article'
25
32
  }],
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.composeFq = composeFq;
6
+ exports.composeFiltersPayload = composeFiltersPayload;
7
7
  exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
8
8
  exports.writeDataStatus = writeDataStatus;
9
9
  exports.writeKeywordsToData = writeKeywordsToData;
@@ -13,10 +13,10 @@ var _constants = require("../constants.js");
13
13
  function writeDataStatus(data) {
14
14
  const status = getStatus(data);
15
15
  const ongoing = status === _constants.STATUS.READY ? !!data.ongoing : undefined;
16
- return (0, _commons.trimObj)(Object.assign({}, data, {
16
+ return (0, _commons.trimObj)(Object.assign({
17
17
  status,
18
18
  ongoing
19
- }));
19
+ }, data)); // let orinigal data override status and ongoing
20
20
  }
21
21
  function getStatus(data) {
22
22
  if (!data) {
@@ -53,7 +53,8 @@ function writeKeywordsToData(data) {
53
53
  request,
54
54
  value
55
55
  } = data;
56
- if (!request || !value) {
56
+ // we still want the value in loading status
57
+ if (!request) {
57
58
  return data;
58
59
  }
59
60
  const {
@@ -93,21 +94,30 @@ function writeAnswerStageToMeta(data) {
93
94
  })
94
95
  });
95
96
  }
96
- function composeFq(filters) {
97
+ function composeFiltersPayload(filters) {
97
98
  if (!filters) {
98
99
  return undefined;
99
100
  }
100
- const clauses = [];
101
101
  const {
102
102
  facets
103
103
  } = filters;
104
+ return (0, _commons.trimObj)({
105
+ facet_filters: composeFacetFilters(facets)
106
+ });
107
+ }
108
+ function composeFacetFilters(facets) {
109
+ if (!facets) {
110
+ return undefined;
111
+ }
112
+ const filters = {};
104
113
  for (const field in facets) {
105
114
  const values = facets[field];
106
115
  if (!values || !values.length) {
107
116
  continue; // just in case
108
117
  }
109
- const vstr = values.length === 1 ? `"${values[0]}"` : `(${values.map(v => `"${v}"`).join(' OR ')})`;
110
- clauses.push(`${field}:${vstr}`);
118
+ filters[field] = {
119
+ terms: values
120
+ };
111
121
  }
112
- return clauses.map(c => `(${c})`).join(' AND ') || undefined;
122
+ return Object.keys(filters).length ? filters : undefined;
113
123
  }
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.11.0-beta.5"
29
+ "@miso.ai/commons": "1.11.0-beta.7"
30
30
  },
31
- "version": "1.11.0-beta.5"
31
+ "version": "1.11.0-beta.7"
32
32
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The phrase displayed right before <miso-question>
2
+ * The phrase to display <miso-question>
3
3
  */
4
- export const question = 'You asked...';
4
+ export const question = 'You asked “${value}”';
5
5
 
6
6
  /**
7
7
  * The phrase displayed right before <miso-sources>
@@ -18,6 +18,11 @@ class Sections extends _Sections {
18
18
  ]);
19
19
  }
20
20
 
21
+ question(options) {
22
+ const { phrase } = this._helpers;
23
+ return phrase(options, { name: 'question', tag: 'h3' }).replaceAll('${value}', '<miso-question></miso-question>');
24
+ }
25
+
21
26
  answerBoxToggle(options) {
22
27
  const { element } = this._helpers;
23
28
  const { classPrefix } = options;
@@ -28,7 +33,7 @@ class Sections extends _Sections {
28
33
 
29
34
  searchResultsGroup(options) {
30
35
  const { container } = this._helpers;
31
- return container(options, { name: 'search-results', visibleWhen: 'ready' }, [
36
+ return container(options, { name: 'search-results', visibleWhen: 'loading ready' }, [
32
37
  this.searchResultsInfoGroup(options),
33
38
  this.searchResultsFilters(options),
34
39
  '<miso-products></miso-products>',
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.11.0-beta.5';
1
+ export default '1.11.0-beta.7';
@@ -38,6 +38,7 @@ const DEFAULT_LAYOUTS = Object.freeze({
38
38
  const DEFAULT_TRACKERS = Object.freeze({
39
39
  [ROLE.SOURCES]: {},
40
40
  [ROLE.AFFILIATION]: {},
41
+ [ROLE.PRODUCTS]: {},
41
42
  });
42
43
 
43
44
  const DEFAULT_OPTIONS = Object.freeze({
@@ -176,6 +177,9 @@ export default class AnswerBasedWorkflow extends Workflow {
176
177
  return;
177
178
  }
178
179
  super._updateData(data);
180
+
181
+ // update URL if autoQuery.updateUrl is not false
182
+ this._updateUrlIfNecessary(data);
179
183
  }
180
184
 
181
185
  _handleHeadResponse(data) {
@@ -185,14 +189,9 @@ export default class AnswerBasedWorkflow extends Workflow {
185
189
 
186
190
  _defaultProcessData(data) {
187
191
  data = super._defaultProcessData(data);
188
-
189
- // update URL if autoQuery.updateUrl is not false
190
- this._updateUrlIfNecessary(data);
191
-
192
- // affiliation
193
192
  data = processAffiliationData(data);
194
-
195
- return writeAnswerStageToMeta(data);
193
+ data = writeAnswerStageToMeta(data);
194
+ return data;
196
195
  }
197
196
 
198
197
  _writeQuestionIdFromData({ value }) {
@@ -160,17 +160,22 @@ export default class Workflow extends Component {
160
160
  _updateData(data) {
161
161
  this._sessions.start(); // in case session not started yet
162
162
 
163
- data = writeDataStatus(data);
164
163
  data = this._defaultProcessData(data);
165
164
  for (const process of this._options.resolved.dataProcessor) {
166
165
  data = process(data);
167
166
  }
168
167
 
169
- this._hub.update(fields.data(), data);
168
+ this._updateDataInHub(data);
170
169
  }
171
170
 
172
171
  _defaultProcessData(data) {
173
- return writeMisoIdToMeta(data);
172
+ data = writeDataStatus(data);
173
+ data = writeMisoIdToMeta(data);
174
+ return data;
175
+ }
176
+
177
+ _updateDataInHub(data) {
178
+ this._hub.update(fields.data(), data);
174
179
  }
175
180
 
176
181
  /*
@@ -20,7 +20,6 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
20
20
  rolesConfig: ROLES_CONFIG,
21
21
  superworkflow,
22
22
  });
23
- this.useInteractions(false);
24
23
  }
25
24
 
26
25
  _initProperties(args) {
@@ -34,6 +33,7 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
34
33
  super.restart();
35
34
  // cascade restart to the sibling
36
35
  const results = this._superworkflow._results;
36
+ results._views.filters.reset();
37
37
  results.restart();
38
38
  this._resultsSession = results.session; // keep track of the session
39
39
  }
@@ -51,10 +51,13 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
51
51
  }
52
52
 
53
53
  // data //
54
- _updateData(data) {
55
- // we want this to be available everywhere
54
+ _defaultProcessData(data) {
55
+ data = super._defaultProcessData(data);
56
56
  data = writeKeywordsToData(data);
57
+ return data;
58
+ }
57
59
 
60
+ _updateDataInHub(data) {
58
61
  switch (data.status) {
59
62
  case STATUS.INITIAL:
60
63
  case STATUS.LOADING:
@@ -62,7 +65,7 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
62
65
  this._dispatchDataToSibling(data);
63
66
  break;
64
67
  }
65
- super._updateData(data);
68
+ super._updateDataInHub(data);
66
69
  }
67
70
 
68
71
  _handleHeadResponse(data) {
@@ -72,7 +75,7 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
72
75
  }
73
76
 
74
77
  _dispatchDataToSibling(data) {
75
- this._superworkflow._results.updateData({ ...data, session: this._resultsSession });
78
+ this._resultsSession && this._superworkflow._results.updateData({ ...data, session: this._resultsSession });
76
79
  }
77
80
 
78
81
  }
@@ -1,9 +1,9 @@
1
1
  import { trimObj } from '@miso.ai/commons';
2
2
  import Workflow from './base.js';
3
3
  import { fields } from '../actor/index.js';
4
- import { ROLE } from '../constants.js';
4
+ import { ROLE, STATUS } from '../constants.js';
5
5
  import { mergeApiOptions } from './options.js';
6
- import { writeKeywordsToData, composeFq } from './processors.js';
6
+ import { writeKeywordsToData, composeFiltersPayload } from './processors.js';
7
7
 
8
8
  const ROLES_CONFIG = Object.freeze({
9
9
  [ROLE.FACETS]: {
@@ -23,7 +23,6 @@ export default class HybridSearchResults extends Workflow {
23
23
  rolesConfig: ROLES_CONFIG,
24
24
  superworkflow,
25
25
  });
26
- this.useInteractions(false);
27
26
  }
28
27
 
29
28
  _initProperties(args) {
@@ -43,6 +42,10 @@ export default class HybridSearchResults extends Workflow {
43
42
 
44
43
  // query //
45
44
  _refine(filters) {
45
+ // remember current facet_counts
46
+ const { facet_counts } = this._hub.states[fields.data()].value || {};
47
+ this._previousFacetCounts = facet_counts;
48
+
46
49
  // start a new session
47
50
  this.restart();
48
51
 
@@ -58,16 +61,15 @@ export default class HybridSearchResults extends Workflow {
58
61
  _buildPayload({ filters, ...payload } = {}) {
59
62
  // borrow the work from the sibling
60
63
  payload = this._superworkflow._answer._buildPayload(payload);
61
- payload = this._writeFqToPayload({ ...payload, filters });
64
+ payload = this._writeFiltersToPayload({ ...payload, filters });
62
65
  payload = this._writeQuestionIdToPayload(payload);
63
66
  return { ...payload, answer: false };
64
67
  }
65
68
 
66
- _writeFqToPayload({ filters, ...payload } = {}) {
67
- const fq = composeFq(filters); // TODO: combine with fq in payload?
69
+ _writeFiltersToPayload({ filters, ...payload } = {}) {
68
70
  return trimObj({
69
71
  ...payload,
70
- fq,
72
+ ...composeFiltersPayload(filters),
71
73
  });
72
74
  }
73
75
 
@@ -89,7 +91,32 @@ export default class HybridSearchResults extends Workflow {
89
91
  _defaultProcessData(data) {
90
92
  data = super._defaultProcessData(data);
91
93
  data = writeKeywordsToData(data);
94
+ data = this._retainFacetCounts(data);
92
95
  return data;
93
96
  }
94
97
 
98
+ _retainFacetCounts(data) {
99
+ if (!this._previousFacetCounts) {
100
+ return data;
101
+ }
102
+ const { status, value } = data;
103
+ switch (status) {
104
+ case STATUS.INITIAL:
105
+ case STATUS.LOADING:
106
+ break;
107
+ default:
108
+ return data;
109
+ }
110
+ if (value && value.facet_counts) {
111
+ return data;
112
+ }
113
+ return {
114
+ ...data,
115
+ value: {
116
+ ...value,
117
+ facet_counts: this._previousFacetCounts,
118
+ },
119
+ };
120
+ }
121
+
95
122
  }
@@ -3,7 +3,7 @@ import { InteractionsActor } from '../actor/index.js';
3
3
  import Workflow from './base.js';
4
4
  import AnswerBasedWorkflow from './answer-based.js';
5
5
  import { ROLE } from '../constants.js';
6
- import { ListLayout, TextLayout, FacetsLayout } from '../layout/index.js';
6
+ import { SearchBoxLayout, ListLayout, TextLayout, FacetsLayout } from '../layout/index.js';
7
7
  import HybridSearchAnswer from './hybrid-search-answer.js';
8
8
  import HybridSearchResults from './hybrid-search-results.js';
9
9
 
@@ -12,12 +12,15 @@ const DEFAULT_API_OPTIONS = Object.freeze({
12
12
  name: API.NAME.SEARCH,
13
13
  payload: {
14
14
  ...AnswerBasedWorkflow.DEFAULT_API_OPTIONS.payload,
15
- fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at'],
15
+ source_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title'],
16
+ fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title'],
16
17
  },
17
18
  });
18
19
 
19
20
  const DEFAULT_LAYOUTS = Object.freeze({
20
21
  ...AnswerBasedWorkflow.DEFAULT_LAYOUTS,
22
+ [ROLE.QUERY]: [SearchBoxLayout.type, { placeholder: '' }],
23
+ [ROLE.QUESTION]: [TextLayout.type, { raw: true }],
21
24
  [ROLE.PRODUCTS]: [ListLayout.type, { itemType: 'article' }],
22
25
  [ROLE.KEYWORDS]: [TextLayout.type, { raw: true }],
23
26
  [ROLE.HITS]: [TextLayout.type, { raw: true, format: 'number' }],
@@ -4,7 +4,7 @@ import { STATUS } from '../constants.js';
4
4
  export function writeDataStatus(data) {
5
5
  const status = getStatus(data);
6
6
  const ongoing = status === STATUS.READY ? !!data.ongoing : undefined;
7
- return trimObj({ ...data, status, ongoing });
7
+ return trimObj({ status, ongoing, ...data }); // let orinigal data override status and ongoing
8
8
  }
9
9
 
10
10
  function getStatus(data) {
@@ -35,7 +35,8 @@ export function writeMisoIdToMeta(data) {
35
35
 
36
36
  export function writeKeywordsToData(data) {
37
37
  const { request, value } = data;
38
- if (!request || !value) {
38
+ // we still want the value in loading status
39
+ if (!request) {
39
40
  return data;
40
41
  }
41
42
  const { payload } = request || {};
@@ -73,19 +74,29 @@ export function writeAnswerStageToMeta(data) {
73
74
  };
74
75
  }
75
76
 
76
- export function composeFq(filters) {
77
+ export function composeFiltersPayload(filters) {
77
78
  if (!filters) {
78
79
  return undefined;
79
80
  }
80
- const clauses = [];
81
81
  const { facets } = filters;
82
+ return trimObj({
83
+ facet_filters: composeFacetFilters(facets),
84
+ });
85
+ }
86
+
87
+ function composeFacetFilters(facets) {
88
+ if (!facets) {
89
+ return undefined;
90
+ }
91
+ const filters = {};
82
92
  for (const field in facets) {
83
93
  const values = facets[field];
84
94
  if (!values || !values.length) {
85
95
  continue; // just in case
86
96
  }
87
- const vstr = values.length === 1 ? `"${values[0]}"` : `(${values.map(v => `"${v}"`).join(' OR ')})`;
88
- clauses.push(`${field}:${vstr}`);
97
+ filters[field] = {
98
+ terms: values,
99
+ };
89
100
  }
90
- return clauses.map(c => `(${c})`).join(' AND ') || undefined;
101
+ return Object.keys(filters).length ? filters : undefined;
91
102
  }