From 44ea0093ef219f3675058b6aa524678532a9073d Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Wed, 17 Oct 2018 11:42:25 +0200 Subject: [PATCH 1/3] Added NSFW filter to query --- server/controllers/lighthouse.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index e33fca7..c2ebc77 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -184,6 +184,7 @@ function getResults (input) { }, }, ], + 'filter': getFilters(input) }, }, size: input.size, @@ -223,10 +224,30 @@ function getAutoCompleteQuery (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 - +function getFilters (input) { + // 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 + var filters = []; + if(input.nsfw === "true" || input.nsfw === "false") { + const nsfwFilter = {"match": {"value.stream.metadata.nsfw": input.nsfw}} + filters.push(nsfwFilter); + } + if(filters.length > 0) { + const filterQuery = { + "nested": { + "path": "value", + "query": { + "bool": { + "must": filters + } + } + } + }; + return filterQuery; + } + else { + return []; + } } function getAutoComplete (query) { From b4052fc921e38c7a6f23f1ab95c14e49573f1f8a Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Thu, 18 Oct 2018 08:36:04 +0200 Subject: [PATCH 2/3] Syntax and indentationn --- server/controllers/lighthouse.js | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index c2ebc77..fcf947c 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -184,7 +184,7 @@ function getResults (input) { }, }, ], - 'filter': getFilters(input) + 'filter': getFilters(input), }, }, size: input.size, @@ -225,29 +225,29 @@ function getAutoCompleteQuery (query) { } function getFilters (input) { - // 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 - var filters = []; - if(input.nsfw === "true" || input.nsfw === "false") { - const nsfwFilter = {"match": {"value.stream.metadata.nsfw": input.nsfw}} - filters.push(nsfwFilter); - } - if(filters.length > 0) { - const filterQuery = { - "nested": { - "path": "value", - "query": { - "bool": { - "must": filters - } - } - } - }; - return filterQuery; - } - else { - return []; - } + // 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 + var filters = []; + if (input.nsfw === 'true' || input.nsfw === 'false') { + const nsfwFilter = {'match': {'value.stream.metadata.nsfw': input.nsfw}}; + filters.push(nsfwFilter); + } + if (filters.length > 0) { + const filterQuery = { + 'nested': { + 'path': 'value', + 'query': { + 'bool': { + 'must': filters, + } + } + } + }; + return filterQuery; + } + else { + return []; + } } function getAutoComplete (query) { From a409396f69e4265008531d0beeed4d361ad15820 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Sun, 21 Oct 2018 00:06:39 -0400 Subject: [PATCH 3/3] fixed some lint issues and function name --- server/controllers/lighthouse.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/controllers/lighthouse.js b/server/controllers/lighthouse.js index fcf947c..2e9c818 100644 --- a/server/controllers/lighthouse.js +++ b/server/controllers/lighthouse.js @@ -235,17 +235,16 @@ function getFilters (input) { if (filters.length > 0) { const filterQuery = { 'nested': { - 'path': 'value', + 'path' : 'value', 'query': { 'bool': { 'must': filters, - } - } - } + }, + }, + }, }; return filterQuery; - } - else { + } else { return []; } } @@ -261,7 +260,7 @@ function getAutoComplete (query) { query: { bool: { must : getAutoCompleteQuery(query), - filter: getFilter(query), + filter: getFilters(query), }, }, },