Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
47
cloud/maplepress-backend/pkg/search/meilisearch.go
Normal file
47
cloud/maplepress-backend/pkg/search/meilisearch.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// File Path: monorepo/cloud/maplepress-backend/pkg/search/meilisearch.go
|
||||
package search
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/meilisearch/meilisearch-go"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Client wraps the Meilisearch client
|
||||
type Client struct {
|
||||
client meilisearch.ServiceManager
|
||||
config *Config
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewClient creates a new Meilisearch client
|
||||
func NewClient(config *Config, logger *zap.Logger) (*Client, error) {
|
||||
if config.Host == "" {
|
||||
return nil, fmt.Errorf("meilisearch host is required")
|
||||
}
|
||||
|
||||
client := meilisearch.New(config.Host, meilisearch.WithAPIKey(config.APIKey))
|
||||
|
||||
return &Client{
|
||||
client: client,
|
||||
config: config,
|
||||
logger: logger.Named("meilisearch"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetIndexName returns the full index name for a site
|
||||
func (c *Client) GetIndexName(siteID string) string {
|
||||
return c.config.IndexPrefix + siteID
|
||||
}
|
||||
|
||||
// Health checks if Meilisearch is healthy
|
||||
func (c *Client) Health() error {
|
||||
_, err := c.client.Health()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetClient returns the underlying Meilisearch client (for advanced operations)
|
||||
func (c *Client) GetClient() meilisearch.ServiceManager {
|
||||
return c.client
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue