UpdateDocument updates a document in the zinc index
(docID string, doc map[string]interface{}, insert bool)
| 60 | |
| 61 | // UpdateDocument updates a document in the zinc index |
| 62 | func (index *Index) UpdateDocument(docID string, doc map[string]interface{}, insert bool) error { |
| 63 | // metrics |
| 64 | IncrMetricStatsByIndex(index.GetName(), "wal_request") |
| 65 | |
| 66 | // check WAL |
| 67 | shard := index.GetShardByDocID(docID) |
| 68 | if err := shard.OpenWAL(); err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | update := true |
| 73 | secondShardID, err := shard.FindShardByDocID(docID) |
| 74 | if err != nil { |
| 75 | if insert && err == errors.ErrorIDNotFound { |
| 76 | update = false |
| 77 | } else { |
| 78 | return err |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | data, err := shard.CheckDocument(docID, doc, update, secondShardID) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | return shard.wal.Write(data) |
| 88 | } |
| 89 | |
| 90 | // DeleteDocument deletes a document in the zinc index |
| 91 | func (index *Index) DeleteDocument(docID string) error { |