only find places/events where words match fixes: #58
This commit is contained in:
parent
d4e1bc7e56
commit
e71421f597
3 changed files with 31 additions and 12 deletions
|
@ -2,10 +2,13 @@
|
|||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
|
||||
from django.conf import settings
|
||||
from ox.utils import json
|
||||
from ox.django.shortcuts import render_to_json_response, json_response
|
||||
|
||||
from api.actions import actions
|
||||
|
||||
from annotation.models import Annotation
|
||||
from item.models import Item
|
||||
from item import utils
|
||||
|
||||
|
@ -81,15 +84,13 @@ def findClips(request):
|
|||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
qs = qs.select_related('item__sort')
|
||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||
from django.conf import settings
|
||||
from annotation.models import Annotation
|
||||
|
||||
keys = data['keys']
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
|
||||
def merge_annotations(layer, qs):
|
||||
def add_annotations(layer, qs):
|
||||
for a in qs.values('public_id', 'value', 'clip__public_id'):
|
||||
for i in response['data']['items']:
|
||||
if i['id'] == a['clip__public_id']:
|
||||
|
@ -99,12 +100,12 @@ def findClips(request):
|
|||
'id': a['public_id'],
|
||||
'value': a['value'],
|
||||
})
|
||||
|
||||
if response['data']['items']:
|
||||
if 'annotations' in keys:
|
||||
merge_annotations('annotations',
|
||||
add_annotations('annotations',
|
||||
Annotation.objects.filter(layer__name__in=public_layers, clip__in=qs))
|
||||
for layer in filter(lambda l: l in keys, public_layers):
|
||||
merge_annotations(layer,
|
||||
add_annotations(layer,
|
||||
Annotation.objects.filter(layer__name=layer, clip__in=qs))
|
||||
elif 'position' in query:
|
||||
qs = order_query(qs, query['sort'])
|
||||
|
|
|
@ -70,7 +70,16 @@ class Event(models.Model):
|
|||
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)
|
||||
return Annotation.objects.filter(q)
|
||||
matches = []
|
||||
for a in Annotation.objects.filter(q):
|
||||
words = ox.words(a.value)
|
||||
for name in [self.name] + list(self.alternativeNames):
|
||||
if name in words:
|
||||
matches.append(a.id)
|
||||
break
|
||||
if not matches:
|
||||
matches = [-1]
|
||||
return Annotation.objects.filter(id__in=matches)
|
||||
|
||||
def update_matches(self):
|
||||
matches = self.get_matches()
|
||||
|
|
|
@ -79,7 +79,16 @@ class Place(models.Model):
|
|||
q = Q(value__contains=" " + self.name)|Q(value__startswith=self.name)
|
||||
for name in self.alternativeNames:
|
||||
q = q|Q(value__contains=" " + name)|Q(value__startswith=name)
|
||||
return Annotation.objects.filter(q)
|
||||
matches = []
|
||||
for a in Annotation.objects.filter(q):
|
||||
words = ox.words(a.value)
|
||||
for name in [self.name] + list(self.alternativeNames):
|
||||
if name in words:
|
||||
matches.append(a.id)
|
||||
break
|
||||
if not matches:
|
||||
matches = [-1]
|
||||
return Annotation.objects.filter(id__in=matches)
|
||||
|
||||
def update_matches(self):
|
||||
matches = self.get_matches()
|
||||
|
|
Loading…
Reference in a new issue