Design a simple document service that stores text documents identified by filename.
Implement these APIs:
-
InsertDoc(filename, content)
: store or overwrite a document.
-
CheckContains(filename, predicate) -> bool
: return whether the document satisfies a boolean keyword expression.
Rules for predicate:
-
A term is a word such as
a
,
b
, or
error
.
-
term
is true if that word appears anywhere in the document.
-
Operators supported:
&&
and
||
.
-
&&
has higher precedence than
||
.
-
You may also support parentheses for grouping.
Examples:
-
a || b || c
is true if the document contains at least one of
a
,
b
, or
c
.
-
a && b || c
is true if the document contains both
a
and
b
, or contains
c
.
Follow-up 1:
-
Implement
GetAllFiles(predicate) -> List[filename]
, which returns all documents matching the predicate.
Follow-up 2:
-
Explain how you would scale this service in a distributed system, including a reasonable sharding or partitioning strategy and a replication policy.
Assume you are starting from a blank editor or whiteboard and should define any necessary data structures and test cases.