diff options
author | Marvin Borner | 2018-11-08 18:19:13 +0100 |
---|---|---|
committer | Marvin Borner | 2018-11-08 18:19:13 +0100 |
commit | d243f31f7d245efce4bd857b32dc758205c28758 (patch) | |
tree | d615c1d5443aeea0ab7dd99c2bd08b34e6ec66f6 | |
parent | 641ed66837dd4bd45c977978609fb38cbeac9319 (diff) |
Improved search algorithms
-rw-r--r-- | app.js | 6 | ||||
-rw-r--r-- | database.js | 4 | ||||
-rw-r--r-- | routes/search.js (renamed from routes/index.js) | 6 | ||||
-rw-r--r-- | routes/suggest.js | 9 |
4 files changed, 19 insertions, 6 deletions
@@ -4,7 +4,8 @@ const path = require('path'); const cookieParser = require('cookie-parser'); const logger = require('morgan'); -const indexRouter = require('./routes/index'); +const searchRouter = require('./routes/search'); +const suggestRouter = require('./routes/suggest'); const app = express(); @@ -14,7 +15,8 @@ app.use(express.urlencoded({extended: false})); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); -app.use('/', indexRouter); +app.use('/search', searchRouter); +app.use('/suggest', suggestRouter); // catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/database.js b/database.js index e080d39..f48f87e 100644 --- a/database.js +++ b/database.js @@ -5,7 +5,7 @@ const esClient = new elasticsearch.Client({ }); module.exports = { - index: function bulkIndex(index, type, data) { + index: (index, type, data) => { let bulkBody = []; data.forEach(item => { @@ -32,7 +32,7 @@ module.exports = { }) .catch(console.err); }, - search: function search(index, body) { + search: (index, body) => { return esClient.search({index: index, body: body}); } };
\ No newline at end of file diff --git a/routes/index.js b/routes/search.js index 570aea0..c861f61 100644 --- a/routes/index.js +++ b/routes/search.js @@ -2,13 +2,15 @@ const database = require("../database"); const express = require("express"); const router = express.Router(); -/* GET home page. */ router.get('/', (req, res, next) => { database.search("crawled", { size: 20, from: 0, query: { - match_all: {} + multi_match: { + query: req.query.q, + fuzziness: 3 // decrease for more specific results + } } }).then(results => { res.json(results.hits) diff --git a/routes/suggest.js b/routes/suggest.js new file mode 100644 index 0000000..352619f --- /dev/null +++ b/routes/suggest.js @@ -0,0 +1,9 @@ +const database = require("../database"); +const express = require("express"); +const router = express.Router(); + +router.get("/", (req, res, next) => { + res.json({message: "NOT INTEGRATED YET!"}) +}); + +module.exports = router;
\ No newline at end of file |