toodles icon indicating copy to clipboard operation
toodles copied to clipboard

exclude tags

Open JeffreyBenjaminBrown opened this issue 6 years ago • 7 comments

The filter function in toodles blows my mind. I love being able to do that.

But it would be nice to be able specify "show me everything except bla".

More generally, a boolean logic would be awesome -- something like Apache Lucene, which lets you ask for "bob AND NOT (speed OR search)". Or, perhaps more natural, it could read like Haskell: "bob && not (speed || search)".

JeffreyBenjaminBrown avatar Oct 29 '18 22:10 JeffreyBenjaminBrown

For the general query language problem, Text.Megaparsec.Expr is extremely well suited. It lets you define unary and binary operators of various precedence levels. If I can figure out how to contribute I plan to try to write this with it.

JeffreyBenjaminBrown avatar Oct 29 '18 23:10 JeffreyBenjaminBrown

I like it! While I can see the benefit (and fun!) of building this into the backend, I'm thinking it might be a pre-optimization. To me it sounds easier to just add this new logic to the frontend, and avoid the back-and-forth to the server. What do you think?

aviaviavi avatar Oct 30 '18 04:10 aviaviavi

I don't know what you mean. Are you saying just provide two windows, one for include and one for exclude? Or do you mean to parse boolean queries, just not in the backend? I'm not yet close enough to the code to know what to call back end and front end.

JeffreyBenjaminBrown avatar Oct 30 '18 04:10 JeffreyBenjaminBrown

I meant the latter. The javascript that powers the web UI of toodles should be able to handle this, so I was suggesting there might not be any Haskell to write here, at least not at first.

aviaviavi avatar Oct 30 '18 05:10 aviaviavi

It could be done in Javascript, I agree -- but why? It'd be far more code, and less safe, and harder to learn or modify. Megaparsec.Expr lets you write a parser for unary and binary operators of different precedence levels in as little as this much code:

expr = makeExprParser term table <?> "expression"

term = parens expr <|> integer <?> "term"

table = [ [ prefix  "-"  negate
          , prefix  "+"  id ]
        , [ postfix "++" (+1) ]
        , [ binary  "*"  (*)
          , binary  "/"  div  ]
        , [ binary  "+"  (+)
          , binary  "-"  (-)  ] ]

binary  name f = InfixL  (f <$ symbol name)
prefix  name f = Prefix  (f <$ symbol name)
postfix name f = Postfix (f <$ symbol name)

JeffreyBenjaminBrown avatar Nov 05 '18 03:11 JeffreyBenjaminBrown

Apologies for the late response here, must have missed the notification of your reply.

I'm on board with your suggestion.

Just for context on I was coming from: currently the UI does this filtering right now, so the Haskell code is not involved. So I was questioning if the complexity of the parsing you are describing even justifies the complexity of simply going back and forth with the server at all. Sounds like it does though :)

aviaviavi avatar Nov 10 '18 23:11 aviaviavi

@JeffreyBenjaminBrown let me know if you need any help getting this working!

aviaviavi avatar Nov 10 '18 23:11 aviaviavi