From 00a41e9e190c555bf2695ca55e187674681c37ed Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Tue, 13 Mar 2018 21:37:57 -0400 Subject: [PATCH 1/2] using ^n on a field is only valid syntax for lycene. This caused the name field to never be search which resulted in channels not being searchable. I added the boost parameter which is what is supposed to be used. I made the weight 5 based tests around "super" which is a query that returns 1800 hits. The intention is to make sure that channels show up first in the results. --- server/controllers/lighthouse.js | 56 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index 404362e..c1ac149 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -18,7 +18,6 @@ const eclient = new elasticsearch.Client({ }, }); - function getResults (input) { if (input.size === undefined) input.size = 10; if (input.from === undefined) input.from = 0; @@ -31,7 +30,10 @@ function getResults (input) { 'should': [ { 'match': { - 'name^100': '*' + input.s.trim() + '*', + 'name': { + 'query': '*' + input.s.trim() + '*', + 'boost': 100, + }, }, }, { @@ -86,54 +88,54 @@ function getResults (input) { }); } -function getIndex() { +function getIndex () { // ideally, data is inserted into elastic search with an index that helps us query it faster/better results // A simple start is to default queries to be within the n months, and to make a new index each month. - return; + } -function getRoutingKey() { +function getRoutingKey () { // This is the most important field for performance. Being able to route the queries ahead of time can make typedowns insanely good. - return; + } -function getAutoCompleteQuery(query) { +function getAutoCompleteQuery (query) { return { multi_match: { - query: query.s.trim(), - type: 'phrase_prefix', - slop: 5, + query : query.s.trim(), + type : 'phrase_prefix', + slop : 5, max_expansions: 50, - fields: [ + fields : [ 'name', 'value.stream.metadata.author', 'value.stream.metadata.title', - 'value.stream.metadata.description' - ] - } + 'value.stream.metadata.description', + ], + }, }; } -function getFilter(query) { +function getFilter (query) { // this is the best place for putting things like filtering on the type of content // Perhaps we can add search param that will filter on how people have categorized / tagged their content - return; + } -function getAutoComplete(query) { +function getAutoComplete (query) { return eclient.search({ - index: getIndex(query) || 'claims', - routing: getRoutingKey(query), + index : getIndex(query) || 'claims', + routing : getRoutingKey(query), ignore_unavailable: true, // ignore error when date index does not exist - body: { - size: query.size || 5, - from: query.from || 0, + body : { + size : query.size || 5, + from : query.from || 0, query: { bool: { - must: getAutoCompleteQuery(query), - filter: getFilter(query) - } - } + must : getAutoCompleteQuery(query), + filter: getFilter(query), + }, + }, }, size: query.size, from: query.from, @@ -191,7 +193,7 @@ class LighthouseControllers { } } - var clean = new Array(); + var clean = []; for (var i = 0; i < cResults.length; i++) { if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) === -1) { clean.push(cResults[i]); From 90e2d3f64b45d0e0ddcf51afccc03fc03a1a1a50 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Tue, 13 Mar 2018 21:43:08 -0400 Subject: [PATCH 2/2] changed weight to 5 from 100. I made the weight 5 based on tests around "super" which is a query that returns 1800 hits. The intention is to make sure that channels show up first in the results. --- server/controllers/lighthouse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index c1ac149..d31a32d 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -32,7 +32,7 @@ function getResults (input) { 'match': { 'name': { 'query': '*' + input.s.trim() + '*', - 'boost': 100, + 'boost': 5, }, }, },