Fast, compact full text search in pure javascript to support npm-kludge-search
.
var Purefts = require('pure-fts');
var p = new Purefts();
p.add({ name: 'foo', description: 'a foo thing' });
p.add({ name: 'bar', description: 'a bar thing' });
p.freeze('index');
var Purefts = require('pure-fts');
Purefts.thaw('index', function (err, p) {
p.get('foo', cb); # cb(err, data)
p.find({ name: 'foo'}, cb, done)
# returns { name: 'foo', description: 'a foo thing' }
p.search('thing', cb, done);
# returns [ 'foo', 'bar' ]
})
When there are two callbacks cb
and done
, cb
is called once with
each matching record, and done
is called after the search is
complete. When there is only one callback (for get
) it is called with
the matching record or NULL if missing.
To support the needs of npm-kludge-search
, this module assumes that
name
is the unique object key. The contents of the fields url
,
keywords
, name
and description
will be added to the full text
search index, in addition to the name
field of the objects in the
maintainers
array.
Any of these fields are allowed to be missing.
It would make sense to abstract this into a set of paths, if this module were going to be useful for general purpose fts indexing.
fts doesn't work right yet
index on keyword or author does not work