Improvements to search relevancy and seperation of search/autocomplete feature.
-- Removed `getSuggestion` -- Added `getResults` -- Added `getAutoComplete` Restructured to search query to bool query that searches on a claims name, title, author and keywords in descripton -- `it's a disaster` now shows in a search for `disaster` autocomplete also returned correctly for the same example.
This commit is contained in:
parent
d5470ce0e3
commit
58c0fa6aa6
4 changed files with 78 additions and 24 deletions
File diff suppressed because one or more lines are too long
|
@ -8,55 +8,104 @@ const loggerStream = winstonStream(winston, 'info');
|
||||||
|
|
||||||
const eclient = new elasticsearch.Client({
|
const eclient = new elasticsearch.Client({
|
||||||
host: 'http://localhost:9200',
|
host: 'http://localhost:9200',
|
||||||
log : {
|
|
||||||
level : 'info',
|
log: {
|
||||||
type : 'stream',
|
level: 'info',
|
||||||
|
type: 'stream',
|
||||||
stream: loggerStream,
|
stream: loggerStream,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function getSuggestions (input) {
|
function getResults(input) {
|
||||||
return eclient.suggest({
|
return eclient.search({
|
||||||
index: 'claims',
|
index: "claims",
|
||||||
body : {
|
body: {
|
||||||
'claim': {
|
"query": {
|
||||||
'text' : input,
|
"bool": {
|
||||||
'completion': {
|
"must": {
|
||||||
'field': 'suggest_name',
|
"query_string": {
|
||||||
},
|
"query": input.trim(),
|
||||||
},
|
"fields": [
|
||||||
},
|
"name",
|
||||||
|
"value.stream.metadata.author",
|
||||||
|
"value.stream.metadata.title",
|
||||||
|
"value.stream.metadata.description"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAutoComplete(input) {
|
||||||
|
return eclient.search({
|
||||||
|
index: "claims",
|
||||||
|
_source: ["name", "value.stream.metadata.title", "value.stream.metadata.author"],
|
||||||
|
body: {
|
||||||
|
"query": {
|
||||||
|
"bool": {
|
||||||
|
"must": {
|
||||||
|
"query_string": {
|
||||||
|
"query": input.trim(),
|
||||||
|
"fields": [
|
||||||
|
"name",
|
||||||
|
"value.stream.metadata.title",
|
||||||
|
"value.stream.metadata.author"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class LighthouseControllers {
|
class LighthouseControllers {
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
// Start syncing blocks...
|
// Start syncing blocks...
|
||||||
startSync () {
|
startSync() {
|
||||||
winston.log('info', '[Importer] Started importer, indexing claims.');
|
winston.log('info', '[Importer] Started importer, indexing claims.');
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Search api here
|
* Search API Endpoint.
|
||||||
* @param {ctx} Koa Context
|
* @param {ctx} Koa Context
|
||||||
*/
|
*/
|
||||||
async search (ctx) {
|
async search(ctx) {
|
||||||
await getSuggestions(ctx.query.s).then(function (result) {
|
await getResults(ctx.query.s).then(function (result) {
|
||||||
let results = result.claim[0].options;
|
console.log(result.hits.hits);
|
||||||
|
let results = result.hits.hits;
|
||||||
let cResults = [];
|
let cResults = [];
|
||||||
for (let pResult of results) {
|
for (let pResult of results) {
|
||||||
cResults.push(pResult._source);
|
cResults.push(pResult._source);
|
||||||
}
|
}
|
||||||
ctx.body = cResults;
|
ctx.body = cResults;
|
||||||
});
|
});
|
||||||
// ctx.body = 'Search...';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autocomplete API Endpoint.
|
||||||
|
* @param {ctx} Koa Context
|
||||||
|
*/
|
||||||
|
async autoComplete(ctx) {
|
||||||
|
await getAutoComplete(ctx.query.s).then(function (result) {
|
||||||
|
console.log(result.hits.hits);
|
||||||
|
let results = result.hits.hits;
|
||||||
|
let cResults = [];
|
||||||
|
for (let pResult of results) {
|
||||||
|
cResults.push(pResult._source);
|
||||||
|
}
|
||||||
|
ctx.body = cResults;
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Info about the api here
|
* Info about the api here
|
||||||
* @param {ctx} Koa Context
|
* @param {ctx} Koa Context
|
||||||
*/
|
*/
|
||||||
async info (ctx) {
|
async info(ctx) {
|
||||||
ctx.body = 'Info...';
|
ctx.body = 'Info...';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +113,7 @@ class LighthouseControllers {
|
||||||
* Status of the api here
|
* Status of the api here
|
||||||
* @param {ctx} Koa Context
|
* @param {ctx} Koa Context
|
||||||
*/
|
*/
|
||||||
async status (ctx) {
|
async status(ctx) {
|
||||||
ctx.body = getStats();
|
ctx.body = getStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,10 @@ router.get('/', LighthouseControllers.info);
|
||||||
// GET /api/search
|
// GET /api/search
|
||||||
router.get('/search', LighthouseControllers.search);
|
router.get('/search', LighthouseControllers.search);
|
||||||
|
|
||||||
|
|
||||||
|
// GET /api/search
|
||||||
|
router.get('/autocomplete', LighthouseControllers.autoComplete);
|
||||||
|
|
||||||
// GET /api/ligthouse/status
|
// GET /api/ligthouse/status
|
||||||
router.get('/status', LighthouseControllers.status);
|
router.get('/status', LighthouseControllers.status);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ import appRoot from 'app-root-path';
|
||||||
|
|
||||||
const loggerStream = winstonStream(winston, 'info');
|
const loggerStream = winstonStream(winston, 'info');
|
||||||
const eclient = new elasticsearch.Client({
|
const eclient = new elasticsearch.Client({
|
||||||
host: 'http://elastic:changeme@localhost:9200',
|
host: 'http://localhost:9200',
|
||||||
|
|
||||||
log : {
|
log : {
|
||||||
level : 'info',
|
level : 'info',
|
||||||
type : 'stream',
|
type : 'stream',
|
||||||
|
|
Loading…
Reference in a new issue