Formal syntax of query expressions
QueryExpression := SearchExpression ActionExpression?
SearchExpression := SearchTerm (SPACE+ SearchTerm)*.
SearchTerm := SearchOperator? SearchValue
| SearchKey SearchOperator SearchValue?
| SearchKey ExistOperator
| "OR"
| "RANDOM"
| "PICK" SPACE+ PosInt
| "ORDER" SPACE+ ("REVERSE" SPACE+)? SearchKey
| "OFFSET" SPACE+ PosInt
| "LIMIT" SPACE+ PosInt.
SearchValue := Word.
SearchKey := MetadataKey.
SearchOperator := '!'
| ('!')? ('~' | ':' | '<' | '>').
ExistOperator := '?'
| '!' '?'.
PosInt := '0'
| ('1' .. '9') DIGIT*.
ActionExpression := '|' (Word (SPACE+ Word)*)?
Word := NO-SPACE NO-SPACE*