from whoosh.index import create_in from whoosh.fields import Schema, TEXT, ID # Define schema with ID and text fields schema = Schema(id=ID(stored=True), text=TEXT(stored=True)) # Create a new index index_dir = "index_dir" ix = create_in(index_dir, schema) # Define some example documents docs = [ {"id": "doc1", "text": "This is the first document"}, {"id": "doc2", "text": "This is the second document"}, {"id": "doc3", "text": "This is the third document"} ] # Add the documents to the index writer = ix.writer() for doc in docs: writer.add_document(id=doc["id"], text=doc["text"]) writer.commit() # Retrieve a specific document by ID with ix.searcher() as searcher: query = ix.schema["id"].contains("doc2") results = searcher.search(query) for result in results: print(result["text"])In this example, the ID field is used to store a unique identifier for each of the documents. The stored=True parameter is used to specify that the field value should be stored in the index and can be retrieved later. A set of example documents is defined and added to the index using the ID and text fields. Finally, the ID field is used to retrieve the second document using a search query, and the text field value is printed. The package library is Whoosh.