summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-11-21 13:54:29 +0100
committerYorhel <git@yorhel.nl>2020-11-21 13:54:31 +0100
commit7761b70d7c387a7903d8bda12260bd07643d2ca3 (patch)
tree3dae33b18d6853ef23a7eb1227d2523863d63371 /elm
parentfeb5d9e07c423b89d6b137b13ea79709d6619745 (diff)
AdvSearch: Add more tag weights + formalize query formats a bit more
Tag weights are in 0.2 increments, to keep the selection list short enough. https://vndb.org/t14995.5 This (again) breaks the query encoding format, but provides a means for filters to define their own compact query encoding instead of having to force their fully normalized value in some way that it also somehow fits the compact form. This allowed me to save one character on the tag filter encoding by using a Tuple value rather than Triple. I don't foresee any other uses for Triples, so removed that as value type.
Diffstat (limited to 'elm')
-rw-r--r--elm/AdvSearch/Query.elm8
-rw-r--r--elm/AdvSearch/Tags.elm13
2 files changed, 8 insertions, 13 deletions
diff --git a/elm/AdvSearch/Query.elm b/elm/AdvSearch/Query.elm
index f1602c68..6b8f30ba 100644
--- a/elm/AdvSearch/Query.elm
+++ b/elm/AdvSearch/Query.elm
@@ -7,7 +7,7 @@ import Gen.Api as GApi
-- Generic dynamically typed representation of a query.
-- Used only as an intermediate format to help with encoding/decoding.
--- Corresponds to the compact JSON encoding, i.e. with field names and VNDBIDs encoded and integers.
+-- Corresponds to the compact JSON form.
type QType = V | R
type Op = Eq | Ne | Ge | Gt | Le | Lt
type Query
@@ -17,7 +17,6 @@ type Query
| QStr Int Op String
| QQuery Int Op Query
| QTuple Int Op Int Int
- | QTriple Int Op Int Int Int
encodeOp : Op -> JE.Value
@@ -39,7 +38,6 @@ encodeQuery q =
QStr s o a -> JE.list identity [JE.int s, encodeOp o, JE.string a]
QQuery s o a -> JE.list identity [JE.int s, encodeOp o, encodeQuery a]
QTuple s o a b -> JE.list identity [JE.int s, encodeOp o, JE.int a, JE.int b]
- QTriple s o a b c -> JE.list identity [JE.int s, encodeOp o, JE.int a, JE.int b, JE.int c]
@@ -73,8 +71,7 @@ decodeQuery = JD.index 0 JD.int |> JD.andThen (\s ->
[ JD.map2 (QInt s ) (JD.index 1 decodeOp) (JD.index 2 JD.int)
, JD.map2 (QStr s ) (JD.index 1 decodeOp) (JD.index 2 JD.string)
, JD.map2 (QQuery s) (JD.index 1 decodeOp) (JD.index 2 decodeQuery)
- , JD.map2 (\o (a,b,c) -> QTriple s o a b c) (JD.index 1 decodeOp) <| JD.index 2 <| JD.map3 (\a b c -> (a,b,c)) (JD.index 0 JD.int) (JD.index 1 JD.int) (JD.index 2 JD.int)
- , JD.map2 (\o (a,b ) -> QTuple s o a b ) (JD.index 1 decodeOp) <| JD.index 2 <| JD.map2 (\a b -> (a,b )) (JD.index 0 JD.int) (JD.index 1 JD.int)
+ , JD.map2 (\o (a,b) -> QTuple s o a b) (JD.index 1 decodeOp) <| JD.index 2 <| JD.map2 (\a b -> (a,b)) (JD.index 0 JD.int) (JD.index 1 JD.int)
]
)
@@ -138,7 +135,6 @@ encQuery query =
QStr n o v -> encStrField n o v
QQuery n o q -> fint n ++ encTypeOp o 1 ++ encQuery q
QTuple n o a b -> fint n ++ encTypeOp o 5 ++ fint a ++ fint b
- QTriple n o a b c -> fint n ++ encTypeOp o 6 ++ fint a ++ fint b ++ fint c
showOp : Op -> String
diff --git a/elm/AdvSearch/Tags.elm b/elm/AdvSearch/Tags.elm
index bdddb6a1..dee6621a 100644
--- a/elm/AdvSearch/Tags.elm
+++ b/elm/AdvSearch/Tags.elm
@@ -55,12 +55,12 @@ update dat msg model =
, c )
-toQuery m = S.toQuery (\o (t,l) -> if m.spoiler == 0 && l == 0 then QInt 8 o t else QTriple 8 o t m.spoiler l) m.sel
+toQuery m = S.toQuery (\o (t,l) -> if m.spoiler == 0 && l == 0 then QInt 8 o t else QTuple 8 o t (l*3+m.spoiler)) m.sel
fromQuery spoil dat q =
let f qr = case qr of
QInt 8 op t -> if spoil == 0 then Just (op, (t,0)) else Nothing
- QTriple 8 op t s l -> if s == spoil then Just (op, (t,l)) else Nothing
+ QTuple 8 op t v -> if modBy 3 v == spoil then Just (op, (t,v//3)) else Nothing
_ -> Nothing
in
S.fromQuery f dat q |> Maybe.map (\(ndat,sel) ->
@@ -96,11 +96,10 @@ view dat model =
, ul [] <| List.map (\(t,l) ->
li []
[ inputButton "X" (Sel (S.Sel (t,l) False)) []
- , inputSelect "" l (Level (t,l)) [style "width" "60px"]
- [ (0, "any")
- , (1, "*")
- , (2, "**")
- , (3, "***") ]
+ , inputSelect "" l (Level (t,l)) [style "width" "60px"] <|
+ (0, "any")
+ :: List.map (\i -> (i, String.fromInt (i//5) ++ "." ++ String.fromInt (2*(modBy 5 i)) ++ "+")) (List.range 1 14)
+ ++ [(15, "3.0")]
, b [ class "grayedout" ] [ text <| " g" ++ String.fromInt t ++ ": " ]
, Dict.get t dat.tags |> Maybe.map (\e -> e.name) |> Maybe.withDefault "" |> text
]