search

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 8 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")
)

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 *config.IndexSettings) error
	Health(ctx context.Context) error
	Type() Engine
}

Adapter 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
}

func NewClient

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

NewClient creates a new search client with provided adapters

func NewClientFromData added in v0.2.0

func NewClientFromData(d *data.Data, collector ...metrics.Collector) *Client

NewClientFromData creates a search client from ncore data layer Automatically detects and creates adapters for available search engines

func NewClientWithConfig

func NewClientWithConfig(collector metrics.Collector, searchConfig *config.Search, adapters ...Adapter) *Client

NewClientWithConfig creates a new search client with configuration

func NewClientWithPrefix

func NewClientWithPrefix(collector metrics.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.Search

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.Search)

type Engine

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

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"`
}

type IndexRequest

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

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"`
}

type Response

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

Jump to

Keyboard shortcuts

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