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:
parent
eee76a5b5d
commit
eaab56dcc7
2 changed files with 22 additions and 0 deletions
|
@ -68,12 +68,23 @@ class Event(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_matches(self):
|
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)
|
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
|
||||||
for name in self.alternativeNames:
|
for name in self.alternativeNames:
|
||||||
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
|
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
|
||||||
matches = []
|
matches = []
|
||||||
for a in Annotation.objects.filter(q):
|
for a in Annotation.objects.filter(q):
|
||||||
value = a.value.lower()
|
value = a.value.lower()
|
||||||
|
for name in super_matches:
|
||||||
|
value = value.replace(name.lower(), '')
|
||||||
for name in [self.name] + list(self.alternativeNames):
|
for name in [self.name] + list(self.alternativeNames):
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):
|
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):
|
||||||
|
|
|
@ -78,12 +78,23 @@ class Place(models.Model):
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def get_matches(self):
|
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)
|
q = Q(value__icontains=" " + self.name)|Q(value__istartswith=self.name)
|
||||||
for name in self.alternativeNames:
|
for name in self.alternativeNames:
|
||||||
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
||||||
matches = []
|
matches = []
|
||||||
for a in Annotation.objects.filter(q):
|
for a in Annotation.objects.filter(q):
|
||||||
value = a.value.lower()
|
value = a.value.lower()
|
||||||
|
for name in super_matches:
|
||||||
|
value = value.replace(name.lower(), '')
|
||||||
for name in [self.name] + list(self.alternativeNames):
|
for name in [self.name] + list(self.alternativeNames):
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):
|
if name in value and re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name):
|
||||||
|
|
Loading…
Reference in a new issue