Skip to content

Commit 439321b

Browse files
authored
Merge pull request #22 from AddSearch/sticky-facets-enhancement
Sticky facets enhancement
2 parents 0ef3a85 + dce1367 commit 439321b

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and [Indexing API](https://www.addsearch.com/docs/api/indexing-overview/) with J
77
## Quick Start
88
The library is available on the global CDN [jsDelivr:](https://www.jsdelivr.com/package/npm/addsearch-js-client)
99
```html
10-
<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client@0.5/dist/addsearch-js-client.min.js"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client@0.6/dist/addsearch-js-client.min.js"></script>
1111
```
1212
Or install the library locally to use it with Node.js:
1313
```sh

dist/addsearch-js-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apifetch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('isomorphic-fetch');
66
/**
77
* Fetch search results of search suggestions from the Addsearch API
88
*/
9-
var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRetry) {
9+
var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRetry, customFilterObject) {
1010

1111
const RESPONSE_BAD_REQUEST = 400;
1212
const RESPONSE_SERVER_ERROR = 500;
@@ -124,7 +124,9 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
124124
}
125125

126126
// Filter object
127-
if (settings.filterObject) {
127+
if (customFilterObject) {
128+
qs = qs + '&filter=' + JSON.stringify(customFilterObject);
129+
} else if (settings.filterObject) {
128130
qs = qs + '&filter=' + JSON.stringify(settings.filterObject);
129131
}
130132

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ var client = function(sitekey, privatekey) {
9393
this.throttledAutocompleteFetch(this.apiHostname, this.sitekey, 'autocomplete', this.settings.getSettings(), callback);
9494
}
9595

96+
/**
97+
* Fetch API with a custom filter object
98+
*/
99+
this.fetchCustomApi = function(field, customFilterObject, callback) {
100+
var settingsCloned = Object.assign({}, this.settings.getSettings());
101+
102+
settingsCloned.facetFields = settingsCloned.facetFields.filter(facetField => field === facetField);
103+
executeApiFetch(this.apiHostname, this.sitekey, 'search', settingsCloned, callback, null, customFilterObject);
104+
}
96105

97106
/**
98107
* Indexing API functions

0 commit comments

Comments
 (0)