merged with mine
[zzz-floof.git] / floof / controllers / search.py
index 5240a0b..abedd16 100644 (file)
@@ -13,43 +13,16 @@ 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','')
-        words = query.split()
+        """Search, implemented the stupid way!"""
+        query = request.params.get('query', '')
+        tags = query.split()
         
-        tags = []
-        for word in words:
-            components = word.split(':')
-            if len(components) == 1:
-                # tags are plain.
-                tags.append(word)
-            elif components[0] == "rating":
-                if components[1].isnumeric():
-                    score = int(components[1])
-                else:
-                    score = Rating.reverse_options.get(components[1])
-                
-                if -1 <= score <= 3:
-                    pass
-                    # 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)
+        tagtext_ids = [_.id for _ in tagtexts]
+
+        # Fetch art that has all the tags
+        c.artwork = Art.query.join(Tag) \
+                       .filter(Tag.tagtext_id.in_(tagtext_ids)) \
+                       .all()
 
-        # 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