Skip to content

Commit 0886683

Browse files
committed
Merge branch 'master' into support-for-analytics-tagging
# Conflicts: # dist/addsearch-js-client.min.js # src/apifetch.js
2 parents 6e790dc + f31c9fd commit 0886683

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
8282
settingToQueryParam(settings.userToken, 'userToken') +
8383
settingToQueryParam(settings.numFacets, 'numFacets') +
8484
settingToQueryParam(settings.cacheResponseTime, 'cacheResponseWithTtlSeconds') +
85+
settingToQueryParam(settings.searchOperator, 'defaultOperator') +
8586
settingToQueryParam(settings.analyticsTag, 'analyticsTag');
8687

8788
// Add custom field filters

src/index.js

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

165166
this.sendStatsEvent = function(type, keyword, data) {
166167
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
};
@@ -217,6 +218,13 @@ var settings = function() {
217218
this.settings.paging.page = this.settings.paging.page - 1;
218219
}
219220
}
221+
222+
this.setSearchOperator = function(operator) {
223+
if (operator !== 'and' && operator !== 'or') {
224+
throw "operator must be 'and' || 'or'"
225+
}
226+
this.settings.searchOperator = operator;
227+
}
220228
}
221229

222230
module.exports = settings;

0 commit comments

Comments
 (0)