Added NSFW filter to query #122

Merged
marcdeb1 merged 3 commits from nsfw_filter into master 2018-10-21 22:34:17 +02:00

View file

@ -184,6 +184,7 @@ function getResults (input) {
}, },
}, },
], ],
'filter': getFilters(input),
}, },
}, },
size: input.size, size: input.size,
@ -223,10 +224,29 @@ function getAutoCompleteQuery (query) {
}; };
} }
function getFilter (query) { function getFilters (input) {
// this is the best place for putting things like filtering on the type of content // 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 // 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) { function getAutoComplete (query) {
@ -240,7 +260,7 @@ function getAutoComplete (query) {
query: { query: {
bool: { bool: {
must : getAutoCompleteQuery(query), must : getAutoCompleteQuery(query),
filter: getFilter(query), filter: getFilters(query),
}, },
}, },
}, },