Skip to content

Commit 2d8139b

Browse files
authored
Merge pull request #16 from AddSearch/new-setting-ignoreLogicalOperatorCase
add a new setting ignoreLogicalOperatorCase, default: false
2 parents c7122af + d9a1053 commit 2d8139b

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
node_modules

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ client.setFilterObject(filter);
197197
client.setResultType('organic');
198198
```
199199

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+
```
207+
200208
### Facets
201209
```js
202210
// Declare fields for faceting. Number of hits found from
@@ -525,4 +533,4 @@ Built bundle is saved under the *dist/* folder
525533

526534
## Support
527535
Feel free to send any questions, ideas, and suggestions at [support@addsearch.com](mailto:support@addsearch.com) or
528-
visit [addsearch.com](https://www.addsearch.com/) for more information.
536+
visit [addsearch.com](https://www.addsearch.com/) for more information.

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
1616
return '&' + key + '=' + setting;
1717
}
1818
return '';
19-
}
19+
};
2020

2121

2222
// Validate query type
@@ -41,7 +41,9 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
4141
kw = settings.keyword;
4242

4343
// Boolean operators (AND, OR, NOT) uppercase
44-
kw = kw.replace(/ and /g, ' AND ').replace(/ or /g, ' OR ').replace(/ not /g, ' NOT ');
44+
kw = settings.enableLogicalOperators ?
45+
kw.replace(/ and /g, ' AND ').replace(/ or /g, ' OR ').replace(/ not /g, ' NOT ') :
46+
kw.replace(/ AND /g, ' and ').replace(/ OR /g, ' or ').replace(/ NOT /g, ' not ');
4547

4648
// Escape
4749
kw = encodeURIComponent(kw);
@@ -173,4 +175,4 @@ var executeApiFetch = function(apiHostname, sitekey, type, settings, cb, fuzzyRe
173175
cb({error: {response: RESPONSE_SERVER_ERROR, message: 'invalid server response'}});
174176
});
175177
};
176-
module.exports = executeApiFetch;
178+
module.exports = executeApiFetch;

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ var client = function(sitekey, privatekey) {
159159
this.setThrottleTime = function(delay) { API_THROTTLE_TIME_MS = delay; }
160160
this.setStatsSessionId = function(id) { this.sessionId = id; }
161161
this.getStatsSessionId = function() { return this.sessionId; }
162+
this.enableLogicalOperators = function(enableLogicalOperators) { this.settings.enableLogicalOperators(enableLogicalOperators) }
162163

163164
this.sendStatsEvent = function(type, keyword, data) {
164165
if (type === 'search') {
@@ -194,4 +195,4 @@ var client = function(sitekey, privatekey) {
194195
}
195196
}
196197

197-
module.exports = client;
198+
module.exports = client;

src/settings.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var settings = function() {
1717
facetFields: [],
1818
autocomplete: {
1919
size: 10
20-
}
20+
},
21+
enableLogicalOperators: false
2122
};
2223

2324
this.getSettings = function() {
@@ -63,6 +64,10 @@ var settings = function() {
6364
this.settings.fuzzy = fuzzy;
6465
}
6566

67+
this.enableLogicalOperators = function(enableLogicalOperators) {
68+
this.settings.enableLogicalOperators = enableLogicalOperators;
69+
}
70+
6671
this.setPostfixWildcard = function(wildcard) {
6772
this.settings.postfixWildcard = wildcard;
6873
}
@@ -200,4 +205,4 @@ var settings = function() {
200205
}
201206
}
202207

203-
module.exports = settings;
208+
module.exports = settings;

0 commit comments

Comments
 (0)