package services import ( "context" "fmt" "log" "tercul/models" "tercul/repositories" "tercul/weaviate" ) // SearchIndexService pushes localized snapshots into Weaviate for search type SearchIndexService interface { IndexWork(ctx context.Context, work models.Work) error } type searchIndexService struct { localization LocalizationService translations repositories.TranslationRepository } func NewSearchIndexService(localization LocalizationService, translations repositories.TranslationRepository) SearchIndexService { return &searchIndexService{localization: localization, translations: translations} } func (s *searchIndexService) IndexWork(ctx context.Context, work models.Work) error { // Choose best content snapshot for indexing content, err := s.localization.GetWorkContent(ctx, work.ID, work.Language) if err != nil { return err } props := map[string]interface{}{ "language": work.Language, "title": work.Title, "description": work.Description, "status": work.Status, } if content != "" { props["content"] = content } _, wErr := weaviate.Client.Data().Creator(). WithClassName("Work"). WithID(formatID(work.ID)). WithProperties(props). Do(ctx) if wErr != nil { log.Printf("weaviate index error: %v", wErr) return wErr } return nil } func formatID(id uint) string { return fmt.Sprintf("%d", id) }