only find places/events where words match fixes: #58

This commit is contained in:
j 2011-10-30 12:55:46 +01:00
commit e71421f597
3 changed files with 31 additions and 12 deletions

View file

@ -79,7 +79,16 @@ class Place(models.Model):
q = Q(value__contains=" " + self.name)|Q(value__startswith=self.name)
for name in self.alternativeNames:
q = q|Q(value__contains=" " + name)|Q(value__startswith=name)
return Annotation.objects.filter(q)
matches = []
for a in Annotation.objects.filter(q):
words = ox.words(a.value)
for name in [self.name] + list(self.alternativeNames):
if name in words:
matches.append(a.id)
break
if not matches:
matches = [-1]
return Annotation.objects.filter(id__in=matches)
def update_matches(self):
matches = self.get_matches()