typesense

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEALTHY   = true
	UNHEALTHY = false
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClientInterface

type APIClientInterface interface {
	api.ClientWithResponsesInterface
	api.ClientInterface
}

type AliasInterface

type AliasInterface interface {
	Retrieve(ctx context.Context) (*api.CollectionAlias, error)
	Delete(ctx context.Context) (*api.CollectionAlias, error)
}

AliasInterface is a type for Alias API operations

type AliasesInterface

type AliasesInterface interface {
	Upsert(ctx context.Context, aliasName string, aliasSchema *api.CollectionAliasSchema) (*api.CollectionAlias, error)
	Retrieve(ctx context.Context) ([]*api.CollectionAlias, error)
}

AliasesInterface is a type for Aliases API operations

type ApiCall

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

func NewApiCall

func NewApiCall(client circuit.HTTPRequestDoer, config *ClientConfig) *ApiCall

func (*ApiCall) Do

func (a *ApiCall) Do(req *http.Request) (*http.Response, error)

type ApiCallOption

type ApiCallOption func(*ApiCall)

type Client

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

func NewClient

func NewClient(opts ...ClientOption) *Client

func (*Client) Alias

func (c *Client) Alias(aliasName string) AliasInterface

func (*Client) Aliases

func (c *Client) Aliases() AliasesInterface

func (*Client) Collection

func (c *Client) Collection(collectionName string) CollectionInterface[map[string]any]

func (*Client) Collections

func (c *Client) Collections() CollectionsInterface

func (*Client) Health

func (c *Client) Health(ctx context.Context, timeout time.Duration) (bool, error)

func (*Client) Key

func (c *Client) Key(keyID int64) KeyInterface

func (*Client) Keys

func (c *Client) Keys() KeysInterface

func (*Client) Operations

func (c *Client) Operations() OperationsInterface

func (*Client) Preset

func (c *Client) Preset(presetName string) PresetInterface

func (*Client) Presets

func (c *Client) Presets() PresetsInterface

type ClientConfig

type ClientConfig struct {
	ServerURL                   string
	NearestNode                 string // optional
	Nodes                       []string
	NumRetries                  int
	RetryInterval               time.Duration
	HealthcheckInterval         time.Duration
	APIKey                      string
	ConnectionTimeout           time.Duration
	CircuitBreakerName          string
	CircuitBreakerMaxRequests   uint32
	CircuitBreakerInterval      time.Duration
	CircuitBreakerTimeout       time.Duration
	CircuitBreakerReadyToTrip   circuit.GoBreakerReadyToTripFunc
	CircuitBreakerOnStateChange circuit.GoBreakerOnStateChangeFunc
}

type ClientOption

type ClientOption func(*Client)

func WithAPIClient

func WithAPIClient(apiClient APIClientInterface) ClientOption

WithAPIClient sets low-level API client

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey sets the API token.

func WithCircuitBreakerInterval

func WithCircuitBreakerInterval(interval time.Duration) ClientOption

WithCircuitBreakerInterval sets the cyclic period of the closed state for CircuitBreaker to clear the internal Counts, described in gobreaker documentation. If Interval is 0, CircuitBreaker doesn't clear the internal Counts during the closed state. Default value is 2 minutes.

func WithCircuitBreakerMaxRequests

func WithCircuitBreakerMaxRequests(maxRequests uint32) ClientOption

WithCircuitBreakerMaxRequests sets the maximum number of requests allowed to pass through when the CircuitBreaker is half-open. If MaxRequests is 0, CircuitBreaker allows only 1 request. Default value is 50 requests.

func WithCircuitBreakerName

func WithCircuitBreakerName(name string) ClientOption

WithCircuitBreakerName sets the name of the CircuitBreaker. Default value is "typesenseClient".

func WithCircuitBreakerOnStateChange

func WithCircuitBreakerOnStateChange(onStateChange circuit.GoBreakerOnStateChangeFunc) ClientOption

WithCircuitBreakerOnStateChange sets the function that is called whenever the state of CircuitBreaker changes.

func WithCircuitBreakerReadyToTrip

func WithCircuitBreakerReadyToTrip(readyToTrip circuit.GoBreakerReadyToTripFunc) ClientOption

WithCircuitBreakerReadyToTrip sets the function that is called with a copy of Counts whenever a request fails in the closed state. If ReadyToTrip returns true, CircuitBreaker will be placed into the open state. If ReadyToTrip is nil, default ReadyToTrip is used. Default ReadyToTrip returns true when number of requests more than 100 and the percent of failures is more than 50 percents.

func WithCircuitBreakerTimeout

func WithCircuitBreakerTimeout(timeout time.Duration) ClientOption

WithCircuitBreakerTimeout sets the period of the open state, after which the state of CircuitBreaker becomes half-open. If Timeout is 0, the timeout value of CircuitBreaker is set to 60 seconds. Default value is 1 minute.

func WithClientConfig

func WithClientConfig(config *ClientConfig) ClientOption

WithClientConfig allows to pass all configs at once

func WithConnectionTimeout

func WithConnectionTimeout(timeout time.Duration) ClientOption

WithConnectionTimeout sets the connection timeout of http client. Default value is 5 seconds.

func WithHealthcheckInterval

func WithHealthcheckInterval(duration time.Duration) ClientOption

WithHealthcheckInterval sets the wait time for an unhealthy node to become healthy again. A node is marked as unhealthy if its response status code is 5xx or has an error (e.g. timeout). Default value is 1 minute.

func WithNearestNode

func WithNearestNode(URL string) ClientOption

WithNearestNode sets the Load Balanced endpoint.

func WithNodes

func WithNodes(URLs []string) ClientOption

WithNodes sets multiple hostnames to load balance reads & writes across all nodes.

func WithNumRetries

func WithNumRetries(num int) ClientOption

WithNumRetries sets the number of retries per request. Default value is the number of nodes (+1 if nearestNode is specified).

func WithRetryInterval

func WithRetryInterval(duration time.Duration) ClientOption

WithRetryInterval sets the wait time between each retry. Default value is 100 milliseconds.

func WithServer

func WithServer(serverURL string) ClientOption

WithServer sets the API server URL

type CollectionInterface

type CollectionInterface[T any] interface {
	Retrieve(ctx context.Context) (*api.CollectionResponse, error)
	Delete(ctx context.Context) (*api.CollectionResponse, error)
	Documents() DocumentsInterface
	Document(documentID string) DocumentInterface[T]
	Overrides() OverridesInterface
	Override(overrideID string) OverrideInterface
	Synonyms() SynonymsInterface
	Synonym(synonymID string) SynonymInterface
	Update(context.Context, *api.CollectionUpdateSchema) (*api.CollectionUpdateSchema, error)
}

CollectionInterface is a type for Collection API operations

func GenericCollection

func GenericCollection[T any](c *Client, collectionName string) CollectionInterface[T]

type CollectionsInterface

type CollectionsInterface interface {
	Create(ctx context.Context, schema *api.CollectionSchema) (*api.CollectionResponse, error)
	Retrieve(ctx context.Context) ([]*api.CollectionResponse, error)
}

CollectionsInterface is a type for Collections API operations

type DocumentInterface

type DocumentInterface[T any] interface {
	Retrieve(ctx context.Context) (T, error)
	Update(ctx context.Context, document any) (T, error)
	Delete(ctx context.Context) (T, error)
}

type DocumentsInterface

type DocumentsInterface interface {
	// Create returns indexed document
	Create(ctx context.Context, document interface{}) (map[string]interface{}, error)
	// Update updates documents matching the filter_by condition
	Update(ctx context.Context, updateFields interface{}, params *api.UpdateDocumentsParams) (int, error)
	// Upsert returns indexed/updated document
	Upsert(context.Context, interface{}) (map[string]interface{}, error)
	// Delete returns number of deleted documents
	Delete(ctx context.Context, filter *api.DeleteDocumentsParams) (int, error)
	// Search performs document search in collection
	Search(ctx context.Context, params *api.SearchCollectionParams) (*api.SearchResult, error)
	// Export returns all documents from index in jsonl format
	Export(ctx context.Context) (io.ReadCloser, error)
	// Import returns json array. Each item of the response indicates
	// the result of each document present in the request body (in the same order).
	Import(ctx context.Context, documents []interface{}, params *api.ImportDocumentsParams) ([]*api.ImportDocumentResponse, error)
	// ImportJsonl accepts documents and returns result in jsonl format. Each line of the
	// response indicates the result of each document present in the
	// request body (in the same order).
	ImportJsonl(ctx context.Context, body io.Reader, params *api.ImportDocumentsParams) (io.ReadCloser, error)
}

DocumentsInterface is a type for Documents API operations

type HTTPError

type HTTPError struct {
	Status int
	Body   []byte
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type KeyInterface

type KeyInterface interface {
	Retrieve(ctx context.Context) (*api.ApiKey, error)
	Delete(ctx context.Context) (*api.ApiKey, error)
}

type KeysInterface

type KeysInterface interface {
	Create(context.Context, *api.ApiKeySchema) (*api.ApiKey, error)
	Retrieve(context.Context) ([]*api.ApiKey, error)
	GenerateScopedSearchKey(searchKey string, params map[string]interface{}) (string, error)
}

type MultiSearchInterface

type MultiSearchInterface interface {
	Perform(ctx context.Context, commonSearchParams *api.MultiSearchParams, searchParams api.MultiSearchSearchesParameter) (*api.MultiSearchResult, error)
	PerformWithContentType(ctx context.Context, commonSearchParams *api.MultiSearchParams, searchParams api.MultiSearchSearchesParameter, contentType string) (*api.MultiSearchResponse, error)
}

type Node

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

type OperationsInterface

type OperationsInterface interface {
	Snapshot(ctx context.Context, snapshotPath string) (bool, error)
	Vote(ctx context.Context) (bool, error)
}

type OverrideInterface

type OverrideInterface interface {
	Retrieve(ctx context.Context) (*api.SearchOverride, error)
	Delete(ctx context.Context) (*api.SearchOverride, error)
}

OverrideInterface is a type for Search Override API operations

type OverridesInterface

type OverridesInterface interface {
	Upsert(ctx context.Context, overrideID string, overrideSchema *api.SearchOverrideSchema) (*api.SearchOverride, error)
	Retrieve(ctx context.Context) ([]*api.SearchOverride, error)
}

OverridesInterface is a type for Search Overrides API operations

type PresetInterface

type PresetInterface interface {
	Retrieve(ctx context.Context) (*api.PresetSchema, error)
	Delete(ctx context.Context) (*api.PresetDeleteSchema, error)
}

type PresetsInterface

type PresetsInterface interface {
	Retrieve(ctx context.Context) ([]*api.PresetSchema, error)
	Upsert(ctx context.Context, presetName string, presetValue *api.PresetUpsertSchema) (*api.PresetSchema, error)
}

type SynonymInterface

type SynonymInterface interface {
	// Retrieve a single search synonym
	Retrieve(ctx context.Context) (*api.SearchSynonym, error)
	// Delete a synonym associated with a collection
	Delete(ctx context.Context) (*api.SearchSynonym, error)
}

SynonymInterface is a type for Search Synonym API operations

type SynonymsInterface

type SynonymsInterface interface {
	// Create or update a synonym
	Upsert(ctx context.Context, synonymID string, synonymSchema *api.SearchSynonymSchema) (*api.SearchSynonym, error)
	// List all collection synonyms
	Retrieve(ctx context.Context) ([]*api.SearchSynonym, error)
}

SynonymsInterface is a type for Search Synonyms API operations

Directories

Path Synopsis
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
circuit
Package circuit implements the Circuit Breaker pattern for http client.
Package circuit implements the Circuit Breaker pattern for http client.
circuit/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
generator command
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package test contains integration tests for the github.com/typesense/typesense-go/typesense package.
Package test contains integration tests for the github.com/typesense/typesense-go/typesense package.

Jump to

Keyboard shortcuts

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