meilisearch

package
v0.0.0-...-66c3222 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexToRecords

func IndexToRecords(index [][]index.Index) iter.Seq[Record]

IndexToRecords converts an Index to a slice of search Records

Types

type Client

type Client struct {
	*http.Client
	URL       string
	MasterKey string
	IndexUID  string
}

func NewClient

func NewClient(client *http.Client, url, masterKey, indexUID string) *Client

func (*Client) BuildIndex

func (c *Client) BuildIndex(ctx context.Context, index [][]index.Index) error

func (*Client) ClearIndex

func (c *Client) ClearIndex(ctx context.Context) error

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (SearchResponse, error)

type CreateKeyRequest

type CreateKeyRequest struct {
	Actions     []string `json:"actions"`
	Indexes     []string `json:"indexes"`
	ExpiresAt   string   `json:"expiresAt"`
	Name        *string  `json:"name"`
	Description *string  `json:"description"`
	UID         string   `json:"uid,omitempty"`
}

type CreateKeyResponse

type CreateKeyResponse struct {
	CreateKeyRequest `       json:",inline"`
	Key              string `json:"key"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	Type    string `json:"type"`
	Link    string `json:"link"`
}

type GetTaskResponse

type GetTaskResponse struct {
	UID        int           `json:"uid"`
	IndexUID   string        `json:"indexUid"`
	Status     TaskStatus    `json:"status"`
	Type       string        `json:"type"`
	CanceledBy int           `json:"canceledBy"`
	Details    any           `json:"details"`
	Error      ErrorResponse `json:"error"`
}

type Hit

type Hit map[string]json.RawMessage // Hit is a map of key and value raw buffer

func (Hit) DecodeInto

func (h Hit) DecodeInto(out any) error

DecodeInto decodes a single Hit into the provided struct without intermediate marshaling.

func (Hit) DecodeWith

func (h Hit) DecodeWith(vPtr any, marshal JSONMarshal, unmarshal JSONUnmarshal) error

DecodeWith decodes a Hit into the provided struct using the provided marshal and unmarshal functions.

type Hits

type Hits []Hit // Hits is an alias for a slice of Hit.

func (Hits) DecodeInto

func (h Hits) DecodeInto(vSlicePtr any) error

DecodeInto decodes hs into the provided slice pointer without re-marshal. vSlicePtr must be a non-nil pointer to a slice whose element type is a struct or *struct. Example:

var out []exampleBookForTest
if err := hits.DecodeInto(&out); err != nil { ... }

var outPtr []*exampleBookForTest
if err := hits.DecodeInto(&outPtr); err != nil { ... }

func (Hits) DecodeWith

func (h Hits) DecodeWith(
	vSlicePtr any,
	marshal JSONMarshal,
	unmarshal JSONUnmarshal,
) error

DecodeWith decodes a Hits into the provided struct using the provided marshal and unmarshal functions.

func (Hits) Len

func (h Hits) Len() int

type JSONMarshal

type JSONMarshal func(v any) ([]byte, error)

JSONMarshal returns the JSON encoding of v.

type JSONUnmarshal

type JSONUnmarshal func(data []byte, v any) error

JSONUnmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

type MatchingStrategy

type MatchingStrategy string
const (
	// Last returns documents containing all the query terms first. If there are not enough results containing all
	// query terms to meet the requested limit, Meilisearch will remove one query term at a time,
	// starting from the end of the query.
	Last MatchingStrategy = "last"
	// All only returns documents that contain all query terms. Meilisearch will not match any more documents even
	// if there aren't enough to meet the requested limit.
	All MatchingStrategy = "all"
	// Frequency returns documents containing all the query terms first. If there are not enough results containing
	//all query terms to meet the requested limit, Meilisearch will remove one query term at a time, starting
	//with the word that is the most frequent in the dataset. frequency effectively gives more weight to terms
	//that appear less frequently in a set of results.
	Frequency MatchingStrategy = "frequency"
)

type Record

type Record struct {
	ObjectID      string `json:"objectID"`
	HierarchyLvl0 string `json:"hierarchy_lvl0,omitempty"`
	HierarchyLvl1 string `json:"hierarchy_lvl1,omitempty"`
	HierarchyLvl2 string `json:"hierarchy_lvl2,omitempty"`
	HierarchyLvl3 string `json:"hierarchy_lvl3,omitempty"`
	HierarchyLvl4 string `json:"hierarchy_lvl4,omitempty"`
	HierarchyLvl5 string `json:"hierarchy_lvl5,omitempty"`
	HierarchyLvl6 string `json:"hierarchy_lvl6,omitempty"`
	Content       string `json:"content"`
	URL           string `json:"url"`
	Anchor        string `json:"anchor"`
}

type RecordWithFormat

type RecordWithFormat struct {
	Record    `json:",inline"`
	Formatted Record `json:"_formatted"`
}

type SearchFederationOptions

type SearchFederationOptions struct {
	Weight float64 `json:"weight,omitempty"`
	Remote string  `json:"remote,omitempty"`
}

type SearchRequest

type SearchRequest struct {
	Offset                  int64                    `json:"offset,omitempty"`
	Limit                   int64                    `json:"limit,omitempty"`
	AttributesToRetrieve    []string                 `json:"attributesToRetrieve,omitempty"`
	AttributesToSearchOn    []string                 `json:"attributesToSearchOn,omitempty"`
	AttributesToCrop        []string                 `json:"attributesToCrop,omitempty"`
	CropLength              int64                    `json:"cropLength,omitempty"`
	CropMarker              string                   `json:"cropMarker,omitempty"`
	AttributesToHighlight   []string                 `json:"attributesToHighlight,omitempty"`
	HighlightPreTag         string                   `json:"highlightPreTag,omitempty"`
	HighlightPostTag        string                   `json:"highlightPostTag,omitempty"`
	MatchingStrategy        MatchingStrategy         `json:"matchingStrategy,omitempty"`
	Filter                  any                      `json:"filter,omitempty"`
	ShowMatchesPosition     bool                     `json:"showMatchesPosition,omitempty"`
	ShowRankingScore        bool                     `json:"showRankingScore,omitempty"`
	ShowRankingScoreDetails bool                     `json:"showRankingScoreDetails,omitempty"`
	Facets                  []string                 `json:"facets,omitempty"`
	Sort                    []string                 `json:"sort,omitempty"`
	Vector                  []float32                `json:"vector,omitempty"`
	HitsPerPage             int64                    `json:"hitsPerPage,omitempty"`
	Page                    int64                    `json:"page,omitempty"`
	IndexUID                string                   `json:"indexUid,omitempty"`
	Query                   string                   `json:"q"`
	Distinct                string                   `json:"distinct,omitempty"`
	Hybrid                  *SearchRequestHybrid     `json:"hybrid"`
	RetrieveVectors         bool                     `json:"retrieveVectors,omitempty"`
	RankingScoreThreshold   float64                  `json:"rankingScoreThreshold,omitempty"`
	FederationOptions       *SearchFederationOptions `json:"federationOptions,omitempty"`
	Locales                 []string                 `json:"locales,omitempty"`
	Media                   map[string]any           `json:"media,omitempty"`
}

SearchRequest is the request url param needed for a search query. This struct will be converted to url param before sent.

Documentation: https://www.meilisearch.com/docs/reference/api/search#search-parameters

type SearchRequestHybrid

type SearchRequestHybrid struct {
	SemanticRatio float64 `json:"semanticRatio,omitempty"`
	Embedder      string  `json:"embedder"`
}

type SearchResponse

type SearchResponse struct {
	Hits               Hits            `json:"hits"`
	EstimatedTotalHits int64           `json:"estimatedTotalHits,omitempty"`
	Offset             int64           `json:"offset,omitempty"`
	Limit              int64           `json:"limit,omitempty"`
	ProcessingTimeMs   int64           `json:"processingTimeMs"`
	Query              string          `json:"query"`
	FacetDistribution  json.RawMessage `json:"facetDistribution,omitempty"`
	TotalHits          int64           `json:"totalHits,omitempty"`
	HitsPerPage        int64           `json:"hitsPerPage,omitempty"`
	Page               int64           `json:"page,omitempty"`
	TotalPages         int64           `json:"totalPages,omitempty"`
	FacetStats         json.RawMessage `json:"facetStats,omitempty"`
	IndexUID           string          `json:"indexUid,omitempty"`
	QueryVector        *[]float32      `json:"queryVector,omitempty"`
}

SearchResponse is the response body for search method

type SubmittedTaskResponse

type SubmittedTaskResponse struct {
	TaskUID  int        `json:"taskUid"`
	IndexUID string     `json:"indexUid"`
	Status   TaskStatus `json:"status"`
	Type     string     `json:"type"`
}

type TaskStatus

type TaskStatus string
const (
	// TaskStatusUnknown is the default TaskStatus, should not exist
	TaskStatusUnknown TaskStatus = "unknown"
	// TaskStatusEnqueued the task request has been received and will be processed soon
	TaskStatusEnqueued TaskStatus = "enqueued"
	// TaskStatusProcessing the task is being processed
	TaskStatusProcessing TaskStatus = "processing"
	// TaskStatusSucceeded the task has been successfully processed
	TaskStatusSucceeded TaskStatus = "succeeded"
	// TaskStatusFailed a failure occurred when processing the task, no changes were made to the database
	TaskStatusFailed TaskStatus = "failed"
	// TaskStatusCanceled the task was canceled
	TaskStatusCanceled TaskStatus = "canceled"
)

Jump to

Keyboard shortcuts

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