Skip to content

Commit 399d1a6

Browse files
committed
add setting 'searchOperator'
1 parent d6b5219 commit 399d1a6

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ client.autocomplete('custom_fields.brand', 'a', callback);
8686
client.setAutocompleteSize(20);
8787
```
8888

89+
#### Search operator
90+
Description for search operator. There are three options:
91+
- **"and"**:
92+
- **"or"**:
93+
- **no parameter**: Remove the query parameter from the search api
94+
95+
```js
96+
// Possible values "and"/"or"/null/ (default: null)
97+
client.setSearchOperator('and');
98+
```
99+
89100
#### Search with fuzzy matching
90101
Fuzzy matching is used for typo tolerance. There are four options:
91102
- **false**: No typo tolerance

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
8181
settingToQueryParam(settings.resultType, 'resultType') +
8282
settingToQueryParam(settings.userToken, 'userToken') +
8383
settingToQueryParam(settings.numFacets, 'numFacets') +
84-
settingToQueryParam(settings.cacheResponseTime, 'cacheResponseWithTtlSeconds');
84+
settingToQueryParam(settings.cacheResponseTime, 'cacheResponseWithTtlSeconds') +
85+
settingToQueryParam(settings.searchOperator, 'defaultOperator');
8586

8687
// Add custom field filters
8788
if (settings.customFieldFilters) {

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ var client = function(sitekey, privatekey) {
160160
this.setStatsSessionId = function(id) { this.sessionId = id; }
161161
this.getStatsSessionId = function() { return this.sessionId; }
162162
this.enableLogicalOperators = function(enableLogicalOperators) { this.settings.enableLogicalOperators(enableLogicalOperators) }
163+
this.setSearchOperator = function(operator) { this.settings.setSearchOperator(operator) }
163164

164165
this.sendStatsEvent = function(type, keyword, data) {
165166
if (type === 'search') {

src/settings.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var settings = function() {
1919
autocomplete: {
2020
size: 10
2121
},
22+
searchOperator: null,
2223
enableLogicalOperators: false,
2324
cacheResponseTime: null
2425
};
@@ -213,6 +214,17 @@ var settings = function() {
213214
this.settings.paging.page = this.settings.paging.page - 1;
214215
}
215216
}
217+
218+
this.setSearchOperator = function(operator) {
219+
if (!operator) {
220+
this.settings.searchOperator = null;
221+
return;
222+
}
223+
if (operator !== 'and' && operator !== 'or') {
224+
throw "operator must be 'and' || 'or'"
225+
}
226+
this.settings.searchOperator = operator;
227+
}
216228
}
217229

218230
module.exports = settings;

0 commit comments

Comments
 (0)