1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00
verdaccio/lib/search.js

35 lines
647 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() {
this.index = lunr(function () {
this.field('name', {boost: 10});
this.field('description');
this.field('author');
});
this.id = 0;
var packages = storage.get_local()
, i = packages.length;
while(i--) {
this.index(packages[i]);
}
};
Search.prototype = {
query: function(q) {
return index.search(q);
},
index: function(package) {
this.index.add({
id: ++this.id,
title: package.name,
description: package.description,
author: package._npmUser.name
});
}
};
module.exports = new Search();