Content Claim type filters #135

Closed
tiger5226 wants to merge 2 commits from content_filters_mb into master
4 changed files with 189 additions and 136 deletions

File diff suppressed because one or more lines are too long

View file

@ -68,6 +68,30 @@
"schema": {
"type": "boolean"
}
},
{
"in": "query",
"name": "contentType",
"description": "Filter by MIME type.",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "mediaType",
"description": "Filter by media type, can be audio, video, image, application, text or cad.",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "claimType",
"description": "Return channels or files only, value can be 'channel' or 'file'.",
"schema": {
"type": "string"
}
}
],
"responses": {

View file

@ -255,14 +255,37 @@ 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 = [];
var bidStateFilter = {'bool': {'must_not': {'match': { 'bid_state': 'Accepted' }}}};
if (input.nsfw === 'true' || input.nsfw === 'false') {
const nsfwFilter = {'match': {'value.stream.metadata.nsfw': input.nsfw}};
filters.push(nsfwFilter);
}
if (input.contentType !== undefined) {
const contentFilter = {'match_phrase': {'value.stream.source.contentType': getEscapedQuery(input.contentType)}};
filters.push(contentFilter);
}
if (input.mediaType !== undefined) {
const mediaTypes = ['audio', 'video', 'text', 'application', 'image'];
if (mediaTypes.includes(input.mediaType)) {
const mediaFilter = {'match_phrase_prefix': {'value.stream.source.contentType': input.mediaType + '\\/'}};
filters.push(mediaFilter);
neb-b commented 2018-11-29 21:55:48 +01:00 (Migrated from github.com)
Review

I think it would be nice if someone could pass in more than one contentType/mediaType in these queries. That would allow even more fine tuned search in the app.

search?contentType=type1,type2

I think it would be nice if someone could pass in more than one contentType/mediaType in these queries. That would allow even more fine tuned search in the app. `search?contentType=type1,type2`
marcdeb1 commented 2018-11-29 22:19:56 +01:00 (Migrated from github.com)
Review

Indeed it's a good idea. I will add it

Indeed it's a good idea. I will add it
marcdeb1 commented 2018-12-02 11:10:58 +01:00 (Migrated from github.com)
Review

It was added to PR #124

It was added to PR #124
} else if (input.mediaType === 'cad') {
const cadTypes = ['SKP', 'simplify3d_stl'];
const cadFilter = {'terms': {'value.stream.source.contentType': cadTypes}};
filters.push(cadFilter);
}
}
if (input.claimType === 'channel' || input.claimType === 'file') {
var query = '';
if (input.claimType === 'channel') {
query = 'certificateType';
} else if (input.claimType === 'file') {
query = 'streamType';
}
const claimTypeFilter = {'match': {'value.claimType': query}};
filters.push(claimTypeFilter);
}
if (filters.length > 0) {
const filterQuery = [
{

View file

@ -20,6 +20,9 @@ router.get('/', LighthouseControllers.info);
* - (query) size {Integer} The amount of results to return at max
* - (query) from {Integer} The number to start from, good for pagination
* - (query) nsfw {Boolean} If search should return nsfw content or not.
* - (query) contentType {String} Filter by MIME type.
* - (query) mediaType {String} Filter by media type, can be audio, video, image, application, text or cad.
* - (query) claimType {String} Return channels or files only, value can be 'channel' or 'file'.
* responses:
* 200:
* description: The search API returns an array of the found matching search items.