From 93c24419f18ab4cb984727142f86de18a707ff5f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 30 Oct 2011 14:46:36 +0100 Subject: [PATCH] also match multiword names --- pandora/event/models.py | 10 +++++++--- pandora/place/models.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index e5a3a1bb..4c4a2375 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -2,10 +2,11 @@ # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division, with_statement +import re + from django.db import models from django.contrib.auth.models import User from django.db.models import Q - import ox from ox.django import fields @@ -72,9 +73,12 @@ class Event(models.Model): q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) matches = [] for a in Annotation.objects.filter(q): - words = ox.words(a.value.lower()) + value = a.value.lower() for name in [self.name] + list(self.alternativeNames): - if name.lower() in words: + name = name.lower() + if name in value and (value.startswith(name) or \ + value.endswith(name) or \ + re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: diff --git a/pandora/place/models.py b/pandora/place/models.py index 738bb72e..52ecd680 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division, with_statement -from django.db import models -import ox -from ox.django import fields +import re + +from django.db import models from django.contrib.auth.models import User, Group from django.db.models import Q +import ox +from ox.django import fields import managers from annotation.models import Annotation @@ -81,9 +83,11 @@ class Place(models.Model): q = q|Q(value__contains=" " + name)|Q(value__startswith=name) matches = [] for a in Annotation.objects.filter(q): - words = ox.words(a.value) + value = a.value for name in [self.name] + list(self.alternativeNames): - if name in words: + if name in value and (value.startswith(name) or \ + value.endswith(name) or \ + re.compile('\s%s[\.!?:\-\s]'%name).findall(value)): matches.append(a.id) break if not matches: