From f48773661a235864a8460e1ca0810f0593ac93be Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 23 Aug 2011 23:24:16 +0200 Subject: Fixed search. --- db.py | 11 ++++++++--- 1 file 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): -- cgit v1.2.3