From eaab56dcc7d417da83829de8d62935f0407f71cf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 23:31:26 +0100 Subject: [PATCH] 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 --- pandora/event/models.py | 11 +++++++++++ pandora/place/models.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/pandora/event/models.py b/pandora/event/models.py index 1141b96c..e6ae546a 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -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): diff --git a/pandora/place/models.py b/pandora/place/models.py index 59c074f3..b592265c 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -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):