Added NSFW filter to query #122
1 changed files with 23 additions and 3 deletions
|
@ -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),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue