Merge pull request #122 from marcdeb1/nsfw_filter

Added NSFW filter to query
This commit is contained in:
filipnyquist 2018-10-21 22:34:16 +02:00 committed by GitHub
commit e3e6d7c94d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,6 +188,7 @@ function getResults (input) {
},
},
],
'filter': getFilters(input),
},
},
size: input.size,
@ -248,10 +249,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
// 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) {
@ -265,7 +285,7 @@ function getAutoComplete (query) {
query: {
bool: {
must : getAutoCompleteQuery(query),
filter: getFilter(query),
filter: getFilters(query),
},
},
},