How to implement a new backend¶
Index¶
- Subclass
whoosh.index.Index. - Indexes must implement the following methods.
- Indexes that require/support locking must implement the following methods.
whoosh.index.Index.lock()whoosh.index.Index.unlock()
- Indexes that support deletion must implement the following methods.
whoosh.index.Index.delete_document()whoosh.index.Index.doc_count_all()– if the backend has delayed deletion.
- Indexes that require/support versioning/transactions may implement the following methods.
- Index may implement the following methods (the base class’s versions are no-ops).
IndexWriter¶
- Subclass
whoosh.writing.IndexWriter. - IndexWriters must implement the following methods.
whoosh.writing.IndexWriter.add_document()whoosh.writing.IndexWriter.add_reader()
- Backends that support deletion must implement the following methods.
- IndexWriters that work as transactions must implement the following methods.
whoosh.reading.IndexWriter.commit()– Save the additions/deletions done with this IndexWriter to the main index, and release any resources used by the IndexWriter.whoosh.reading.IndexWriter.cancel()– Throw away any additions/deletions done with this IndexWriter, and release any resources used by the IndexWriter.
IndexReader¶
- Subclass
whoosh.reading.IndexReader. - IndexReaders must implement the following methods.
whoosh.reading.IndexReader.__contains__()whoosh.reading.IndexReader.__iter__()whoosh.reading.IndexReader.iter_from()whoosh.reading.IndexReader.stored_fields()whoosh.reading.IndexReader.doc_count_all()whoosh.reading.IndexReader.doc_count()whoosh.reading.IndexReader.doc_field_length()whoosh.reading.IndexReader.field_length()whoosh.reading.IndexReader.max_field_length()whoosh.reading.IndexReader.postings()whoosh.reading.IndexReader.has_vector()whoosh.reading.IndexReader.vector()whoosh.reading.IndexReader.doc_frequency()whoosh.reading.IndexReader.frequency()
- Backends that support deleting documents should implement the following methods.
- Backends that support versioning should implement the following methods.
- If the IndexReader object does not keep the schema in the
self.schemaattribute, it needs to override the following methods.whoosh.reading.IndexReader.field()whoosh.reading.IndexReader.field_names()whoosh.reading.IndexReader.scorable_names()whoosh.reading.IndexReader.vector_names()
- IndexReaders may implement the following methods.
whoosh.reading.DocReader.close()– closes any open resources associated with the reader.
Matcher¶
The whoosh.reading.IndexReader.postings() method returns a
whoosh.matching.Matcher object. You will probably need to implement
a custom Matcher class for reading from your posting lists.
- Subclass
whoosh.matching.Matcher. - Implement the following methods at minimum.
- Depending on the implementation, you may implement the following methods more efficiently.
- If the implementation supports quality, you should implement the following
methods.
whoosh.matching.Matcher.supports_quality()whoosh.matching.Matcher.quality()whoosh.matching.Matcher.block_quality()whoosh.matching.Matcher.skip_to_quality()