Skip to content

Commit 32123ad

Browse files
authored
Merge pull request #30 from JasonStoltz/search-fields
Added resultFields and searchFields This is so that we can render all results in the Reference UI with snippets via the resultFields option, but defer to the server for configuration of which fields to search over.
2 parents b4eb2df + c113e4c commit 32123ad

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ and then restart this app.
6666

6767
The following is a complete list of options available for configuration in [engine.json](src/config/engine.json).
6868

69-
| option | value type | required/optional | source |
70-
| -------------------- | ------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71-
| `engineName` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
72-
| `hostIdentifier` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
73-
| `searchKey` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
74-
| `fields` | Array[String] | required | A list of fields that will be searched and displayed within your results. |
75-
| `querySuggestFields` | Array[String] | optional | A list of fields that will be searched and displayed as query suggestions. |
76-
| `titleField` | String | optional | The field to display as the title in results. |
77-
| `urlField` | String | optional | A field with a url to use as a link in results. |
78-
| `urlFieldTemplate` | String | optional | Instead of urlField, you can provide a URL "template" here, which lets you build a URL from other fields. ex: "https://www.example.com/{{id}}". |
79-
| `sortFields` | Array[String] | optional | A list of fields that will be used for sort options. |
80-
| `facets` | Array[String] | optional | A list of fields that will be available as "facet" filters. Read more about facets within the [App Search documentation](https://swiftype.com/documentation/search-lib/guides/facets). |
69+
| option | value type | required/optional | source |
70+
| --------------------- | ------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71+
| `engineName` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
72+
| `hostIdentifier` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
73+
| `searchKey` | String | required | Found in your [App Search Dashboard](http://app.swiftype.com/as). |
74+
| `searchFields` | Array[String] | required | A list of fields that will be searched with your search term. |
75+
| `resultFields` | Array[String] | required | A list of fields that will be displayed within your results. |
76+
| `fields` (Deprecated) | Array[String] | optional | A list of fields that will be searched and displayed within your results. Deprecation: Use resultFields and searchFields instead. |
77+
| `querySuggestFields` | Array[String] | optional | A list of fields that will be searched and displayed as query suggestions. |
78+
| `titleField` | String | optional | The field to display as the title in results. |
79+
| `urlField` | String | optional | A field with a url to use as a link in results. |
80+
| `urlFieldTemplate` | String | optional | Instead of urlField, you can provide a URL "template" here, which lets you build a URL from other fields. ex: "https://www.example.com/{{id}}". |
81+
| `sortFields` | Array[String] | optional | A list of fields that will be used for sort options. |
82+
| `facets` | Array[String] | optional | A list of fields that will be available as "facet" filters. Read more about facets within the [App Search documentation](https://swiftype.com/documentation/search-lib/guides/facets). |
8183

8284
### External configuration
8385

src/config/config-helper.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,29 @@ export function stripUnnecessaryResultFields(resultFields) {
108108

109109
export function buildSearchOptionsFromConfig() {
110110
const config = getConfig();
111-
const searchFields = (config.fields || []).reduce((acc, n) => {
112-
acc = acc || {};
113-
acc[n] = {};
114-
return acc;
115-
}, undefined);
116-
117-
const resultFields = (config.fields || []).reduce((acc, n) => {
118-
acc = acc || {};
119-
acc[n] = {
120-
raw: {},
121-
snippet: {
122-
size: 100,
123-
fallback: true
124-
}
125-
};
126-
return acc;
127-
}, undefined);
111+
const searchFields = (config.searchFields || config.fields || []).reduce(
112+
(acc, n) => {
113+
acc = acc || {};
114+
acc[n] = {};
115+
return acc;
116+
},
117+
undefined
118+
);
119+
120+
const resultFields = (config.resultFields || config.fields || []).reduce(
121+
(acc, n) => {
122+
acc = acc || {};
123+
acc[n] = {
124+
raw: {},
125+
snippet: {
126+
size: 100,
127+
fallback: true
128+
}
129+
};
130+
return acc;
131+
},
132+
undefined
133+
);
128134

129135
// We can't use url or title fields unless they're actually
130136
// in the reuslts.

src/config/engine.json.example

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22
"engineName": "your-engine-name",
33
"hostIdentifier": "host-XXXXX",
44
"searchKey": "search-XXXXXXXXXXXXXXXXXXXXXXX",
5-
"fields": [
6-
"id",
7-
"title",
8-
"anotherField",
9-
"someField",
10-
"created"
11-
],
12-
"querySuggestFields": [
13-
"title"
14-
],
5+
"searchFields": ["title", "description"],
6+
"resultFields": ["id", "title", "anotherField", "someField", "created"],
7+
"querySuggestFields": ["title"],
158
"titleField": "title",
169
"urlField": "url",
1710
"urlFieldTemplate": "http://www.example.com/{{id}}",
18-
"sortFields": [
19-
"title",
20-
"anotherField"
21-
],
11+
"sortFields": ["title", "anotherField"],
2212
"facets": ["anotherField", "someField"]
2313
}

0 commit comments

Comments
 (0)