Added a watch/unwatch button to user pages.
[zzz-floof.git] / floof / lib / search.py
1 from floof.model.art import Art, Tag, TagText
2
3 def do_search(query):
4 tags = query.split()
5
6 tagtexts = TagText.query.filter(TagText.text.in_(tags))
7 tagtext_ids = [_.id for _ in tagtexts]
8
9 # Fetch art that has all the tags
10 artwork = Art.query.join(Tag) \
11 .filter(Tag.tagtext_id.in_(tagtext_ids)) \
12 .all()
13 return artwork
14
15
16
17
18
19
20 # unfinished stuff
21 def parse(query):
22 words = query.split()
23
24 tags = []
25 for word in words:
26 components = word.split(':')
27 if len(components) == 1:
28 # tags are plain.
29 tags.append(word)
30 elif components[0] == "rating":
31 if components[1].isnumeric():
32 score = int(components[1])
33 else:
34 score = Rating.reverse_options.get(components[1])
35
36 if -1 <= score <= 3:
37 pass
38 # TODO: Find stuff that has this rating
39 # Rating.query.filter(Rating.s)
40
41 tagtexts = TagText.query.filter(TagText.text.in_(tags))
42 tagtext_ids = map(lambda x:x.id, tagtexts)
43