1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/lib/search.js

46 lines
933 B
JavaScript
Raw Normal View History

2014-05-07 17:29:47 +02:00
var lunr = require('lunr')
, localList = require('./local-list');
var Search = function() {
2014-05-07 17:29:47 +02: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 17:29:47 +02:00
});
};
Search.prototype = {
query: function(q) {
2014-05-07 20:08:29 +02:00
return this.index.search(q);
2014-05-07 17:29:47 +02:00
},
2014-05-07 20:08:29 +02:00
add: function(package) {
this.index.add({
id: package.name,
name: package.name,
description: package.description,
author: package._npmUser.name
2014-05-07 17:29:47 +02:00
});
2014-05-07 20:08:29 +02:00
},
2014-05-08 23:48:15 +02:00
remove: function(name) {
this.index.remove({
id: name
});
},
2014-05-07 20:08:29 +02: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 17:29:47 +02:00
}
};
module.exports = new Search();