0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

Added a search class

This commit is contained in:
Brian Peacock 2014-05-07 10:29:47 -05:00
parent c47f73f799
commit 27c032d53f
3 changed files with 38 additions and 2 deletions

View file

@ -18,6 +18,7 @@
npm adduser --registry {{ baseUrl }}
</code>
<h2>Packages:</h2>
{{#each packages}}
<article>
<h3>{{ name }} <small>v{{ version }}</small></h3>

View file

@ -122,14 +122,14 @@ module.exports = function(config_hash) {
console.log(d)
})
})*/
var template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.handlebars'), 'utf8'));
app.get('/', can('access'), function(req, res, next) {
res.setHeader('Content-Type', 'text/html');
storage.get_local(function(err, packages) {
res.send(template({
name: "Sinopia",
name: config.title || "Sinopia",
packages: packages,
baseUrl: req.protocol + '://' + req.get('host') + '/'
}));

35
lib/search.js Normal file
View file

@ -0,0 +1,35 @@
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();