Skip to content

Commit

Permalink
Support exclusions in custom quick filters
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Oct 11, 2023
1 parent 5b9af9d commit 16748ee
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 30 deletions.
6 changes: 6 additions & 0 deletions core/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#@formatter:off
- version: "v5.3.0"
date: "2023-10-11"
changes:
- type: "feature"
text: "Custom quickfilters may also contain exclamation marks (!) to filter out words."
final: true
- version: "v5.2.0"
date: "2023-09-22"
changes:
Expand Down
59 changes: 44 additions & 15 deletions core/src/main/resources/static/js/nzbhydra.js
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ angular.module('nzbhydraApp').controller('IndexerConfigSelectionBoxInstanceContr
},
{
name: "omgwtfnzbs",
host: "https://api.omgwtfnzbs.me"
host: "https://api.omgwtfnzbs.org"
},
{
name: "spotweb.com",
Expand Down Expand Up @@ -10234,22 +10234,51 @@ function SearchResultsController($stateParams, $scope, $q, $timeout, $document,
}
}
if ($scope.filterButtonsModel.custom !== null && !_.isEmpty($scope.filterButtonsModel.custom)) {
var requiresAnyOf = _.keys(_.pick($scope.filterButtonsModel.custom, function (value, key) {
return value
}));
if (requiresAnyOf.length === 0) {
return true;
}
var containsAtLeastOne = _.any(requiresAnyOf, function (required) {
if (item.title.toLowerCase().indexOf(required.toLowerCase()) > -1) {
return true;
var quickFilterWords = [];
_.each($scope.filterButtonsModel.custom, function (value, key) { //key is something like 'camts', value is true or false
if (value) {

_.each($scope.filterButtonsModelMap[key], function (string) {
Array.prototype.push.apply(quickFilterWords, string.split(" "));

});
}
});
if (quickFilterWords.length !== 0) {
var allMatch = _.all(quickFilterWords, function (word) {
if (word.startsWith("!")) {
if (word.length === 1) {
return true;
}
return item.title.toLowerCase().indexOf(word.substring(1)) === -1;
}
return item.title.toLowerCase().indexOf(word) > -1;
})

if (!allMatch) {
console.debug(item.title + " does not match all the terms of " + JSON.stringify(quickFilterWords));
filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
return false;
}
})
if (!containsAtLeastOne) {
console.debug(item.title + " does not contain any of the custom values' " + JSON.stringify(requiresAnyOf));
filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
return false;
}


// var requiresAnyOf = _.keys(_.pick($scope.filterButtonsModel.custom, function (value, key) {
// return value
// }));
// if (requiresAnyOf.length === 0) {
// return true;
// }
// var containsAtLeastOne = _.any(requiresAnyOf, function (required) {
// if (item.title.toLowerCase().indexOf(required.toLowerCase()) > -1) {
// return true;
// }
// })
// if (!containsAtLeastOne) {
// console.debug(item.title + " does not contain any of the custom values' " + JSON.stringify(requiresAnyOf));
// filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
// return false;
// }
}

if ($scope.foo.hideAlreadyDownloadedResults && item.downloadedAt !== null) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/static/js/nzbhydra.js.map

Large diffs are not rendered by default.

57 changes: 43 additions & 14 deletions core/ui-src/js/search-results-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,51 @@ function SearchResultsController($stateParams, $scope, $q, $timeout, $document,
}
}
if ($scope.filterButtonsModel.custom !== null && !_.isEmpty($scope.filterButtonsModel.custom)) {
var requiresAnyOf = _.keys(_.pick($scope.filterButtonsModel.custom, function (value, key) {
return value
}));
if (requiresAnyOf.length === 0) {
return true;
}
var containsAtLeastOne = _.any(requiresAnyOf, function (required) {
if (item.title.toLowerCase().indexOf(required.toLowerCase()) > -1) {
return true;
var quickFilterWords = [];
_.each($scope.filterButtonsModel.custom, function (value, key) { //key is something like 'camts', value is true or false
if (value) {

_.each($scope.filterButtonsModelMap[key], function (string) {
Array.prototype.push.apply(quickFilterWords, string.split(" "));

});
}
});
if (quickFilterWords.length !== 0) {
var allMatch = _.all(quickFilterWords, function (word) {
if (word.startsWith("!")) {
if (word.length === 1) {
return true;
}
return item.title.toLowerCase().indexOf(word.substring(1)) === -1;
}
return item.title.toLowerCase().indexOf(word) > -1;
})

if (!allMatch) {
console.debug(item.title + " does not match all the terms of " + JSON.stringify(quickFilterWords));
filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
return false;
}
})
if (!containsAtLeastOne) {
console.debug(item.title + " does not contain any of the custom values' " + JSON.stringify(requiresAnyOf));
filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
return false;
}


// var requiresAnyOf = _.keys(_.pick($scope.filterButtonsModel.custom, function (value, key) {
// return value
// }));
// if (requiresAnyOf.length === 0) {
// return true;
// }
// var containsAtLeastOne = _.any(requiresAnyOf, function (required) {
// if (item.title.toLowerCase().indexOf(required.toLowerCase()) > -1) {
// return true;
// }
// })
// if (!containsAtLeastOne) {
// console.debug(item.title + " does not contain any of the custom values' " + JSON.stringify(requiresAnyOf));
// filterReasons["quickFilter"] = filterReasons["quickFilter"] + 1;
// return false;
// }
}

if ($scope.foo.hideAlreadyDownloadedResults && item.downloadedAt !== null) {
Expand Down

0 comments on commit 16748ee

Please sign in to comment.