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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
==============================
How to implement a new backend
==============================
Index
=====
* Subclass :class:`whoosh.index.Index`.
* Indexes must implement the following methods.
* :meth:`whoosh.index.Index.is_empty`
* :meth:`whoosh.index.Index.doc_count`
* :meth:`whoosh.index.Index.reader`
* :meth:`whoosh.index.Index.writer`
* Indexes that require/support locking must implement the following methods.
* :meth:`whoosh.index.Index.lock`
* :meth:`whoosh.index.Index.unlock`
* Indexes that support deletion must implement the following methods.
* :meth:`whoosh.index.Index.delete_document`
* :meth:`whoosh.index.Index.doc_count_all` -- if the backend has delayed
deletion.
* Indexes that require/support versioning/transactions *may* implement the following methods.
* :meth:`whoosh.index.Index.latest_generation`
* :meth:`whoosh.index.Index.up_to_date`
* :meth:`whoosh.index.Index.last_modified`
* Index *may* implement the following methods (the base class's versions are no-ops).
* :meth:`whoosh.index.Index.optimize`
* :meth:`whoosh.index.Index.close`
IndexWriter
===========
* Subclass :class:`whoosh.writing.IndexWriter`.
* IndexWriters must implement the following methods.
* :meth:`whoosh.writing.IndexWriter.add_document`
* :meth:`whoosh.writing.IndexWriter.add_reader`
* Backends that support deletion must implement the following methods.
* :meth:`whoosh.writing.IndexWriter.delete_document`
* IndexWriters that work as transactions must implement the following methods.
* :meth:`whoosh.reading.IndexWriter.commit` -- Save the additions/deletions done with
this IndexWriter to the main index, and release any resources used by the IndexWriter.
* :meth:`whoosh.reading.IndexWriter.cancel` -- Throw away any additions/deletions done
with this IndexWriter, and release any resources used by the IndexWriter.
IndexReader
===========
* Subclass :class:`whoosh.reading.IndexReader`.
* IndexReaders must implement the following methods.
* :meth:`whoosh.reading.IndexReader.__contains__`
* :meth:`whoosh.reading.IndexReader.__iter__`
* :meth:`whoosh.reading.IndexReader.iter_from`
* :meth:`whoosh.reading.IndexReader.stored_fields`
* :meth:`whoosh.reading.IndexReader.doc_count_all`
* :meth:`whoosh.reading.IndexReader.doc_count`
* :meth:`whoosh.reading.IndexReader.doc_field_length`
* :meth:`whoosh.reading.IndexReader.field_length`
* :meth:`whoosh.reading.IndexReader.max_field_length`
* :meth:`whoosh.reading.IndexReader.postings`
* :meth:`whoosh.reading.IndexReader.has_vector`
* :meth:`whoosh.reading.IndexReader.vector`
* :meth:`whoosh.reading.IndexReader.doc_frequency`
* :meth:`whoosh.reading.IndexReader.frequency`
* Backends that support deleting documents should implement the following
methods.
* :meth:`whoosh.reading.IndexReader.has_deletions`
* :meth:`whoosh.reading.IndexReader.is_deleted`
* Backends that support versioning should implement the following methods.
* :meth:`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.
* :meth:`whoosh.reading.IndexReader.field`
* :meth:`whoosh.reading.IndexReader.field_names`
* :meth:`whoosh.reading.IndexReader.scorable_names`
* :meth:`whoosh.reading.IndexReader.vector_names`
* IndexReaders *may* implement the following methods.
* :meth:`whoosh.reading.DocReader.close` -- closes any open resources associated with the
reader.
Matcher
=======
The :meth:`whoosh.reading.IndexReader.postings` method returns a
:class:`whoosh.matching.Matcher` object. You will probably need to implement
a custom Matcher class for reading from your posting lists.
* Subclass :class:`whoosh.matching.Matcher`.
* Implement the following methods at minimum.
* :meth:`whoosh.matching.Matcher.is_active`
* :meth:`whoosh.matching.Matcher.copy`
* :meth:`whoosh.matching.Matcher.id`
* :meth:`whoosh.matching.Matcher.next`
* :meth:`whoosh.matching.Matcher.value`
* :meth:`whoosh.matching.Matcher.value_as`
* :meth:`whoosh.matching.Matcher.score`
* Depending on the implementation, you *may* implement the following methods
more efficiently.
* :meth:`whoosh.matching.Matcher.skip_to`
* :meth:`whoosh.matching.Matcher.weight`
* If the implementation supports quality, you should implement the following
methods.
* :meth:`whoosh.matching.Matcher.supports_quality`
* :meth:`whoosh.matching.Matcher.quality`
* :meth:`whoosh.matching.Matcher.block_quality`
* :meth:`whoosh.matching.Matcher.skip_to_quality`
|