#48: make the tag matching smarter

This commit is contained in:
Daniel Quinn
2016-02-19 00:45:02 +00:00
parent 99be40a433
commit ec88ea73f6
2 changed files with 124 additions and 4 deletions

View File

@@ -105,21 +105,21 @@ class Tag(SluggedModel):
if self.matching_algorithm == self.MATCH_ALL:
for word in self.match.split(" "):
if word not in text:
if not re.search(r"\b{}\b".format(word), text):
return False
return True
if self.matching_algorithm == self.MATCH_ANY:
for word in self.match.split(" "):
if word in text:
if re.search(r"\b{}\b".format(word), text):
return True
return False
if self.matching_algorithm == self.MATCH_LITERAL:
return self.match in text
return bool(re.search(r"\b{}\b".format(self.match), text))
if self.matching_algorithm == self.MATCH_REGEX:
return re.search(re.compile(self.match), text)
return bool(re.search(re.compile(self.match), text))
raise NotImplementedError("Unsupported matching algorithm")