-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_segment.py
49 lines (39 loc) · 1.72 KB
/
index_segment.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import List
from document import Document
class IndexSegment:
"""
Represents a segment of the search index, containing a collection of documents.
Attributes:
segment_id (str): A unique identifier for the index segment.
documents (List[Document]): A list of Document objects contained within the segment.
"""
def __init__(self, segment_id: str, documents: List[Document]):
"""
Initializes a new instance of the IndexSegment class.
Parameters:
segment_id (str): The unique identifier for the index segment.
documents (List[Document]): The list of Document objects to be included in the segment.
"""
self.segment_id = segment_id
self.documents = documents
def __repr__(self):
"""
Provides a string representation of the IndexSegment object, primarily for debugging purposes.
Returns:
str: A string representation of the IndexSegment, typically including the segment ID and the number of documents it contains.
"""
return f"IndexSegment(ID: {self.segment_id}, Documents: {len(self.documents)})"
def add_document(self, document: Document):
"""
Adds a Document to the index segment.
Parameters:
document (Document): The Document object to be added to the segment.
"""
self.documents.append(document)
def remove_document(self, document_id: str):
"""
Removes a Document from the index segment based on its ID.
Parameters:
document_id (str): The unique identifier of the Document to be removed.
"""
self.documents = [doc for doc in self.documents if doc.id != document_id]