search-text-tokenizer
A tokenizer for Google-like search queries
Last updated 4 years ago by tatsuyaoiw .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install search-text-tokenizer 
SYNC missed versions from official npm registry.

search-text-tokenizer

Build Status

A search query tokeniser inspired by Google.

  • Split a space-delimitered query string into an array of terms
  • Treat quoted terms as phrases
  • Support tagged terms (tag:term)
  • Detect excluded terms (-term)

Examples

var tokenizer = require( 'search-text-tokenizer' );

console.log( tokenizer( 'red bull' ) );
// [ { term: 'red' }, { term: 'bull' } ]

var result = console.log( tokenizer( '"red bull" "gives you wings"' ) );
// [ { term: 'red bull', phrase: true }, { term: 'gives you wings', phrase: true } ]

result = console.log( tokenizer( 'author:tolkien' ) );
// [ { term: 'tolkien', tag: 'author' } ]

result = console.log( tokenizer( '-car' ) );
// [ { term: 'car', exclude: true } ]

Installation

$ npm install search-text-tokenizer

Running test

To run the test suite enter these commands in the project directory.

$ npm install
$ npm test

License

MIT © Tatsuya Oiwa, Dannii Willis, James Anthony Bruno

Current Tags

  • 2.1.1                                ...           latest (4 years ago)

7 Versions

  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 3
Dependencies (1)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |