fix 'all' filter failing

This commit is contained in:
Corban-Lee Jones 2024-11-15 23:46:49 +00:00
parent a9c08dea4d
commit ca2037528d

View File

@ -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,