Today you create the core object of the whole project - a search index you can add documents to and read them back. Everything else you build hangs off this one type.
Build a SearchIndex that stores documents by id and reports how many it holds.
Every search engine begins with the same humble object: a place to put documents. Before you can tokenize, index, or rank anything, you need a document store - a mapping from a document id to its original text. Keeping the raw text around matters: later you will show snippets of it in results, so the store is not just a stepping stone.
Keep it tiny. A dictionary from id to text, an add method, a size, and a
document(id) lookup. This is the spine the rest of the project attaches to -
every later lesson adds a method to this same class.
class SearchIndex:def __init__(self):self._docs = {} # id -> original textdef add(self, doc_id, text):... # store it# size, document(id) read it back
Manning, Introduction to Information Retrieval - ch. 1.