-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jarvys/master
Add exclusion syntax 👍
- Loading branch information
Showing
3 changed files
with
126 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,8 @@ var searchQueryObj = searchQuery.parse(query, options); | |
|
||
You can configure what keywords and ranges the parser should accept with the options argument. | ||
It accepts 2 values: | ||
* `keywords`, that can be separated by commas (,) | ||
* `ranges`, that can be separated by a hyphen (-) | ||
* `keywords`, that can be separated by commas (,) | ||
* `ranges`, that can be separated by a hyphen (-) | ||
|
||
Both values take an array of strings, as in the example just above. | ||
|
||
|
@@ -67,9 +67,20 @@ var parsedQueryWithOptions = searchQuery.parse(query, options); | |
// parsedQueryWithOptions is now 'a query with just text' | ||
``` | ||
|
||
You can also use exclusion syntax, like `-from:[email protected] name:hello,world` . And it will return : | ||
|
||
```javascript | ||
{ | ||
name: ['hello', 'world'], | ||
exclusion: { | ||
from: ['[email protected]'] | ||
} | ||
} | ||
``` | ||
|
||
## Testing | ||
|
||
The 17 tests are written using the BDD testing framework should.js, and run with mocha. | ||
The 20 tests are written using the BDD testing framework should.js, and run with mocha. | ||
|
||
Run `npm install should` and `npm install -g mocha` to install them both. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,4 +223,39 @@ describe('Search query syntax parser', function () { | |
}); | ||
|
||
|
||
it('should parse a single keyword query in exclusion syntax', function() { | ||
var searchQuery = '-from:[email protected]'; | ||
var options = {keywords: ['from']}; | ||
var parsedSearchQuery = searchquery.parse(searchQuery, options); | ||
|
||
parsedSearchQuery.should.be.an.Object; | ||
parsedSearchQuery.exclude.should.be.an.Object; | ||
parsedSearchQuery.exclude.should.have.property('from', '[email protected]'); | ||
parsedSearchQuery.should.not.have.property('text'); | ||
}); | ||
|
||
it('should concatenate a keyword multiple values in exclusion syntax', function() { | ||
var searchQuery = '-from:[email protected],[email protected]'; | ||
var options = {keywords: ['from']}; | ||
var parsedSearchQuery = searchquery.parse(searchQuery, options); | ||
|
||
parsedSearchQuery.should.be.an.Object; | ||
parsedSearchQuery.exclude.should.be.an.Object; | ||
parsedSearchQuery.exclude.from.should.containEql('[email protected]'); | ||
parsedSearchQuery.exclude.from.should.containEql('[email protected]'); | ||
parsedSearchQuery.should.not.have.property('text'); | ||
}); | ||
|
||
it('should support keywords which appear multiple times with exclusion syntax', function() { | ||
var searchQuery = '-from:[email protected],[email protected] -from:[email protected]'; | ||
var options = {keywords: ['from']}; | ||
var parsedSearchQuery = searchquery.parse(searchQuery, options); | ||
|
||
parsedSearchQuery.should.be.an.Object; | ||
parsedSearchQuery.exclude.should.be.an.Object; | ||
parsedSearchQuery.exclude.from.should.containEql('[email protected]'); | ||
parsedSearchQuery.exclude.from.should.containEql('[email protected]'); | ||
parsedSearchQuery.exclude.from.should.containEql('[email protected]'); | ||
parsedSearchQuery.should.not.have.property('text'); | ||
}); | ||
}); |