dont match if there is another place/event with a name containing this place/event that is in the string, example York should not match New York

This commit is contained in:
j 2011-10-30 23:31:26 +01:00
parent eee76a5b5d
commit eaab56dcc7
2 changed files with 22 additions and 0 deletions

View file

@ -68,12 +68,23 @@ class Event(models.Model):
return False
def get_matches(self):
super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames:
q = q|Q(name_find__contains=" " + name)|Q(name_find__contains="|%s"%name)
for p in Event.objects.filter(q).exclude(id=self.id):
for othername in [p.name] + list(p.alternativeNames):
for name in [self.name] + list(self.alternativeNames):
if name in othername:
super_matches.append(othername)
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
matches = []
for a in Annotation.objects.filter(q):
value = a.value.lower()
for name in super_matches:
value = value.replace(name.lower(), '')
for name in [self.name] + list(self.alternativeNames):
name = name.lower()
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):

View file

@ -78,12 +78,23 @@ class Place(models.Model):
return j
def get_matches(self):
super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames:
q = q|Q(name_find__contains=" " + name)|Q(name_find__contains="|%s"%name)
for p in Place.objects.filter(q).exclude(id=self.id):
for othername in [p.name] + list(p.alternativeNames):
for name in [self.name] + list(self.alternativeNames):
if name in othername:
super_matches.append(othername)
q = Q(value__icontains=" " + self.name)|Q(value__istartswith=self.name)
for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
matches = []
for a in Annotation.objects.filter(q):
value = a.value.lower()
for name in super_matches:
value = value.replace(name.lower(), '')
for name in [self.name] + list(self.alternativeNames):
name = name.lower()
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):