MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / upsertDocument

Method upsertDocument

internal/search/search.go:414–436  ·  view source on GitHub ↗

upsertDocument handles the final upsert operation to Typesense

(ctx context.Context, table string, data map[string]interface{})

Source from the content-addressed store, hash-verified

412
413// upsertDocument handles the final upsert operation to Typesense
414func (t *TypesenseClient) upsertDocument(ctx context.Context, table string, data map[string]interface{}) error {
415 idField := t.getIDField(table)
416
417 if idField != "" {
418 if id, ok := data[idField].(string); ok && id != "" {
419 // Upsert the document in Typesense with the provided ID
420 data["id"] = id
421 _, err := t.Client.Collection(table).Documents().Upsert(ctx, data)
422 if err != nil {
423 return fmt.Errorf("failed to upsert document in Typesense: %w", err)
424 }
425 return nil
426 }
427 }
428
429 // For other collections, perform a regular upsert
430 _, err := t.Client.Collection(table).Documents().Upsert(ctx, data)
431 if err != nil {
432 return fmt.Errorf("failed to index document in Typesense: %w", err)
433 }
434
435 return nil
436}
437
438// MigrateTypeSenseSchema adds new fields and removes old fields from the existing collection schema in Typesense.
439// This is useful when the schema has been updated, and fields need to be added or removed.

Callers 2

HandleNotificationMethod · 0.95

Calls 1

getIDFieldMethod · 0.95

Tested by

no test coverage detected