Skip to content

Commit ba31ee4

Browse files
author
Brian Earwood
committed
Make filter fields optional and update README
1 parent 43ab0cf commit ba31ee4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ The following is a complete list of options available for configuration in [engi
5858
| `titleField` | String | optional | The field to display as the title in results. |
5959
| `urlField` | String | optional | A field with a url to use as a link in results. |
6060
| `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}}". |
61-
| `sortFields` | Array[String] | required | A list of fields that will be used for sort options. |
62-
| `facets` | Array[String] | required | 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). |
61+
| `sortFields` | Array[String] | optional | A list of fields that will be used for sort options. |
62+
| `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). |
6363

6464
### External configuration
6565

src/search-lib/SearchDriver.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,18 @@ export default class SearchDriver {
297297
current,
298298
size: resultsPerPage
299299
},
300-
facets: removeConditionalFacets(this.facetConfig, filters),
301300
filters: {
302301
all: formatORFiltersAsAND(convertRangeFiltersToDateString(filters))
303302
}
304303
};
305304

305+
const facets = removeConditionalFacets(this.facetConfig, filters);
306+
const numberOfFacets = Object.keys(facets).length;
307+
308+
if (numberOfFacets > 0) {
309+
searchOptions.facets = facets;
310+
}
311+
306312
if (sortField && sortDirection) {
307313
searchOptions.sort = {
308314
[sortField]: sortDirection

0 commit comments

Comments
 (0)