Skip to content

Commit dce1367

Browse files
authored
Merge branch 'master' into sticky-facets-enhancement
2 parents 2c09c06 + 0ef3a85 commit dce1367

File tree

6 files changed

+62
-14
lines changed

6 files changed

+62
-14
lines changed

README.md

Lines changed: 30 additions & 7 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**
@@ -108,6 +120,24 @@ term **add**
108120
client.setPostfixWildcard(false);
109121
```
110122

123+
124+
#### Set enableLogicalOperators
125+
```js
126+
// (default: false)
127+
// enableLogicalOperators(true) = Support user specified logical operators (and/or/not) in the search query like "cat and dog"
128+
// enableLogicalOperators(false) = Treat logical operators in the search query as literal strings
129+
client.enableLogicalOperators(true);
130+
```
131+
132+
#### Set cacheResponseTime
133+
Caching the response, define the time-to-live of the cache.
134+
135+
```js
136+
// Specify time-to-live value in seconds
137+
client.setCacheResponseTime(3600);
138+
```
139+
140+
111141
### Pagination
112142
Set page number, page size and sorting parameters. It's possible to order results by:
113143
- relevance (descending)
@@ -197,13 +227,6 @@ client.setFilterObject(filter);
197227
client.setResultType('organic');
198228
```
199229

200-
#### Set enableLogicalOperators
201-
```js
202-
// (default: false)
203-
// enableLogicalOperators(true) = Support user specified logical operators (and/or/not) in the search query like "cat and dog"
204-
// enableLogicalOperators(false) = Treat logical operators in the search query as literal strings
205-
client.enableLogicalOperators(true);
206-
```
207230

208231
### Facets
209232
```js

dist/addsearch-js-client.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "addsearch-js-client",
3-
"version": "0.6.1",
3+
"version": "0.6.3",
44
"description": "AddSearch API JavaScript client",
55
"main": "index.js",
66
"jsdelivr": "./dist/addsearch-js-client.min.js",

src/apifetch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
8080
settingToQueryParam(settings.jwt, 'jwt') +
8181
settingToQueryParam(settings.resultType, 'resultType') +
8282
settingToQueryParam(settings.userToken, 'userToken') +
83-
settingToQueryParam(settings.numFacets, 'numFacets');
83+
settingToQueryParam(settings.numFacets, 'numFacets') +
84+
settingToQueryParam(settings.cacheResponseTime, 'cacheResponseWithTtlSeconds') +
85+
settingToQueryParam(settings.searchOperator, 'defaultOperator') +
86+
settingToQueryParam(settings.analyticsTag, 'analyticsTag');
8487

8588
// Add custom field filters
8689
if (settings.customFieldFilters) {

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,23 @@ var client = function(sitekey, privatekey) {
163163
this.setShuffleAndLimitTo = function(shuffleAndLimitTo) { this.settings.setShuffleAndLimitTo(shuffleAndLimitTo); }
164164
this.setFuzzyMatch = function(fuzzy) { this.settings.setFuzzyMatch(fuzzy); }
165165
this.setPostfixWildcard = function(wildcard) { this.settings.setPostfixWildcard(wildcard); }
166+
this.setCacheResponseTime = function(cacheResponseTime) { this.settings.setCacheResponseTime(cacheResponseTime) }
166167
this.setCollectAnalytics = function(collectAnalytics) { this.settings.setCollectAnalytics(collectAnalytics); }
168+
this.setAnalyticsTag = function(tagName) { this.settings.setAnalyticsTag(tagName) }
167169
this.setThrottleTime = function(delay) { this.settings.setThrottleTime(delay); }
168170
this.setStatsSessionId = function(id) { this.sessionId = id; }
169171
this.getStatsSessionId = function() { return this.sessionId; }
170172
this.enableLogicalOperators = function(enableLogicalOperators) { this.settings.enableLogicalOperators(enableLogicalOperators) }
173+
this.setSearchOperator = function(operator) { this.settings.setSearchOperator(operator) }
171174

172175
this.sendStatsEvent = function(type, keyword, data) {
173176
if (type === 'search') {
174177
var data = {
175178
action: 'search',
176179
session: this.sessionId,
177180
keyword: keyword,
178-
numberOfResults: data.numberOfResults
181+
numberOfResults: data.numberOfResults,
182+
analyticsTag: this.getSettings().analyticsTag
179183
};
180184
sendStats(this.apiHostname, this.sitekey, data);
181185
}
@@ -186,7 +190,8 @@ var client = function(sitekey, privatekey) {
186190
session: this.sessionId,
187191
keyword: keyword,
188192
docid: data.documentId,
189-
position: data.position
193+
position: data.position,
194+
analyticsTag: this.getSettings().analyticsTag
190195
};
191196
sendStats(this.apiHostname, this.sitekey, data);
192197
}

src/settings.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ var settings = function() {
1919
autocomplete: {
2020
size: 10
2121
},
22-
enableLogicalOperators: false
22+
searchOperator: null,
23+
enableLogicalOperators: false,
24+
cacheResponseTime: null
2325
};
2426

2527
this.getSettings = function() {
@@ -73,6 +75,10 @@ var settings = function() {
7375
this.settings.enableLogicalOperators = enableLogicalOperators;
7476
}
7577

78+
this.setCacheResponseTime = function(cacheResponseTime) {
79+
this.settings.cacheResponseTime = cacheResponseTime;
80+
}
81+
7682
this.setPostfixWildcard = function(wildcard) {
7783
this.settings.postfixWildcard = wildcard;
7884
}
@@ -81,6 +87,10 @@ var settings = function() {
8187
this.settings.collectAnalytics = collectAnalytics;
8288
}
8389

90+
this.setAnalyticsTag = function(tagName) {
91+
this.settings.analyticsTag = tagName;
92+
}
93+
8494
this.setCategoryFilters = function(categories) {
8595
this.settings.categories = categories;
8696
}
@@ -208,6 +218,13 @@ var settings = function() {
208218
this.settings.paging.page = this.settings.paging.page - 1;
209219
}
210220
}
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+
}
211228
}
212229

213230
module.exports = settings;

0 commit comments

Comments
 (0)