MCPcopy
hub / github.com/zincsearch/zincsearch / UpdateDocument

Method UpdateDocument

pkg/core/index_document.go:62–88  ·  view source on GitHub ↗

UpdateDocument updates a document in the zinc index

(docID string, doc map[string]interface{}, insert bool)

Source from the content-addressed store, hash-verified

60
61// UpdateDocument updates a document in the zinc index
62func (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
91func (index *Index) DeleteDocument(docID string) error {

Callers 2

TestIndex_UpdateDocumentFunction · 0.95
UpdateFunction · 0.80

Calls 7

GetNameMethod · 0.95
GetShardByDocIDMethod · 0.95
IncrMetricStatsByIndexFunction · 0.85
OpenWALMethod · 0.80
FindShardByDocIDMethod · 0.80
CheckDocumentMethod · 0.80
WriteMethod · 0.45

Tested by 1

TestIndex_UpdateDocumentFunction · 0.76