nepsilon / search-query-parser

A simple parser for advanced search query syntax
https://www.npmjs.org/package/search-query-parser
MIT License
253 stars 40 forks source link

Add support for tokenized terms, quoted terms, and negation of terms. #18

Closed jonestristand closed 6 years ago

jonestristand commented 6 years ago

Added support for returning tokenized text terms instead of a string, e.g.: search: 'plain pyjama wear'

{
  text: ['plain', 'pyjama', 'wear'],
  [...]
}

Also added support for quoted term literals, e.g.: search: 'plain "pyjama wear" dinner'

{
  text: ['plain', 'pyjama wear', 'dinner'],
  [...]
}

Finally, support for negation of text terms, e.g.: search: '-plain -"pyjama wear" dinner'

{
  text: ['dinner'],
  exclude: {
    text: ['plain', 'pyjama wear']
  }
  [...]
}

None of these changes should break existing projects. Negation of text terms is enabled by default, and tokenized return of terms is enabled by passing tokenize: true in options

Tests updated for new functionality, all passing.

Cheers, Tristan

jonestristand commented 6 years ago

FYI Travis CI failure above is a result of a strict mode issue with mocha, not with the code in this PR

nepsilon commented 6 years ago

Indeed, tests passed for me. Thanks a lot for your contribution!

nepsilon commented 6 years ago

@jonestristand Could you also update the README to document this new usage? Copy/pasting your first PR comment is fine. Thanks!

jonestristand commented 6 years ago

I've updated the README.md and will submit a new PR with those changes (PR#19). Thanks!

FYI your README badge is showing build:failing due to the above issue with travis CI... Might be worth updating the build config to pass again. I think all that is needed is to update the config to use a more recent version of node.js as it is still using node v0.10 and v0.11...

nepsilon commented 6 years ago

Thanks. Merged and updated the Travis's node version.