Document Store with Predicates
Asked at Snowflake
Reported by the problem's creator, not verified
Documents are identified by a file name and hold text made of whitespace-separated words. Word matching is exact and case-sensitive: a predicate word matches a document only if the document contains that exact word.
A predicate is built from words, &&, || and parentheses. && binds tighter than ||. Predicates are always valid, and operators and parentheses may or may not be surrounded by spaces.
Each test drives one DocStore through a sequence of calls and checks every return value.
Examples
Example 1
Input: init =
[["n1","n2","n3"],4,2], operations =[["insert_doc",["doc1","a b"]],["check_contains",["doc1","a && b || c"]],["check_contains",["doc1","c || a && c"]],["check_contains",["doc1","a || b && c"]],["check_contains",["doc1","(a || c) && (c || b)"]],["check_contains",["doc1","(a && c)||b"]],["check_contains",["nodoc","a || b"]],["check_contains",["doc1","a&&c"]]]Output:
[null,true,false,true,true,true,false,false]Explanation: doc1 holds the words a and b.
a && b || creads as(a && b) || c, which is true.c || a && creads asc || (a && c), which is false.a || b && creads asa || (b && c), which is true. The parenthesized forms and the space-freea&&cparse the same way. The missing filenodochas no words, soa || bis false.