From 44ea0093ef219f3675058b6aa524678532a9073d Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Wed, 17 Oct 2018 11:42:25 +0200 Subject: [PATCH] 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) {