Documentation
¶
Overview ¶
Package search provides search backend implementations including Elasticsearch.
Index ¶
- Variables
- type Document
- type ElasticBackend
- func (eb *ElasticBackend) BulkIndex(ctx context.Context, docs []Document) error
- func (eb *ElasticBackend) Delete(ctx context.Context, docType string, id string) error
- func (eb *ElasticBackend) GetBackendName() string
- func (eb *ElasticBackend) HealthCheck(ctx context.Context) error
- func (eb *ElasticBackend) Index(ctx context.Context, doc Document) error
- func (eb *ElasticBackend) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
- type ElasticSearchResponse
- type Facet
- type PostgresBackend
- func (pb *PostgresBackend) BulkIndex(ctx context.Context, docs []Document) error
- func (pb *PostgresBackend) Delete(ctx context.Context, docType string, id string) error
- func (pb *PostgresBackend) GetBackendName() string
- func (pb *PostgresBackend) HealthCheck(ctx context.Context) error
- func (pb *PostgresBackend) Index(ctx context.Context, doc Document) error
- func (pb *PostgresBackend) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
- type SearchBackend
- type SearchError
- type SearchHit
- type SearchManager
- func (sm *SearchManager) GetBackend(name string) (SearchBackend, bool)
- func (sm *SearchManager) GetPrimaryBackend() SearchBackend
- func (sm *SearchManager) RegisterBackend(name string, backend SearchBackend, isPrimary bool)
- func (sm *SearchManager) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
- type SearchQuery
- type SearchResults
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoBackendAvailable = &SearchError{Code: "NO_BACKEND", Message: "No search backend available"} ErrInvalidQuery = &SearchError{Code: "INVALID_QUERY", Message: "Invalid search query"} ErrIndexingFailed = &SearchError{Code: "INDEXING_FAILED", Message: "Failed to index document"} )
Common errors.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
ID string `json:"id"`
Type string `json:"type"` // ticket, article, customer, etc.
Title string `json:"title"`
Content string `json:"content"`
Metadata map[string]interface{} `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
ModifiedAt time.Time `json:"modified_at"`
}
Document represents a searchable document.
type ElasticBackend ¶
type ElasticBackend struct {
// contains filtered or unexported fields
}
ElasticBackend implements SearchBackend using Elasticsearch-compatible APIs (works with Zinc).
func NewElasticBackend ¶
func NewElasticBackend(endpoint, username, password string) *ElasticBackend
NewElasticBackend creates a new Elasticsearch/Zinc search backend.
func (*ElasticBackend) BulkIndex ¶
func (eb *ElasticBackend) BulkIndex(ctx context.Context, docs []Document) error
BulkIndex indexes multiple documents at once.
func (*ElasticBackend) GetBackendName ¶
func (eb *ElasticBackend) GetBackendName() string
GetBackendName returns the backend name.
func (*ElasticBackend) HealthCheck ¶
func (eb *ElasticBackend) HealthCheck(ctx context.Context) error
HealthCheck verifies the Elasticsearch/Zinc connection.
func (*ElasticBackend) Index ¶
func (eb *ElasticBackend) Index(ctx context.Context, doc Document) error
Index adds or updates a document in Elasticsearch/Zinc.
func (*ElasticBackend) Search ¶
func (eb *ElasticBackend) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
Search performs a search using Elasticsearch/Zinc.
type ElasticSearchResponse ¶
type ElasticSearchResponse struct {
Took int64 `json:"took"`
Hits struct {
Total struct {
Value int `json:"value"`
} `json:"total"`
Hits []struct {
ID string `json:"_id"`
Score float64 `json:"_score"`
Source map[string]interface{} `json:"_source"`
Highlight map[string][]string `json:"highlight,omitempty"`
} `json:"hits"`
} `json:"hits"`
}
ElasticSearchResponse represents Elasticsearch API response.
type PostgresBackend ¶
type PostgresBackend struct {
// contains filtered or unexported fields
}
PostgresBackend implements SearchBackend using PostgreSQL full-text search.
func NewPostgresBackend ¶
func NewPostgresBackend() (*PostgresBackend, error)
NewPostgresBackend creates a new PostgreSQL search backend.
func (*PostgresBackend) BulkIndex ¶
func (pb *PostgresBackend) BulkIndex(ctx context.Context, docs []Document) error
BulkIndex indexes multiple documents (no-op for PostgreSQL).
func (*PostgresBackend) GetBackendName ¶
func (pb *PostgresBackend) GetBackendName() string
GetBackendName returns the backend name.
func (*PostgresBackend) HealthCheck ¶
func (pb *PostgresBackend) HealthCheck(ctx context.Context) error
HealthCheck verifies the PostgreSQL connection.
func (*PostgresBackend) Index ¶
func (pb *PostgresBackend) Index(ctx context.Context, doc Document) error
Index adds or updates a document (no-op for PostgreSQL as it searches directly).
func (*PostgresBackend) Search ¶
func (pb *PostgresBackend) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
Search performs a full-text search using PostgreSQL.
type SearchBackend ¶
type SearchBackend interface {
// Search performs a search across specified entities
Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
// Index adds or updates a document in the search index
Index(ctx context.Context, doc Document) error
// Delete removes a document from the search index
Delete(ctx context.Context, docType string, id string) error
// BulkIndex indexes multiple documents at once
BulkIndex(ctx context.Context, docs []Document) error
// HealthCheck verifies the search backend is operational
HealthCheck(ctx context.Context) error
// GetBackendName returns the name of the search backend
GetBackendName() string
}
SearchBackend defines the interface for pluggable search implementations.
type SearchError ¶
SearchError represents a search-related error.
func (*SearchError) Error ¶
func (e *SearchError) Error() string
type SearchHit ¶
type SearchHit struct {
ID string `json:"id"`
Type string `json:"type"`
Score float64 `json:"score"`
Title string `json:"title"`
Content string `json:"content"`
Highlights map[string][]string `json:"highlights,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
}
SearchHit represents a single search result.
type SearchManager ¶
type SearchManager struct {
// contains filtered or unexported fields
}
SearchManager manages different search backend implementations.
func NewSearchManager ¶
func NewSearchManager() *SearchManager
NewSearchManager creates a new search manager.
func (*SearchManager) GetBackend ¶
func (sm *SearchManager) GetBackend(name string) (SearchBackend, bool)
GetBackend returns a specific backend by name.
func (*SearchManager) GetPrimaryBackend ¶
func (sm *SearchManager) GetPrimaryBackend() SearchBackend
GetPrimaryBackend returns the primary search backend.
func (*SearchManager) RegisterBackend ¶
func (sm *SearchManager) RegisterBackend(name string, backend SearchBackend, isPrimary bool)
RegisterBackend registers a search backend.
func (*SearchManager) Search ¶
func (sm *SearchManager) Search(ctx context.Context, query SearchQuery) (*SearchResults, error)
Search performs a search using the primary backend.
type SearchQuery ¶
type SearchQuery struct {
Query string `json:"query"` // The search query string
Types []string `json:"types"` // Entity types to search (ticket, article, customer)
Filters map[string]string `json:"filters"` // Additional filters
Offset int `json:"offset"` // Pagination offset
Limit int `json:"limit"` // Results per page
SortBy string `json:"sort_by"` // Sort field
SortOrder string `json:"sort_order"` // asc or desc
Highlight bool `json:"highlight"` // Enable result highlighting
Facets []string `json:"facets"` // Fields to generate facets for
}
SearchQuery represents a search request.
type SearchResults ¶
type SearchResults struct {
Query string `json:"query"`
TotalHits int `json:"total_hits"`
Took int64 `json:"took_ms"` // Time taken in milliseconds
Hits []SearchHit `json:"hits"`
Facets map[string][]Facet `json:"facets,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
}
SearchResults contains search results.