0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/lib/search.js

46 lines
933 B
JavaScript
Raw Normal View History

2014-05-07 10:29:47 -05:00
var lunr = require('lunr')
, localList = require('./local-list');
var Search = function() {
2014-05-07 10:29:47 -05:00
this.index = lunr(function () {
this.field('name', {boost: 10});
this.field('description', {boost: 4});
this.field('author', {boost: 6});
this.field('readme');
2014-05-07 10:29:47 -05:00
});
};
Search.prototype = {
query: function(q) {
2014-05-07 13:08:29 -05:00
return this.index.search(q);
2014-05-07 10:29:47 -05:00
},
2014-05-07 13:08:29 -05:00
add: function(package) {
this.index.add({
id: package.name,
name: package.name,
description: package.description,
author: package._npmUser.name
2014-05-07 10:29:47 -05:00
});
2014-05-07 13:08:29 -05:00
},
2014-05-08 16:48:15 -05:00
remove: function(name) {
this.index.remove({
id: name
});
},
2014-05-07 13:08:29 -05:00
reindex: function() {
var self = this;
this.storage.get_local(function(err, packages) {
var i = packages.length;
while(i--) {
self.add(packages[i]);
}
});
},
configureStorage: function(storage) {
this.storage = storage;
this.reindex();
2014-05-07 10:29:47 -05:00
}
};
module.exports = new Search();