brianreavis / sifter.js

A library for textually searching arrays and hashes of objects by property (or multiple properties). Designed specifically for autocomplete.
1.09k stars 125 forks source link

Treat entire search string as token? #11

Open Jorenm opened 10 years ago

Jorenm commented 10 years ago

So "red car" would only match explicitly "red car", not red, car, reddit, carnage, etc.

hagabaka commented 9 years ago

I also think this should be added. I accomplished it with this hack:

// Treat search query as an entire token
    Sifter.prototype.tokenize = function(query) {
      if(!query || !query.length) {
        return [];
      } else {
        return [{
          string: query,
          regex: new RegExp(query, 'i')
        }];
      }
    };

It doesn't work if I just override tokenize for a single Sifter object for some reason.