diff --git a/src/models.py b/src/models.py index 2dfb838..c870541 100644 --- a/src/models.py +++ b/src/models.py @@ -117,7 +117,7 @@ class ContentFilter(DjangoDataModel): def _match_all(self, matching_against: str): for word in self.cleaned_matching_pattern: - if re.search(rf"\b{word}\b", matching_against, self._regex_flags): + if not re.search(rf"\b{word}\b", matching_against, self._regex_flags): return False return True @@ -170,14 +170,17 @@ class ContentFilter(DjangoDataModel): if not self.matching_pattern.strip(): return False - algorithm_func = self._get_algorithm_func() - if not algorithm_func: - log.error(f"Bad algorithm function: {self.matching_algorithm}") - return False + if self.matching_algorithm == MatchingAlgorithm.ALL: + match_found = self._match_all(content.item_title + " " + content.item_description) + else: + algorithm_func = self._get_algorithm_func() + if not algorithm_func: + log.error(f"Bad algorithm function: {self.matching_algorithm}") + return False + + match_found = algorithm_func(content.item_title) or algorithm_func(content.item_description) - match_found = algorithm_func(content.item_title) or algorithm_func(content.item_description) log.debug(f"filter match found: {match_found}") - return not match_found if self.is_whitelist else match_found @@ -356,6 +359,8 @@ class Content(DjangoDataModel): "subscription": self.subscription_id } + log.debug(f"params: {params}") + try: response = await client.get( url=url,