### Navigation

- index
- modules |
- next |
- previous |
- Whoosh 2.5.7 documentation »
- Technical notes »

# How to implement a new backend

## Index

- Subclass `whoosh.index.Index`.
- Indexes must implement the following methods.
  - `whoosh.index.Index.is_empty()`
  - `whoosh.index.Index.doc_count()`
  - `whoosh.index.Index.reader()`
  - `whoosh.index.Index.writer()`
- 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.
  - `whoosh.index.Index.latest_generation()`
  - `whoosh.index.Index.up_to_date()`
  - `whoosh.index.Index.last_modified()`
- Index may implement the following methods (the base class’s versions are no-ops).
  - `whoosh.index.Index.optimize()`
  - `whoosh.index.Index.close()`

## 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.
  - `whoosh.writing.IndexWriter.delete_document()`
- 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.
  - `whoosh.reading.IndexReader.has_deletions()`
  - `whoosh.reading.IndexReader.is_deleted()`
- Backends that support versioning should implement the following methods.
  - `whoosh.reading.IndexReader.generation()`
- If the IndexReader object does not keep the schema in the `self.schema` attribute, 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.
  - `whoosh.matching.Matcher.is_active()`
  - `whoosh.matching.Matcher.copy()`
  - `whoosh.matching.Matcher.id()`
  - `whoosh.matching.Matcher.next()`
  - `whoosh.matching.Matcher.value()`
  - `whoosh.matching.Matcher.value_as()`
  - `whoosh.matching.Matcher.score()`
- Depending on the implementation, you may implement the following methods more efficiently.
  - `whoosh.matching.Matcher.skip_to()`
  - `whoosh.matching.Matcher.weight()`
- 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()`

### Navigation

- index
- modules |
- next |
- previous |
- Whoosh 2.5.7 documentation »
- Technical notes »