summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-08-23 23:24:16 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-08-23 23:24:16 +0200
commitf48773661a235864a8460e1ca0810f0593ac93be (patch)
tree78f2474f06f923a381b610fc4ecc78a3c8cc7e54
parent8f1b87a29af1526c6adbb16694dbb52aa8cce26e (diff)
Fixed search.
-rw-r--r--db.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/db.py b/db.py
index ac73a47..d71a717 100644
--- a/db.py
+++ b/db.py
@@ -8,7 +8,7 @@ Base = declarative_base()
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship, backref
-from sqlalchemy import and_
+from sqlalchemy import and_, or_
from sqlalchemy.orm.exc import NoResultFound
@@ -132,11 +132,16 @@ class Track(Base):
@staticmethod
def search(session, *args, **kwargs):
r = session.query(Track)
+ s_or = []
for f, n in ((Artist, 'artist'), (Track, 'title'), (Album, 'album')):
+ if f != Track:
+ r = r.join(f)
if n in kwargs:
- if f != Track:
- r = r.join(f)
r = r.filter(f.name.ilike('%{0}%'.format(kwargs[n])))
+ for i in args:
+ s_or.append(f.name.ilike('%{0}%'.format(i)))
+ if len(s_or):
+ r = r.filter(or_(*s_or))
return r.all()
def get_path(self):