Skip to content

Commit f31c9fd

Browse files
authored
Merge pull request #21 from AddSearch/default-operator-support
add setting 'searchOperator'
2 parents d6b5219 + 373eaa1 commit f31c9fd

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ Fuzzy matching is used for typo tolerance. There are four options:
9999
client.setFuzzyMatch(false);
100100
```
101101

102+
#### Search operator
103+
When a user searches with multiple keywords, we return only documents that contain all the terms which means
104+
applying the logical operator AND for the query. It is possible to choose which logical operator to use for
105+
fuzzy results when the fuzzy parameter is set to auto. There are two options:
106+
- **"or"**: makes fuzzy results broader and includes partial matches of a few search terms
107+
- **"and"**: makes fuzzy results stricter and includes only mistyped search terms
108+
109+
```js
110+
// Possible values "and"/"or" (default: "or")
111+
client.setSearchOperator('and');
112+
```
113+
102114
#### Postfix wildcard
103115
Enable or disable postfix wildcard. I.e. should keyword "add" match to "addsearch" or should it just match to the
104116
term **add**

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: 8 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,13 @@ var settings = function() {
213214
this.settings.paging.page = this.settings.paging.page - 1;
214215
}
215216
}
217+
218+
this.setSearchOperator = function(operator) {
219+
if (operator !== 'and' && operator !== 'or') {
220+
throw "operator must be 'and' || 'or'"
221+
}
222+
this.settings.searchOperator = operator;
223+
}
216224
}
217225

218226
module.exports = settings;

0 commit comments

Comments
 (0)