Converting the search query to an AST will increase flexibility. But after giving it some thought, I wonder if it may be over-engineering it.
From what I understand, creating an AST in full generality requires a lexer, a parser, and a grammar for the query. Building these from scratch would be difficult, so I would need to depend on a library for this. And even after creating this tree, mapping it into a single SQL query would be hard.
Having boolean connectives (and/or/not) among all filters, tags, and search terms seems both unnecessary and complicated. Considering that not even StackOverflow’s search does this, I’d say it would be better to go for a limited version for now.
I suggest the following:
Limit boolean search to tags, title, and body. So we can do this -
tag:office and tag:important -tag:spam title:"Week" or body:"boring"
But not this:
is:note or is:todo and created:20200119 or updated:20191103
Instead of boolean connectives between the other filters, let’s instead allow multiple filters of the same type.
in:notebook1 in:notebook2 created:day-10 created:20200512 updated:day-5