diff --git a/package.json b/package.json index 1f38f75..7a6486c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,12 @@ }, "dependencies": { "babel-polyfill": "^6.5.0", + "bitcoin-promise": "filipnyquist/node-bitcoin-promise#c3eb4bea552a7a136a4a1405d831da3e92f2efea", + "bluebird": "^3.5.0", + "chalk": "^2.0.1", + "elasticsearch": "^13.2.0", "glob": "^7.1.1", + "jsonfile": "^3.0.1", "jsonwebtoken": "^7.2.1", "koa": "^2.0.0-alpha.7", "koa-bodyparser": "^3.0.0", @@ -40,15 +45,11 @@ "koa-jwt": "^2.1.0", "koa-logger": "^2.0.0", "koa-router": "^7.0.0", - "bitcoin-promise": "filipnyquist/node-bitcoin-promise#c3eb4bea552a7a136a4a1405d831da3e92f2efea", - "bluebird": "^3.5.0", - "chalk": "^2.0.1", - "elasticsearch": "^13.2.0", - "jsonfile": "^3.0.1", "limited-request-queue": "^3.0.4", "ora": "^1.3.0", "request": "^2.81.0", - "request-promise": "^4.2.1" + "request-promise": "^4.2.1", + "winston": "^2.3.1" }, "devDependencies": { "babel-cli": "^6.5.1", diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index 47cae57..c5cd8ea 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -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...'; } /** diff --git a/server/index.js b/server/index.js index 5945def..b5c11fd 100644 --- a/server/index.js +++ b/server/index.js @@ -4,6 +4,11 @@ import logger from 'koa-logger'; import helmet from 'koa-helmet'; import routing from './routes/'; import { port } from './config'; +import winston from 'winston'; + +// Setup logging +winston.remove(winston.transports.Console); +winston.add(winston.transports.Console, {colorize: true}); // Create Koa Application const app = new Koa(); @@ -16,6 +21,6 @@ app routing(app); // Start the application -app.listen(port, () => console.log(`✅ The server is running at http://localhost:${port}/`)); +app.listen(port, () => winston.log('info', `Lighthouse API server is running at http://localhost:${port}/`)); export default app; diff --git a/server/utils/importer/index.js b/server/utils/importer/index.js index 70b508b..04012fd 100644 --- a/server/utils/importer/index.js +++ b/server/utils/importer/index.js @@ -51,7 +51,7 @@ function send (arr) { // Modular change output here :) if (claim.name && claim.value) { claim.suggest_name = { input : claim.name, - weight: 20, + weight: 30, }; if (claim.value.claimType === 'streamType' && claim.value.stream.metadata && claim.value.stream.metadata.description) { claim.suggest_desc = { @@ -66,7 +66,7 @@ function send (arr) { // Modular change output here :) id : claim.claimId, body : claim, }, function (error, response) { - if (error) { status.err = error } + if (error) { status.err = error; console.log(error) } }); }); } diff --git a/yarn.lock b/yarn.lock index 3b201df..4f14d63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -144,6 +144,10 @@ async@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" +async@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/async/-/async-1.0.0.tgz#f8fc04ca3a13784ade9e1641af98578cfbd647a9" + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -862,6 +866,10 @@ color-name@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" +colors@1.0.x: + version "1.0.3" + resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" + combined-stream@^1.0.5, combined-stream@~1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" @@ -967,6 +975,10 @@ cryptiles@2.x.x: dependencies: boom "2.x.x" +cycle@1.0.x: + version "1.0.3" + resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2" + d@1: version "1.0.0" resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f" @@ -1388,6 +1400,10 @@ extsprintf@1.3.0, extsprintf@^1.2.0: version "1.3.0" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" +eyes@0.1.x: + version "0.1.8" + resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" + fast-levenshtein@~2.0.4: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" @@ -1998,7 +2014,7 @@ isobject@^2.0.0: dependencies: isarray "1.0.0" -isstream@~0.1.2: +isstream@0.1.x, isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" @@ -3214,6 +3230,10 @@ sshpk@^1.7.0: jsbn "~0.1.0" tweetnacl "~0.14.0" +stack-trace@0.0.x: + version "0.0.10" + resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" + "statuses@>= 1.3.1 < 2", statuses@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" @@ -3526,6 +3546,17 @@ wide-align@^1.1.0: dependencies: string-width "^1.0.2" +winston@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/winston/-/winston-2.3.1.tgz#0b48420d978c01804cf0230b648861598225a119" + dependencies: + async "~1.0.0" + colors "1.0.x" + cycle "1.0.x" + eyes "0.1.x" + isstream "0.1.x" + stack-trace "0.0.x" + wordwrap@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"