X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/6fb3ad2a578aa2e0eced735187a02a79a8907668..eba4c9b980b8a0ff0953e56975c263bf361f4684:/floof/lib/search.py diff --git a/floof/lib/search.py b/floof/lib/search.py index 3acb248..f7ce65b 100644 --- a/floof/lib/search.py +++ b/floof/lib/search.py @@ -1,3 +1,23 @@ +from floof.model.art import Art, Tag, TagText + +def do_search(query): + tags = query.split() + + tagtexts = TagText.query.filter(TagText.text.in_(tags)) + tagtext_ids = [_.id for _ in tagtexts] + + # Fetch art that has all the tags + artwork = Art.query.join(Tag) \ + .filter(Tag.tagtext_id.in_(tagtext_ids)) \ + .all() + return artwork + + + + + + +# unfinished stuff def parse(query): words = query.split() @@ -18,16 +38,6 @@ def parse(query): # TODO: Find stuff that has this rating # Rating.query.filter(Rating.s) - - - 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')