A Boolean full-text parser
We know the Boolean syntax of the MySQL built-in full-text parser. MySQL already supports it; there is no fun in reimplementing the same thing. To do something new we could make a parser that supports AND, OR
, and NOT
keywords, which is supposedly a more user-friendly syntax and our users may like it more than MySQL plus and minus prefixes.
How could our parser support such a syntax? It could, for example, by doing look-ahead, reading the next word before sending the current one to MySQL. If the next word is AND
, the current one must have yesno=1
. The idea is simple, but the devil, as always, is in the detail:
Both words before and after
AND
must haveyesno=1
.To support
foo AND NOT bar
we may need to look two words ahead.Typically, both words around
OR
must haveyesno=0
. But not if anAND
is involved. Infoo OR bar AND bla
the second word must haveyesno=1
.In a query string such as
foo AND bar OR some AND thing
we cannot simply haveyesno=1
in all four words....