place/event matches

This commit is contained in:
j 2012-01-02 20:59:43 +05:30
parent f23340ddbb
commit 4c25291c88
3 changed files with 16 additions and 6 deletions

View file

@ -7,6 +7,7 @@ import re
from django.db import models, transaction
from django.contrib.auth.models import User
from django.db.models import Q
from django.conf import settings
import ox
from ox.django import fields
@ -68,6 +69,8 @@ class Event(models.Model):
return False
def get_matches(self):
layers = filter(lambda l: l['type'] == 'event' or l.get('hasEvents'),
settings.CONFIG['layers'])
super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames:
@ -81,7 +84,7 @@ class Event(models.Model):
for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
matches = []
for a in Annotation.objects.filter(q):
for a in Annotation.objects.filter(layer__in=layers).filter(q):
value = a.value.lower()
for name in super_matches:
value = value.replace(name.lower(), '')

View file

@ -7,6 +7,7 @@ import re
from django.db import models, transaction
from django.contrib.auth.models import User, Group
from django.db.models import Q
from django.conf import settings
import ox
from ox.django import fields
@ -82,6 +83,8 @@ class Place(models.Model):
return j
def get_matches(self):
layers = filter(lambda l: l['type'] == 'place' or l.get('hasPlaces'),
settings.CONFIG['layers'])
super_matches = []
q = Q(name_find__contains=" " + self.name)|Q(name_find__contains="|%s"%self.name)
for name in self.alternativeNames:
@ -95,7 +98,7 @@ class Place(models.Model):
for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__istartswith=name)
matches = []
for a in Annotation.objects.filter(q):
for a in Annotation.objects.filter(layer__in=layers).filter(q):
value = a.value.lower()
for name in super_matches:
value = value.replace(name.lower(), '')

View file

@ -27,13 +27,17 @@ pandora.ui.placesDialog = function() {
getMatches: function(names, callback) {
// fixme: the results of this are of course
// not identical to actual place matches
var key = pandora.site.layers.filter(function(layer) {
return layer.type == 'place' || layer.hasPlaces;
}).map(function(layer) {
return layer.id;
})[0],
operator = Ox.getObjectById(pandora.site.layers, key).type == 'place' ?
'==' : '=';
pandora.api.findClips({
query: {
conditions: names.map(function(name) {
//FIXME: this should be more generic
return Ox.getObjectById(pandora.site.layers, 'subtitles')
? {key: 'subtitles', value: name, operator: '='}
: {key: 'places', value: name, operator: '=='};
return {key: key, value: name, operator: operator};
}),
operator: names.length == 1 ? '&' : '|'
}