Skip to content

Commit

Permalink
update indexer to perform replacement for existing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Jul 3, 2024
1 parent 2802bbc commit 8529f57
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions app/services/semdex/weaviate/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,37 @@ func (s *weaviateSemdexer) Index(ctx context.Context, object datagraph.Indexable
return nil
}

_, err := s.wc.Data().Creator().
WithClassName(s.cn.String()).
WithID(wid).
WithProperties(map[string]any{
"datagraph_id": sid.String(),
"datagraph_type": object.GetKind(),
"name": object.GetName(),
"content": content,
"props": object.GetProps(),
}).
Do(ctx)
existing, err := s.wc.Data().ObjectsGetter().WithID(wid).Do(ctx)
if err != nil {
return fault.Wrap(err, fctx.With(ctx))
}

if len(existing) > 0 {
err = s.wc.Data().Updater().
WithClassName(s.cn.String()).
WithID(wid).
WithProperties(map[string]any{
"datagraph_id": sid.String(),
"datagraph_type": object.GetKind(),
"name": object.GetName(),
"content": content,
"props": object.GetProps(),
}).
Do(ctx)
} else {
_, err = s.wc.Data().Creator().
WithClassName(s.cn.String()).
WithID(wid).
WithProperties(map[string]any{
"datagraph_id": sid.String(),
"datagraph_type": object.GetKind(),
"name": object.GetName(),
"content": content,
"props": object.GetProps(),
}).
Do(ctx)
}

if err != nil {
we := &weaviate_errors.WeaviateClientError{}
if errors.As(err, &we) {
Expand Down

0 comments on commit 8529f57

Please sign in to comment.