Restore from checkpoint bytes.
(bytes: &[u8])
| 172 | |
| 173 | /// Restore from checkpoint bytes. |
| 174 | pub fn from_checkpoint(bytes: &[u8]) -> Option<Self> { |
| 175 | let snapshot: SparseIndexSnapshot = zerompk::from_msgpack(bytes).ok()?; |
| 176 | let mut index = Self::new(); |
| 177 | index.next_id = snapshot.next_id; |
| 178 | |
| 179 | for doc in snapshot.documents { |
| 180 | index |
| 181 | .doc_id_forward |
| 182 | .insert(doc.doc_id.clone(), doc.internal_id); |
| 183 | index.doc_id_reverse.insert(doc.internal_id, doc.doc_id); |
| 184 | |
| 185 | let mut dims = Vec::with_capacity(doc.entries.len()); |
| 186 | for (dim, weight) in doc.entries { |
| 187 | index |
| 188 | .postings |
| 189 | .entry(dim) |
| 190 | .or_default() |
| 191 | .push((doc.internal_id, weight)); |
| 192 | dims.push(dim); |
| 193 | } |
| 194 | index.doc_dims.insert(doc.internal_id, dims); |
| 195 | index.doc_count += 1; |
| 196 | } |
| 197 | |
| 198 | Some(index) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /// Checkpoint serialization format. |