hapi-algolia-search
Hapi plugin wrapping the JS Algolia Search client
Algolia is a "Search Engine as a Service", with high performance, great docs, and API clients available for many languages. Check it out !
Table of Contents
Install
$ npm install hapi-algolia-search
Register
Manually
const HapiAlgoliaSearch = require('hapi-algolia-search');
const plugin = {
register: HapiAlgoliaSearch,
options: {
appId: 'ABCDEFGHIJ',
apiKey: 'LKHFDLSKHFLKSDFHLSKHFSLKFHLSKHDFLSKHDFLKHSDFL',
indexPrefix: 'dev_',
indexes: {
Users: 'usersIndex',
Products: 'productsIndex'
},
clientOptions: {
timeout: 1000
}
}
};
server.register(plugin, (err) => {
if (err) {
console.log('Failed loading plugin');
}
});
Via manifest
{
"servers": [{
"port": 8080
}],
"plugins": {
"hapi-algolia-search": {
"appId": "ABCDEFGHIJ",
"apiKey": "LKHFDLSKHFLKSDFHLSKHFSLKFHLSKHDFLSKHDFLKHSDFL",
"indexPrefix": "dev_",
"indexes": {
"Users": "usersIndex",
"Products": "productsIndex"
},
"clientOptions": {
"timeout": 1000
}
}
}
}
Configuration options
Usage
In your route handler :
server.route({
method: "GET",
path: "/search/{term}",
handler: function(request, reply) {
const term = request.params.term;
const productIndex = request.server.plugins['hapi-algolia-search'].indexes.Products;
productsIndex.search(term, function(err, results){
if(err) { return reply(err); }
reply(results);
})
const algoliaClient = request.server.plugins['hapi-algolia-search'].client
client.search(.....
}
})
Questions and contributing
Any issues or questions (no matter how basic), open an issue. Please check if it's not an
issue with the Algolia API first. Also, please take the
initiative to include basic debugging information like operating system
and relevant version details such as:
$ npm version
Contributions are welcome. Your code should:
If you're changing something non-trivial, you may want to submit an issue
first.
License
MIT