shaped up routing: enabled explicit mode, and created some named routes
[zzz-floof.git] / floof / lib / search.py
1 def parse(query):
2 words = query.split()
3
4 tags = []
5 for word in words:
6 components = word.split(':')
7 if len(components) == 1:
8 # tags are plain.
9 tags.append(word)
10 elif components[0] == "rating":
11 if components[1].isnumeric():
12 score = int(components[1])
13 else:
14 score = Rating.reverse_options.get(components[1])
15
16 if -1 <= score <= 3:
17 pass
18 # TODO: Find stuff that has this rating
19 # Rating.query.filter(Rating.s)
20
21
22
23
24 tagtexts = TagText.query.filter(TagText.text.in_(tags))
25 tagtext_ids = map(lambda x:x.id, tagtexts)
26
27 # TODO: this is wrong. Please fix it so it returns art that has all the tags.
28 art_tag_pairs = elixir.session.query(Art,Tag).filter(Art.id == Tag.art_id).\
29 filter(Tag.tagtext_id.in_(tagtext_ids)).all()
30
31 # just the art please.
32 c.artwork = map(lambda x: x[0], art_tag_pairs)
33 return render('/index.mako')