From 4f16b59458ed9e5d68b6a02fbb8e0eab8f0595ad Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 9 Mar 2012 23:37:54 +0100 Subject: [PATCH] find matches accros newlines --- pandora/annotation/models.py | 8 ++++++-- pandora/annotation/tasks.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 45e91dfd8..c49bf9d10 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -44,8 +44,10 @@ def get_matches(obj, model, layer_type): has_type = 'has%ss' % layer_type.capitalize() contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])] if contains: - q = Q(value__icontains=" " + obj.name)|Q(value__istartswith=obj.name) + name = ox.decodeHtml(obj.name) + q = Q(findvalue__icontains=" " + name)|Q(findvalue__istartswith=name) for name in obj.alternativeNames: + name = ox.decodeHtml(name) q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name) contains_matches = q&Q(layer__in=contains) if f: @@ -55,11 +57,13 @@ def get_matches(obj, model, layer_type): matches = [] for a in Annotation.objects.filter(f): - value = a.value.lower() + value = a.findvalue.lower() for name in super_matches: + name = ox.decodeHtml(name) value = value.replace(name.lower(), '') for name in [obj.name] + list(obj.alternativeNames): name = name.lower() + name = ox.decodeHtml(name) if name in value and (exact or re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name).findall(value)): matches.append(a.id) break diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index a15909e33..bd8e6c702 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 import json +import ox from django.conf import settings from celery.task import task @@ -24,8 +25,9 @@ def update_matching_events(id): names = {} for n in Event.objects.all().values('id', 'name', 'alternativeNames'): - names[n['id']] = [n['name']] + json.loads(n['alternativeNames']) - value = a.value.lower() + names[n['id']] = [ox.decodeHtml(n) for n in [n['name']] + json.loads(n['alternativeNames'])] + + value = a.findvalue.lower() update = [] for i in names: for name in names[i]: