Files
gochat/backend/internal/service/search_indexer.go
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

61 lines
2.0 KiB
Go

package service
import (
"context"
"github.com/gochat/gochat/internal/model"
"github.com/gochat/gochat/internal/search"
applogger "github.com/gochat/gochat/pkg/logger"
)
// SearchIndexer is the service-layer boundary for search synchronization.
// Implementations may index synchronously or enqueue durable jobs later.
type SearchIndexer interface {
IndexConversation(ctx context.Context, conversation *model.Conversation) error
DeleteConversation(ctx context.Context, accountID uint, id uint) error
IndexMessage(ctx context.Context, message *model.Message) error
DeleteMessage(ctx context.Context, accountID uint, id uint) error
IndexContact(ctx context.Context, contact *model.Contact) error
DeleteContact(ctx context.Context, accountID uint, id uint) error
IndexCompany(ctx context.Context, company *model.Company) error
DeleteCompany(ctx context.Context, accountID uint, id uint) error
IndexArticle(ctx context.Context, article *model.Article) error
DeleteArticle(ctx context.Context, accountID uint, id uint) error
}
type ContactSearchReader interface {
SearchContacts(ctx context.Context, accountID uint, query string, filter *search.SearchFilter) ([]search.SearchResult, int64, error)
}
type CompanySearchReader interface {
SearchCompanies(ctx context.Context, accountID uint, query string, filter *search.SearchFilter) ([]search.SearchResult, int64, error)
}
func serviceSearchFilter(offset, limit int, sort string, searchMode search.SearchMode, resultType search.SearchResultType) *search.SearchFilter {
if limit <= 0 {
limit = search.DefaultPerPage
}
page := 1
if offset > 0 {
page = offset/limit + 1
}
sortBy := sort
if sortBy == "" {
sortBy = search.DefaultSortBy
}
return &search.SearchFilter{
SearchMode: searchMode,
Types: []search.SearchResultType{resultType},
SortBy: sortBy,
SortOrder: search.DefaultSortOrder,
Page: page,
PerPage: limit,
}
}
func logSearchIndexError(entity string, id uint, err error) {
if err != nil {
applogger.L().Warnf("search index sync failed for %s %d: %v", entity, id, err)
}
}