mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
- Core Go application with GraphQL API using gqlgen - Comprehensive data models for literary works, authors, translations - Repository pattern with caching layer - Authentication and authorization system - Linguistics analysis capabilities with multiple adapters - Vector search integration with Weaviate - Docker containerization support - Python data migration and analysis scripts - Clean architecture with proper separation of concerns - Production-ready configuration and middleware - Proper .gitignore excluding vendor/, database files, and build artifacts
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
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) }
|