Adding channel_id search back in. Reworked to avoid null queries being passed in.

Signed-off-by: Mark Beamer Jr <markbeamerjr@gmail.com>
This commit is contained in:
Mark Beamer Jr 2019-09-22 21:52:15 -04:00
parent e9598d6b76
commit 715ecc3d92
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973

View file

@ -40,33 +40,38 @@ function getResults (input) {
let escapedQuery = getEscapedQuery(trimmedQuery); let escapedQuery = getEscapedQuery(trimmedQuery);
let washedQuery = getEscapedQuery(getWashedQuery(trimmedQuery)); let washedQuery = getEscapedQuery(getWashedQuery(trimmedQuery));
let effectiveFactor = '0.00000000001'; let effectiveFactor = '0.00000000001';
// Search is split up into different parts, all search parts goes under this line. const dynamicFilters = () => {
let channelidSearch; let queries = [];
if (input.channel_id !== undefined) { // Search is split up into different parts, all search parts goes under this line.
channelidSearch = { // If we got a channel_id argument, lets filter out only that channel_id if (input.channel_id !== undefined) {
'bool': { const channelidSearch = { // If we got a channel_id argument, lets filter out only that channel_id
'must': { 'bool': {
'query_string': { 'must': {
'fields': ['channel_id'], 'query_string': {
'query' : getEscapedQuery(input.channel_id.trim()), 'fields': ['channel_id'],
'query' : getEscapedQuery(input.channel_id.trim()),
},
}, },
}, },
}, };
}; queries.push(channelidSearch);
} }
let channelSearch; if (input.channel !== undefined) { // If we got a channel argument, lets filter out only that channel
if (input.channel !== undefined) { // If we got a channel argument, lets filter out only that channel const channelSearch = {
channelSearch = { 'bool': {
'bool': { 'must': {
'must': { 'query_string': {
'query_string': { 'fields': ['channel'],
'fields': ['channel'], 'query' : getEscapedQuery(input.channel.trim()),
'query' : getEscapedQuery(input.channel.trim()), },
}, },
}, },
}, };
}; queries.push(channelSearch);
} }
return queries;
};
const conBoost = { // Controlling claims should get higher placement in search results. const conBoost = { // Controlling claims should get higher placement in search results.
'match': { 'match': {
'bid_state': { 'bid_state': {
@ -268,8 +273,7 @@ function getResults (input) {
funcScoreChannelWeight, funcScoreChannelWeight,
], ],
'must': [ 'must': [
channelSearch, ...dynamicFilters(),
// channelidSearch, // Commented for now to prevent query error while I investigate.
{ {
'bool': { 'bool': {
'should': [ 'should': [
@ -292,7 +296,7 @@ function getResults (input) {
}, },
}, },
}; };
// console.log('QUERY: ', esQuery); // console.log('QUERY: ', JSON.stringify(esQuery));
return eclient.search(esQuery); return eclient.search(esQuery);
} }