-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.py
31 lines (26 loc) · 1.31 KB
/
document.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Document:
"""
Represents a document to be indexed or searched within the search engine.
Attributes:
id (str): Unique identifier for the document.
content (dict): The content of the document stored in key-value pairs, where keys are field names
and values are the corresponding field values. This structure supports various data types
and is flexible for different document schemas.
"""
def __init__(self, document_id: str, content: dict):
"""
Initializes a new instance of the Document class.
Parameters:
document_id (str): The unique identifier for the document.
content (dict): The content of the document, including all fields and their values.
"""
self.id = document_id
self.content = content
def __repr__(self):
"""
Provides a string representation of the Document object, primarily for debugging purposes.
Returns:
str: A string representation of the Document, typically including the document ID and a summary of the content.
"""
content_summary = {key: value for key, value in self.content.items()[:5]} # Just show a summary if many fields
return f"Document(ID: {self.id}, Content: {content_summary})"