search

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEngineAvailable = errors.New("no search engine available")
	ErrEngineNotFound    = errors.New("search engine not found")
)

Search engine error definitions

Functions

func RegisterAdapterFactory added in v0.2.0

func RegisterAdapterFactory(engine Engine, factory AdapterFactory)

RegisterAdapterFactory registers a factory for creating search adapters This is called by search driver packages in their init() functions

Types

type Adapter added in v0.2.0

type Adapter interface {
	Search(ctx context.Context, req *Request) (*Response, error)
	Index(ctx context.Context, req *IndexRequest) error
	Delete(ctx context.Context, index, id string) error
	BulkIndex(ctx context.Context, index string, documents []any) error
	BulkDelete(ctx context.Context, index string, documentIDs []string) error
	IndexExists(ctx context.Context, indexName string) (bool, error)
	CreateIndex(ctx context.Context, indexName string, settings *IndexSettings) error
	Health(ctx context.Context) error
	Type() Engine
}

Adapter defines the interface for search engine implementations

type AdapterFactory added in v0.2.0

type AdapterFactory func(conn any) (Adapter, error)

AdapterFactory creates search adapters from data connections

func GetAdapterFactory added in v0.2.0

func GetAdapterFactory(engine Engine) (AdapterFactory, error)

GetAdapterFactory returns the factory for a given engine

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages search operations across multiple search engines

func NewClient

func NewClient(collector Collector, adapters ...Adapter) *Client

NewClient creates a new search client with provided adapters

func NewClientWithConfig

func NewClientWithConfig(collector Collector, searchConfig *Config, adapters ...Adapter) *Client

NewClientWithConfig creates a new search client with configuration

func NewClientWithPrefix

func NewClientWithPrefix(collector Collector, prefix string, adapters ...Adapter) *Client

NewClientWithPrefix creates a new search client with index prefix

func (*Client) BulkDelete

func (c *Client) BulkDelete(ctx context.Context, index string, documentIDs []string) error

func (*Client) BulkIndex

func (c *Client) BulkIndex(ctx context.Context, index string, documents []any) error

func (*Client) BulkIndexWith

func (c *Client) BulkIndexWith(ctx context.Context, engine Engine, index string, documents []any) error

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, index, documentID string) error

func (*Client) GetAvailableEngines

func (c *Client) GetAvailableEngines() []Engine

func (*Client) GetEngine

func (c *Client) GetEngine() Engine

func (*Client) GetIndexPrefix

func (c *Client) GetIndexPrefix() string

func (*Client) GetSearchConfig

func (c *Client) GetSearchConfig() *Config

func (*Client) Health

func (c *Client) Health(ctx context.Context) map[Engine]error

func (*Client) Index

func (c *Client) Index(ctx context.Context, req *IndexRequest) error

func (*Client) IndexWith

func (c *Client) IndexWith(ctx context.Context, engine Engine, req *IndexRequest) error

func (*Client) Search

func (c *Client) Search(ctx context.Context, req *Request) (*Response, error)

func (*Client) SearchWith

func (c *Client) SearchWith(ctx context.Context, engine Engine, req *Request) (*Response, error)

func (*Client) SetIndexPrefix

func (c *Client) SetIndexPrefix(prefix string)

func (*Client) UpdateSearchConfig

func (c *Client) UpdateSearchConfig(searchConfig *Config)

type Collector added in v0.2.1

type Collector interface {
	SearchQuery(engine string, err error)
	SearchIndex(engine, operation string)
}

Collector interface for metrics collection

type Config added in v0.2.1

type Config struct {
	IndexPrefix     string
	DefaultEngine   string
	AutoCreateIndex bool
	IndexSettings   *IndexSettings
}

Config represents search engine configuration

type Engine

type Engine string

Engine represents the type of search engine

const (
	Elasticsearch Engine = "elasticsearch"
	OpenSearch    Engine = "opensearch"
	Meilisearch   Engine = "meilisearch"
)

Supported search engine constants

func GetRegisteredEngines added in v0.2.0

func GetRegisteredEngines() []Engine

GetRegisteredEngines returns list of engines with registered factories

type Hit

type Hit struct {
	ID     string         `json:"id"`
	Score  float64        `json:"score"`
	Source map[string]any `json:"source"`
}

Hit represents a single search result

type IndexRequest

type IndexRequest struct {
	Index      string `json:"index"`
	DocumentID string `json:"document_id,omitempty"`
	Document   any    `json:"document"`
}

IndexRequest represents a document indexing request

type IndexSettings added in v0.2.1

type IndexSettings struct {
	Shards           int
	Replicas         int
	RefreshInterval  string
	SearchableFields []string
	FilterableFields []string
}

IndexSettings represents default index configuration

type NoOpCollector added in v0.2.1

type NoOpCollector struct{}

NoOpCollector is a no-op implementation of Collector

func (NoOpCollector) SearchIndex added in v0.2.1

func (NoOpCollector) SearchIndex(string, string)

func (NoOpCollector) SearchQuery added in v0.2.1

func (NoOpCollector) SearchQuery(string, error)

type Request

type Request struct {
	Index  string         `json:"index"`
	Query  string         `json:"query"`
	Filter map[string]any `json:"filter,omitempty"`
	From   int            `json:"from,omitempty"`
	Size   int            `json:"size,omitempty"`
}

Request represents a search query request

type Response

type Response struct {
	Total    int64         `json:"total"`
	Hits     []Hit         `json:"hits"`
	Duration time.Duration `json:"duration"`
	Engine   Engine        `json:"engine"`
}

Response represents a search query response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL