Bird
Raised Fist0
HLDsystem_design~10 mins

Search and metadata in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main component responsible for storing metadata in a search system.

HLD
class [1]:
    def __init__(self):
        self.metadata_store = {}
Drag options to blanks, or click blank then click option'
AIndexBuilder
BMetadataStore
CQueryProcessor
DSearchEngine
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing SearchEngine instead of MetadataStore
Confusing IndexBuilder with metadata storage
2fill in blank
medium

Complete the code to add a method that indexes a document's metadata.

HLD
def index_metadata(self, document_id, metadata):
    self.metadata_store[[1]] = metadata
Drag options to blanks, or click blank then click option'
Adocument_id
Bmetadata
Cindex
Ddoc
Attempts:
3 left
💡 Hint
Common Mistakes
Using metadata as the key instead of document_id
Using a generic name like index which is undefined
3fill in blank
hard

Fix the error in the method that retrieves metadata for a given document.

HLD
def get_metadata(self, document_id):
    return self.metadata_store.get([1], None)
Drag options to blanks, or click blank then click option'
Ametadata
Bdoc_id
Cdocument_id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using metadata or id which are not keys in the store
Using doc_id which is undefined in this context
4fill in blank
hard

Fill both blanks to create a function that filters documents by a metadata key and value.

HLD
def filter_documents(self, key, value):
    return [doc_id for doc_id, meta in self.metadata_store.items() if meta.get([1]) [2] value]
Drag options to blanks, or click blank then click option'
Akey
B==
C!=
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'key' in the first blank
Using '!=' instead of '==' for filtering matching documents
5fill in blank
hard

Fill all three blanks to build a dictionary comprehension that maps document IDs to metadata values for a specific key if the value exists.

HLD
result = {doc_id: meta.get([1]) for doc_id, meta in self.metadata_store.items() if meta.get([2]) is not [3]
Drag options to blanks, or click blank then click option'
Akey
CNone
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for the two meta.get calls
Checking against 'value' instead of None