1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/lib/search.js
Alex Kocharin 8d841ea8e3 hide local-list.json to storage/.sinopia-db.json
It was always in the current folder, which is a bad thing.
2014-09-07 00:50:34 +04:00

46 lines
920 B
JavaScript

var lunr = require('lunr')
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 ? 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();