forked from 0x2620/pandora
find matches accros newlines
This commit is contained in:
parent
be41feadbd
commit
4f16b59458
2 changed files with 10 additions and 4 deletions
|
@ -44,8 +44,10 @@ def get_matches(obj, model, layer_type):
|
||||||
has_type = 'has%ss' % layer_type.capitalize()
|
has_type = 'has%ss' % layer_type.capitalize()
|
||||||
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])]
|
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])]
|
||||||
if contains:
|
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:
|
for name in obj.alternativeNames:
|
||||||
|
name = ox.decodeHtml(name)
|
||||||
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
|
||||||
contains_matches = q&Q(layer__in=contains)
|
contains_matches = q&Q(layer__in=contains)
|
||||||
if f:
|
if f:
|
||||||
|
@ -55,11 +57,13 @@ def get_matches(obj, model, layer_type):
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
for a in Annotation.objects.filter(f):
|
for a in Annotation.objects.filter(f):
|
||||||
value = a.value.lower()
|
value = a.findvalue.lower()
|
||||||
for name in super_matches:
|
for name in super_matches:
|
||||||
|
name = ox.decodeHtml(name)
|
||||||
value = value.replace(name.lower(), '')
|
value = value.replace(name.lower(), '')
|
||||||
for name in [obj.name] + list(obj.alternativeNames):
|
for name in [obj.name] + list(obj.alternativeNames):
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
|
name = ox.decodeHtml(name)
|
||||||
if name in value and (exact or re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name).findall(value)):
|
if name in value and (exact or re.compile('((^|\s)%s([\.,;:!?\-\/\s]|$))'%name).findall(value)):
|
||||||
matches.append(a.id)
|
matches.append(a.id)
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
import json
|
import json
|
||||||
|
import ox
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from celery.task import task
|
from celery.task import task
|
||||||
|
@ -24,8 +25,9 @@ def update_matching_events(id):
|
||||||
|
|
||||||
names = {}
|
names = {}
|
||||||
for n in Event.objects.all().values('id', 'name', 'alternativeNames'):
|
for n in Event.objects.all().values('id', 'name', 'alternativeNames'):
|
||||||
names[n['id']] = [n['name']] + json.loads(n['alternativeNames'])
|
names[n['id']] = [ox.decodeHtml(n) for n in [n['name']] + json.loads(n['alternativeNames'])]
|
||||||
value = a.value.lower()
|
|
||||||
|
value = a.findvalue.lower()
|
||||||
update = []
|
update = []
|
||||||
for i in names:
|
for i in names:
|
||||||
for name in names[i]:
|
for name in names[i]:
|
||||||
|
|
Loading…
Reference in a new issue