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

46 lines
No EOL
933 B
JavaScript

var lunr = require('lunr')
, localList = require('./local-list');
var Search = function() {
this.index = lunr(function () {
this.field('name', {boost: 10});
this.field('description', {boost: 4});
this.field('author', {boost: 6});
this.field('readme');
});
};
Search.prototype = {
query: function(q) {
return this.index.search(q);
},
add: function(package) {
this.index.add({
id: package.name,
name: package.name,
description: package.description,
author: package._npmUser.name
});
},
remove: function(name) {
this.index.remove({
id: name
});
},
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();
}
};
module.exports = new Search();