Searching for one tag works. Two tags acts like or and returns multiple copies.
[zzz-floof.git] / floof / controllers / search.py
diff --git a/floof/controllers/search.py b/floof/controllers/search.py
new file mode 100644 (file)
index 0000000..75926e7
--- /dev/null
@@ -0,0 +1,35 @@
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from floof.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+from floof.model.art import Art, Tag, TagText
+import elixir
+
+class SearchController(BaseController):
+
+    def index(self):
+        # Return a rendered template
+        #return render('/search.mako')
+        # or, return a response
+        return 'Hello World'
+
+    def results(self):
+        """ Search, implemented the stupid way! """
+        query = request.params.get('query','')
+        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