Boolean search [feature request]
RobertTalbert opened this issue · comments
It would be nice to have basic AND and OR functionality built into the search bar. For example if I want to look for all tasks that have both @computer
and !important
I might enter @computer AND !important
into the search bar. Or, if I wanted tasks with one or the other (or both), I might enter @computer OR !important
. Currently it looks like the search bar only searches for the literal text that's entered into the search query -- if there's a way to do what I'm describing, it's not obvious.
Beautiful app by the way, kudos.
I like the idea. The app already allows searching for multiple words, so we just need to support OR and maybe we can simply ignore AND if we find it.
Should we simply evaluate left to right?
For example, @work
would be mandatory in @computer OR !important AND @work
.
It would be more consistent with order of operations in programming languages (I'm thinking Python mostly) to have AND take precedence over OR. So @computer OR !important AND @work
would be evaluated like @computer OR (!important AND @work)
. I'd need to whip up a truth table to see if those two expressions are equivalent but I think they aren't always going to be.
If I wanted tasks that had either @computer
or !important
but they all must have @work
, I'd enter (@computer OR !important) AND @work
(or write it out without parentheses using DeMorgan's Laws). I'm not saying that would be the easiest approach! But that would make the most sense from a user perspective.
Oh, I forgot NOT -- a search for NOT @work
would give me all tasks that don't have @work
attached. NOT would take precedence over both AND and OR.
What would be the best way to write a parser that is simple and forgiving for bad inputs, e.g. unmatched brackets?
Update: Now that I've had my coffee -- If you evaluate left to right, then x or y and z
would be interpreted (x or y) and z
which is definitely not equivalent to x or (y and z)
. The latter is what would be evaluated if x or y and z
were done using regular order of operations.
What would be the best way to write a parser that is simple and forgiving for bad inputs, e.g. unmatched brackets?
I am not actually a programmer, but IIRC these parsers are often done by representing the input as a tree structure and then doing a traversal (the exact type of traversal being dependent on whether you want to use a queue or a stack). Example: x or (y and z)
would be the tree
(Sorry for the huge size) Then the parser traverses the tree -- a postorder traversal would give x y z AND OR
which could then be evaluated with a stack (I think).
Actually getting the input expression from a parenthesized form into a tree is just a matter of parsing out the parentheses as tokens, but again IANA programmer.
I hacked something. Since this is JavaScript we can use builtin functionality to do the parsing. Please report any issues you find. &&
and ||
also work.
Nice! That seems to work well. Thanks a lot.