8874824f022550b95b1acf475b9ad70473c7c979
1 from floof
.model
import Art
, ArtUser
, ArtUserType
, Tag
, TagText
, User
3 def parse(search_string
):
4 """Parses a search query, and returns a query object on Art.
8 - User relations: by:kalu, of:eevee, for:ootachi
11 - Negative versions of anything above: -by:eevee, -dongs
14 # XXX doesn't do negative querying yet.
15 # XXX could use some sane limits.
17 # We'll be building this as we go.
20 terms
= search_string
.split()
23 # This is a special tag; at the moment, by/for/of to indicate
25 prefix
, tag
= tag
.split(':', 1)
27 # XXX what to do if this fails? abort? return empty query?
28 target_user
= User
.get_by(name
=tag
)
37 # Bogus tag. Not sure what to do here, so for the moment,
41 # Inner join to the ArtUser table
42 q
= q
.join(ArtUser
, aliased
=True) \
43 .filter(ArtUser
.user
== target_user
) \
44 .filter(ArtUser
.type == rel
)
48 q
= q
.join(Tag
, TagText
, aliased
=True) \
49 .filter(TagText
.text
== tag
)