From 7222589e3a941faf670445af1f93a930f5a6fde0 Mon Sep 17 00:00:00 2001 From: Eevee Date: Sun, 4 Oct 2009 19:17:34 -0700 Subject: [PATCH 1/1] Fix search to do an AND of tags, not OR. --- floof/controllers/search.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/floof/controllers/search.py b/floof/controllers/search.py index 75926e7..75bbba8 100644 --- a/floof/controllers/search.py +++ b/floof/controllers/search.py @@ -24,12 +24,11 @@ class SearchController(BaseController): tags = query.split() tagtexts = TagText.query.filter(TagText.text.in_(tags)) - tagtext_ids = map(lambda x:x.id, tagtexts) - - # TODO: this is wrong. Please fix it so it returns art that has all the tags. - art_tag_pairs = elixir.session.query(Art,Tag).filter(Art.id == Tag.art_id).\ - filter(Tag.tagtext_id.in_(tagtext_ids)).all() - - # just the art please. - c.artwork = map(lambda x: x[0], art_tag_pairs) - return render('/index.mako') \ No newline at end of file + tagtext_ids = [_.id for _ in tagtexts] + + # Fetch art that has all the tags + c.artwork = Art.query.join(Tag) \ + .filter(Tag.id.in_(tagtext_ids)) \ + .all() + + return render('/index.mako') -- 2.7.4