Added the basic search, no sorting, no extra stuff.

Added the basic search, no sorting, no extra stuff, raw from elasticsearch.
This commit is contained in:
Fillerino 2017-08-17 18:11:53 +02:00
parent e9ff812273
commit dd74ca7c0a
5 changed files with 73 additions and 16 deletions
server/controllers

View file

@ -1,14 +1,31 @@
import 'babel-polyfill';
import winston from 'winston';
import { sync, getStats } from '../utils/importer';
// import elasticSearch from 'elasticsearch';
/* const eclient = new elasticSearch.Client({
host: 'http://elastic:changeme@localhost:9200',
log : 'info',
}); */
import elasticsearch from 'elasticsearch';
const eclient = new elasticsearch.Client({
host: 'http://elastic:changeme@localhost:9200',
log : 'info',
});
function getSuggestions (input) {
return eclient.suggest({
index: 'claims',
body : {
'claim': {
'text' : input,
'completion': {
'field': 'suggest_name',
},
},
},
});
}
class LighthouseControllers {
/* eslint-disable no-param-reassign */
// Start syncing blocks...
startSync () {
winston.log('info', '[Importer] Started importer, indexing claims.');
sync(200000);
}
/**
@ -16,7 +33,10 @@ class LighthouseControllers {
* @param {ctx} Koa Context
*/
async search (ctx) {
ctx.body = 'Search...';
await getSuggestions(ctx.query.s).then(function (result) {
ctx.body = result;
});
// ctx.body = 'Search...';
}
/**