meilisearch

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 16 Imported by: 96

README ΒΆ

MeiliSearch-Go

MeiliSearch Go

MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ

GitHub Workflow Status Test License Bors enabled

⚑ The MeiliSearch API client written for Golang

MeiliSearch Go is the MeiliSearch API client for Go developers.

MeiliSearch is an open-source search engine. Discover what MeiliSearch is!

Table of Contents

πŸ“– Documentation

See our Documentation or our API References.

πŸ”§ Installation

With go get in command line:

go get github.com/meilisearch/meilisearch-go

Run MeiliSearch

There are many easy ways to download and run a MeiliSearch instance.

For example, if you use Docker:

docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

πŸš€ Getting Started

Add documents
package main

import (
	"fmt"
	"os"

	"github.com/meilisearch/meilisearch-go"
)

func main() {
	client := meilisearch.NewClient(meilisearch.ClientConfig{
                Host: "http://127.0.0.1:7700",
                APIKey: "masterKey",
        })
	// An index is where the documents are stored.
	index := client.Index("indexUID")

	// If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
	documents := []map[string]interface{}{
		{"book_id": 123,  "title": "Pride and Prejudice"},
		{"book_id": 456,  "title": "Le Petit Prince"},
		{"book_id": 1,    "title": "Alice In Wonderland"},
		{"book_id": 1344, "title": "The Hobbit"},
		{"book_id": 4,    "title": "Harry Potter and the Half-Blood Prince"},
		{"book_id": 42,   "title": "The Hitchhiker's Guide to the Galaxy"},
	}
	update, err := index.AddDocuments(documents)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(update.UpdateID)
}

With the updateId, you can check the status (enqueued, processed or failed) of your documents addition using the update endpoint.

package main

import (
    "fmt"
    "os"

    "github.com/meilisearch/meilisearch-go"
)

func main() {
    // MeiliSearch is typo-tolerant:
    searchRes, err := client.Index("books").Search("harry pottre",
        &meilisearch.SearchRequest{
            Limit: 10,
        })
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(searchRes.Hits)
}

JSON output:

{
  "hits": [{
    "book_id": 4,
    "title": "Harry Potter and the Half-Blood Prince"
  }],
  "offset": 0,
  "limit": 10,
  "processingTimeMs": 1,
  "query": "harry pottre"
}

All the supported options are described in the search parameters section of the documentation.

func main() {
    searchRes, err := client.Index("books").Search("prince",
        &meilisearch.SearchRequest{
            AttributesToHighlight: []string{"*"},
            Filters: "book_id > 10",
        })
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(searchRes.Hits)
}

JSON output:

{
    "hits": [
        {
            "book_id": 456,
            "title": "Le Petit Prince",
            "_formatted": {
                "book_id": 456,
                "title": "Le Petit <em>Prince</em>"
            }
        }
    ],
    "offset": 0,
    "limit": 1,
    "processingTimeMs": 0,
    "query": "prince"
}

πŸ€– Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.20.0 of MeiliSearch.

πŸ’‘ Learn More

The following sections may interest you:

βš™οΈ Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!


MeiliSearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	DefaultLimit int64 = 20
)

This constant contains the default values assigned by meilisearch to the limit in search parameters

Documentation: https://docs.meilisearch.com/reference/features/search_parameters.html

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type AsyncUpdateID ΒΆ added in v0.9.0

type AsyncUpdateID struct {
	UpdateID int64 `json:"updateId"`
}

AsyncUpdateID is returned for asynchronous method

Documentation: https://docs.meilisearch.com/learn/advanced/asynchronous_updates.html

func (AsyncUpdateID) MarshalEasyJSON ΒΆ added in v0.13.1

func (v AsyncUpdateID) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AsyncUpdateID) MarshalJSON ΒΆ added in v0.13.1

func (v AsyncUpdateID) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AsyncUpdateID) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *AsyncUpdateID) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AsyncUpdateID) UnmarshalJSON ΒΆ added in v0.13.1

func (v *AsyncUpdateID) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Client ΒΆ

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

Client is a structure that give you the power for interacting with an high-level api with meilisearch.

func NewClient ΒΆ

func NewClient(config ClientConfig) *Client

NewClient creates Meilisearch with default fasthttp.Client

func NewFastHTTPCustomClient ΒΆ added in v0.13.1

func NewFastHTTPCustomClient(config ClientConfig, client *fasthttp.Client) *Client

NewFastHTTPCustomClient creates Meilisearch with custom fasthttp.Client

func (*Client) CreateDump ΒΆ added in v0.15.0

func (c *Client) CreateDump() (resp *Dump, err error)

func (*Client) CreateIndex ΒΆ added in v0.15.0

func (c *Client) CreateIndex(config *IndexConfig) (resp *Index, err error)

func (*Client) DeleteIndex ΒΆ added in v0.15.0

func (c *Client) DeleteIndex(uid string) (ok bool, err error)

func (*Client) GetAllIndexes ΒΆ added in v0.15.0

func (c *Client) GetAllIndexes() (resp []*Index, err error)

func (*Client) GetAllStats ΒΆ added in v0.15.0

func (c *Client) GetAllStats() (resp *Stats, err error)

func (*Client) GetDumpStatus ΒΆ added in v0.15.0

func (c *Client) GetDumpStatus(dumpUID string) (resp *Dump, err error)

func (*Client) GetIndex ΒΆ added in v0.15.0

func (c *Client) GetIndex(uid string) (resp *Index, err error)

func (*Client) GetKeys ΒΆ added in v0.15.0

func (c *Client) GetKeys() (resp *Keys, err error)

func (*Client) GetOrCreateIndex ΒΆ added in v0.15.0

func (c *Client) GetOrCreateIndex(config *IndexConfig) (resp *Index, err error)

func (*Client) GetVersion ΒΆ added in v0.15.0

func (c *Client) GetVersion() (resp *Version, err error)

func (*Client) Health ΒΆ

func (c *Client) Health() (resp *Health, err error)

func (*Client) Index ΒΆ added in v0.15.0

func (c *Client) Index(uid string) *Index

func (*Client) IsHealthy ΒΆ added in v0.15.0

func (c *Client) IsHealthy() bool

func (Client) MarshalEasyJSON ΒΆ added in v0.15.0

func (v Client) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Client) MarshalJSON ΒΆ added in v0.15.0

func (v Client) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Client) UnmarshalEasyJSON ΒΆ added in v0.15.0

func (v *Client) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Client) UnmarshalJSON ΒΆ added in v0.15.0

func (v *Client) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (*Client) Version ΒΆ

func (c *Client) Version() (resp *Version, err error)

type ClientConfig ΒΆ added in v0.15.0

type ClientConfig struct {

	// Host is the host of your meilisearch database
	// Example: 'http://localhost:7700'
	Host string

	// APIKey is optional
	APIKey string

	// Timeout is optional
	Timeout time.Duration
}

ClientConfig configure the Client

type ClientInterface ΒΆ added in v0.13.1

type ClientInterface interface {
	Index(uid string) *Index
	GetIndex(indexID string) (resp *Index, err error)
	GetAllIndexes() (resp []*Index, err error)
	CreateIndex(config *IndexConfig) (resp *Index, err error)
	GetOrCreateIndex(config *IndexConfig) (resp *Index, err error)
	DeleteIndex(uid string) (bool, error)
	GetKeys() (resp *Keys, err error)
	GetAllStats() (resp *Stats, err error)
	CreateDump() (resp *Dump, err error)
	GetDumpStatus(dumpUID string) (resp *Dump, err error)
	Version() (*Version, error)
	GetVersion() (resp *Version, err error)
	Health() (*Health, error)
	IsHealthy() bool
}

ClientInterface is interface for all Meilisearch client

type CreateIndexRequest ΒΆ

type CreateIndexRequest struct {
	UID        string `json:"uid,omitempty"`
	PrimaryKey string `json:"primaryKey,omitempty"`
}

CreateIndexRequest is the request body for create index method

func (CreateIndexRequest) MarshalEasyJSON ΒΆ added in v0.13.1

func (v CreateIndexRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CreateIndexRequest) MarshalJSON ΒΆ added in v0.13.1

func (v CreateIndexRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CreateIndexRequest) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *CreateIndexRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CreateIndexRequest) UnmarshalJSON ΒΆ added in v0.13.1

func (v *CreateIndexRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type DocumentsRequest ΒΆ added in v0.15.0

type DocumentsRequest struct {
	Offset               int64    `json:"offset,omitempty"`
	Limit                int64    `json:"limit,omitempty"`
	AttributesToRetrieve []string `json:"attributesToRetrieve,omitempty"`
}

DocumentsRequest is the request body for list documents method

func (DocumentsRequest) MarshalEasyJSON ΒΆ added in v0.15.0

func (v DocumentsRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (DocumentsRequest) MarshalJSON ΒΆ added in v0.15.0

func (v DocumentsRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*DocumentsRequest) UnmarshalEasyJSON ΒΆ added in v0.15.0

func (v *DocumentsRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*DocumentsRequest) UnmarshalJSON ΒΆ added in v0.15.0

func (v *DocumentsRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Dump ΒΆ added in v0.14.1

type Dump struct {
	UID    string `json:"uid"`
	Status string `json:"status"`
}

Dump indicate information about an dump

Documentation: https://docs.meilisearch.com/reference/api/dump.html

func (Dump) MarshalEasyJSON ΒΆ added in v0.14.1

func (v Dump) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Dump) MarshalJSON ΒΆ added in v0.14.1

func (v Dump) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Dump) UnmarshalEasyJSON ΒΆ added in v0.14.1

func (v *Dump) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Dump) UnmarshalJSON ΒΆ added in v0.14.1

func (v *Dump) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ErrCode ΒΆ

type ErrCode int

ErrCode are all possible errors found during requests

const (
	// ErrCodeUnknown default error code, undefined
	ErrCodeUnknown ErrCode = 0
	// ErrCodeMarshalRequest impossible to serialize request body
	ErrCodeMarshalRequest ErrCode = iota + 1
	// ErrCodeResponseUnmarshalBody impossible deserialize the response body
	ErrCodeResponseUnmarshalBody
	// MeilisearchApiError send by the Meilisearch api
	MeilisearchApiError
	// MeilisearchApiError send by the Meilisearch api
	MeilisearchApiErrorWithoutMessage
	// MeilisearchTimeoutError
	MeilisearchTimeoutError
	// MeilisearchCommunicationError impossible execute a request
	MeilisearchCommunicationError
)

type Error ΒΆ

type Error struct {
	// Endpoint is the path of the request (host is not in)
	Endpoint string

	// Method is the HTTP verb of the request
	Method string

	// Function name used
	Function string

	// RequestToString is the raw request into string ('empty request' if not present)
	RequestToString string

	// RequestToString is the raw request into string ('empty response' if not present)
	ResponseToString string

	// Error info from Meilisearch api
	// Message is the raw request into string ('empty meilisearch message' if not present)
	MeilisearchApiMessage meilisearchApiMessage

	// StatusCode of the request
	StatusCode int

	// StatusCode expected by the endpoint to be considered as a success
	StatusCodeExpected []int

	// OriginError is the origin error that produce the current Error. It can be nil in case of a bad status code.
	OriginError error

	// ErrCode is the internal error code that represent the different step when executing a request that can produce
	// an error.
	ErrCode ErrCode
	// contains filtered or unexported fields
}

Error is the internal error structure that all exposed method use. So ALL errors returned by this library can be cast to this struct (as a pointer)

func (Error) Error ΒΆ

func (e Error) Error() string

Error return a well human formatted message.

func (*Error) ErrorBody ΒΆ

func (e *Error) ErrorBody(body []byte)

ErrorBody add a body to an error

func (*Error) WithErrCode ΒΆ

func (e *Error) WithErrCode(err ErrCode, errs ...error) *Error

WithErrCode add an error code to an error

type Health ΒΆ added in v0.13.1

type Health struct {
	Status string `json:"status"`
}

Health is the request body for set Meilisearch health

func (Health) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Health) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Health) MarshalJSON ΒΆ added in v0.13.1

func (v Health) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Health) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Health) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Health) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Health) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Index ΒΆ

type Index struct {
	UID        string    `json:"uid"`
	CreatedAt  time.Time `json:"createdAt"`
	UpdatedAt  time.Time `json:"updatedAt"`
	PrimaryKey string    `json:"primaryKey,omitempty"`
	// contains filtered or unexported fields
}

Index is the type that represent an index in MeiliSearch

func (Index) AddDocuments ΒΆ added in v0.15.0

func (i Index) AddDocuments(documentsPtr interface{}) (resp *AsyncUpdateID, err error)

func (Index) AddDocumentsWithPrimaryKey ΒΆ added in v0.15.0

func (i Index) AddDocumentsWithPrimaryKey(documentsPtr interface{}, primaryKey string) (resp *AsyncUpdateID, err error)

func (Index) DefaultWaitForPendingUpdate ΒΆ added in v0.15.0

func (i Index) DefaultWaitForPendingUpdate(updateID *AsyncUpdateID) (UpdateStatus, error)

DefaultWaitForPendingUpdate checks each 50ms the status of a WaitForPendingUpdate. This is a default implementation of WaitForPendingUpdate.

func (Index) Delete ΒΆ added in v0.15.0

func (i Index) Delete(uid string) (ok bool, err error)

func (Index) DeleteAllDocuments ΒΆ added in v0.15.0

func (i Index) DeleteAllDocuments() (resp *AsyncUpdateID, err error)

func (Index) DeleteDocument ΒΆ added in v0.15.0

func (i Index) DeleteDocument(identifier string) (resp *AsyncUpdateID, err error)

func (Index) DeleteDocuments ΒΆ added in v0.15.0

func (i Index) DeleteDocuments(identifier []string) (resp *AsyncUpdateID, err error)

func (Index) FetchInfo ΒΆ added in v0.15.0

func (i Index) FetchInfo() (resp *Index, err error)

func (Index) FetchPrimaryKey ΒΆ added in v0.15.0

func (i Index) FetchPrimaryKey() (resp *string, err error)

func (Index) GetAllUpdateStatus ΒΆ added in v0.15.0

func (i Index) GetAllUpdateStatus() (resp *[]Update, err error)

func (Index) GetAttributesForFaceting ΒΆ added in v0.15.0

func (i Index) GetAttributesForFaceting() (resp *[]string, err error)

func (Index) GetDisplayedAttributes ΒΆ added in v0.15.0

func (i Index) GetDisplayedAttributes() (resp *[]string, err error)

func (Index) GetDistinctAttribute ΒΆ added in v0.15.0

func (i Index) GetDistinctAttribute() (resp *string, err error)

func (Index) GetDocument ΒΆ added in v0.15.0

func (i Index) GetDocument(identifier string, documentPtr interface{}) error

func (Index) GetDocuments ΒΆ added in v0.15.0

func (i Index) GetDocuments(request *DocumentsRequest, resp interface{}) error

func (Index) GetRankingRules ΒΆ added in v0.15.0

func (i Index) GetRankingRules() (resp *[]string, err error)

func (Index) GetSearchableAttributes ΒΆ added in v0.15.0

func (i Index) GetSearchableAttributes() (resp *[]string, err error)

func (Index) GetSettings ΒΆ added in v0.15.0

func (i Index) GetSettings() (resp *Settings, err error)

func (Index) GetStats ΒΆ added in v0.15.0

func (i Index) GetStats() (resp *StatsIndex, err error)

func (Index) GetStopWords ΒΆ added in v0.15.0

func (i Index) GetStopWords() (resp *[]string, err error)

func (Index) GetSynonyms ΒΆ added in v0.15.0

func (i Index) GetSynonyms() (resp *map[string][]string, err error)

func (Index) GetUpdateStatus ΒΆ added in v0.15.0

func (i Index) GetUpdateStatus(updateID int64) (resp *Update, err error)

func (Index) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Index) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Index) MarshalJSON ΒΆ added in v0.13.1

func (v Index) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (Index) ResetAttributesForFaceting ΒΆ added in v0.15.0

func (i Index) ResetAttributesForFaceting() (resp *AsyncUpdateID, err error)

func (Index) ResetDisplayedAttributes ΒΆ added in v0.15.0

func (i Index) ResetDisplayedAttributes() (resp *AsyncUpdateID, err error)

func (Index) ResetDistinctAttribute ΒΆ added in v0.15.0

func (i Index) ResetDistinctAttribute() (resp *AsyncUpdateID, err error)

func (Index) ResetRankingRules ΒΆ added in v0.15.0

func (i Index) ResetRankingRules() (resp *AsyncUpdateID, err error)

func (Index) ResetSearchableAttributes ΒΆ added in v0.15.0

func (i Index) ResetSearchableAttributes() (resp *AsyncUpdateID, err error)

func (Index) ResetSettings ΒΆ added in v0.15.0

func (i Index) ResetSettings() (resp *AsyncUpdateID, err error)

func (Index) ResetStopWords ΒΆ added in v0.15.0

func (i Index) ResetStopWords() (resp *AsyncUpdateID, err error)

func (Index) ResetSynonyms ΒΆ added in v0.15.0

func (i Index) ResetSynonyms() (resp *AsyncUpdateID, err error)

func (Index) Search ΒΆ added in v0.15.0

func (i Index) Search(query string, request *SearchRequest) (*SearchResponse, error)

func (*Index) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Index) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Index) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Index) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (Index) UpdateAttributesForFaceting ΒΆ added in v0.15.0

func (i Index) UpdateAttributesForFaceting(request *[]string) (resp *AsyncUpdateID, err error)

func (Index) UpdateDisplayedAttributes ΒΆ added in v0.15.0

func (i Index) UpdateDisplayedAttributes(request *[]string) (resp *AsyncUpdateID, err error)

func (Index) UpdateDistinctAttribute ΒΆ added in v0.15.0

func (i Index) UpdateDistinctAttribute(request string) (resp *AsyncUpdateID, err error)

func (Index) UpdateDocuments ΒΆ added in v0.15.0

func (i Index) UpdateDocuments(documentsPtr interface{}) (*AsyncUpdateID, error)

func (Index) UpdateDocumentsWithPrimaryKey ΒΆ added in v0.15.0

func (i Index) UpdateDocumentsWithPrimaryKey(documentsPtr interface{}, primaryKey string) (resp *AsyncUpdateID, err error)

func (Index) UpdateIndex ΒΆ added in v0.15.0

func (i Index) UpdateIndex(primaryKey string) (resp *Index, err error)

func (Index) UpdateRankingRules ΒΆ added in v0.15.0

func (i Index) UpdateRankingRules(request *[]string) (resp *AsyncUpdateID, err error)

func (Index) UpdateSearchableAttributes ΒΆ added in v0.15.0

func (i Index) UpdateSearchableAttributes(request *[]string) (resp *AsyncUpdateID, err error)

func (Index) UpdateSettings ΒΆ added in v0.15.0

func (i Index) UpdateSettings(request *Settings) (resp *AsyncUpdateID, err error)

func (Index) UpdateStopWords ΒΆ added in v0.15.0

func (i Index) UpdateStopWords(request *[]string) (resp *AsyncUpdateID, err error)

func (Index) UpdateSynonyms ΒΆ added in v0.15.0

func (i Index) UpdateSynonyms(request *map[string][]string) (resp *AsyncUpdateID, err error)

func (Index) WaitForPendingUpdate ΒΆ added in v0.15.0

func (i Index) WaitForPendingUpdate(
	ctx context.Context,
	interval time.Duration,
	updateID *AsyncUpdateID) (UpdateStatus, error)

WaitForPendingUpdate waits for the end of an update. The function will check by regular interval provided in parameter interval the UpdateStatus. If it is not UpdateStatusEnqueued or the ctx cancelled we return the UpdateStatus.

type IndexConfig ΒΆ added in v0.15.0

type IndexConfig struct {

	// Host is the host of your meilisearch database
	// Example: 'http://localhost:7700'
	Uid string

	// PrimaryKey is optional
	PrimaryKey string
	// contains filtered or unexported fields
}

IndexConfig configure the Index

type IndexInterface ΒΆ added in v0.15.0

type IndexInterface interface {
	FetchInfo() (resp *Index, err error)
	FetchPrimaryKey() (resp *string, err error)
	UpdateIndex(primaryKey string) (resp *Index, err error)
	Delete(uid string) (ok bool, err error)
	GetStats() (resp *StatsIndex, err error)

	AddDocuments(documentsPtr interface{}) (resp *AsyncUpdateID, err error)
	UpdateDocuments(documentsPtr interface{}) (resp *AsyncUpdateID, err error)
	AddDocumentsWithPrimaryKey(documentsPtr interface{}, primaryKey string) (resp *AsyncUpdateID, err error)
	UpdateDocumentsWithPrimaryKey(documentsPtr interface{}, primaryKey string) (resp *AsyncUpdateID, err error)
	GetDocument(uid string, documentPtr interface{}) error
	GetDocuments(request *DocumentsRequest, resp interface{}) error
	DeleteDocument(uid string) (resp *AsyncUpdateID, err error)
	DeleteDocuments(uid []string) (resp *AsyncUpdateID, err error)
	DeleteAllDocuments() (resp *AsyncUpdateID, err error)
	Search(query string, request *SearchRequest) (*SearchResponse, error)

	GetUpdateStatus(updateID int64) (resp *Update, err error)
	GetAllUpdateStatus() (resp *[]Update, err error)

	GetSettings() (resp *Settings, err error)
	UpdateSettings(request *Settings) (resp *AsyncUpdateID, err error)
	ResetSettings() (resp *AsyncUpdateID, err error)
	GetRankingRules() (resp *[]string, err error)
	UpdateRankingRules(request *[]string) (resp *AsyncUpdateID, err error)
	ResetRankingRules() (resp *AsyncUpdateID, err error)
	GetDistinctAttribute() (resp *string, err error)
	UpdateDistinctAttribute(request string) (resp *AsyncUpdateID, err error)
	ResetDistinctAttribute() (resp *AsyncUpdateID, err error)
	GetSearchableAttributes() (resp *[]string, err error)
	UpdateSearchableAttributes(request *[]string) (resp *AsyncUpdateID, err error)
	ResetSearchableAttributes() (resp *AsyncUpdateID, err error)
	GetDisplayedAttributes() (resp *[]string, err error)
	UpdateDisplayedAttributes(request *[]string) (resp *AsyncUpdateID, err error)
	ResetDisplayedAttributes() (resp *AsyncUpdateID, err error)
	GetStopWords() (resp *[]string, err error)
	UpdateStopWords(request *[]string) (resp *AsyncUpdateID, err error)
	ResetStopWords() (resp *AsyncUpdateID, err error)
	GetSynonyms() (resp *map[string][]string, err error)
	UpdateSynonyms(request *map[string][]string) (resp *AsyncUpdateID, err error)
	ResetSynonyms() (resp *AsyncUpdateID, err error)
	GetAttributesForFaceting() (resp *[]string, err error)
	UpdateAttributesForFaceting(request *[]string) (resp *AsyncUpdateID, err error)
	ResetAttributesForFaceting() (resp *AsyncUpdateID, err error)

	WaitForPendingUpdate(ctx context.Context, interval time.Duration, updateID *AsyncUpdateID) (UpdateStatus, error)
	DefaultWaitForPendingUpdate(updateID *AsyncUpdateID) (UpdateStatus, error)
}

type Keys ΒΆ added in v0.9.0

type Keys struct {
	Public  string `json:"public,omitempty"`
	Private string `json:"private,omitempty"`
}

Keys allow the user to connect to the MeiliSearch instance

Documentation: https://docs.meilisearch.com/learn/advanced/asynchronous_updates.html

func (Keys) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Keys) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Keys) MarshalJSON ΒΆ added in v0.13.1

func (v Keys) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Keys) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Keys) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Keys) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Keys) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type RawType ΒΆ added in v0.13.1

type RawType []byte

RawType is an alias for raw byte[]

func (RawType) MarshalJSON ΒΆ added in v0.13.1

func (b RawType) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*RawType) UnmarshalJSON ΒΆ added in v0.13.1

func (b *RawType) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type SearchRequest ΒΆ

type SearchRequest struct {
	Offset                int64
	Limit                 int64
	AttributesToRetrieve  []string
	AttributesToCrop      []string
	CropLength            int64
	AttributesToHighlight []string
	Filters               string
	Matches               bool
	FacetsDistribution    []string
	FacetFilters          interface{}
	PlaceholderSearch     bool
}

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

Documentation: https://docs.meilisearch.com/reference/features/search_parameters.html

func (SearchRequest) MarshalEasyJSON ΒΆ added in v0.13.1

func (v SearchRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (SearchRequest) MarshalJSON ΒΆ added in v0.13.1

func (v SearchRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*SearchRequest) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *SearchRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*SearchRequest) UnmarshalJSON ΒΆ added in v0.13.1

func (v *SearchRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type SearchResponse ΒΆ

type SearchResponse struct {
	Hits                  []interface{} `json:"hits"`
	NbHits                int64         `json:"nbHits"`
	Offset                int64         `json:"offset"`
	Limit                 int64         `json:"limit"`
	ExhaustiveNbHits      bool          `json:"exhaustiveNbHits"`
	ProcessingTimeMs      int64         `json:"processingTimeMs"`
	Query                 string        `json:"query"`
	FacetsDistribution    interface{}   `json:"facetsDistribution,omitempty"`
	ExhaustiveFacetsCount interface{}   `json:"exhaustiveFacetsCount,omitempty"`
}

SearchResponse is the response body for search method

func (SearchResponse) MarshalEasyJSON ΒΆ added in v0.13.1

func (v SearchResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (SearchResponse) MarshalJSON ΒΆ added in v0.13.1

func (v SearchResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*SearchResponse) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *SearchResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*SearchResponse) UnmarshalJSON ΒΆ added in v0.13.1

func (v *SearchResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Settings ΒΆ

type Settings struct {
	RankingRules          []string            `json:"rankingRules,omitempty"`
	DistinctAttribute     *string             `json:"distinctAttribute,omitempty"`
	SearchableAttributes  []string            `json:"searchableAttributes,omitempty"`
	DisplayedAttributes   []string            `json:"displayedAttributes,omitempty"`
	StopWords             []string            `json:"stopWords,omitempty"`
	Synonyms              map[string][]string `json:"synonyms,omitempty"`
	AttributesForFaceting []string            `json:"attributesForFaceting,omitempty"`
}

Settings is the type that represents the settings in MeiliSearch

func (Settings) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Settings) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Settings) MarshalJSON ΒΆ added in v0.13.1

func (v Settings) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Settings) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Settings) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Settings) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Settings) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Stats ΒΆ

type Stats struct {
	DatabaseSize int64                 `json:"database_size"`
	LastUpdate   time.Time             `json:"last_update"`
	Indexes      map[string]StatsIndex `json:"indexes"`
}

Stats is the type that represent all stats

func (Stats) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Stats) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Stats) MarshalJSON ΒΆ added in v0.13.1

func (v Stats) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Stats) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Stats) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Stats) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Stats) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type StatsIndex ΒΆ added in v0.9.1

type StatsIndex struct {
	NumberOfDocuments int64            `json:"numberOfDocuments"`
	IsIndexing        bool             `json:"isIndexing"`
	FieldsFrequency   map[string]int64 `json:"fieldsFrequency"`
}

StatsIndex is the type that represent the stats of an index in MeiliSearch

func (StatsIndex) MarshalEasyJSON ΒΆ added in v0.13.1

func (v StatsIndex) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (StatsIndex) MarshalJSON ΒΆ added in v0.13.1

func (v StatsIndex) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*StatsIndex) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *StatsIndex) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*StatsIndex) UnmarshalJSON ΒΆ added in v0.13.1

func (v *StatsIndex) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Unknown ΒΆ

type Unknown map[string]interface{}

Unknown is unknown json type

type Update ΒΆ

type Update struct {
	Status      UpdateStatus `json:"status"`
	UpdateID    int64        `json:"updateId"`
	Type        Unknown      `json:"type"`
	Error       string       `json:"error"`
	EnqueuedAt  time.Time    `json:"enqueuedAt"`
	ProcessedAt time.Time    `json:"processedAt"`
}

Update indicate information about an update

func (Update) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Update) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Update) MarshalJSON ΒΆ added in v0.13.1

func (v Update) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Update) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Update) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Update) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Update) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type UpdateIndexRequest ΒΆ added in v0.15.0

type UpdateIndexRequest struct {
	PrimaryKey string `json:"primaryKey"`
}

UpdateIndexRequest is the request body for update Index primary key

func (UpdateIndexRequest) MarshalEasyJSON ΒΆ added in v0.15.0

func (v UpdateIndexRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (UpdateIndexRequest) MarshalJSON ΒΆ added in v0.15.0

func (v UpdateIndexRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*UpdateIndexRequest) UnmarshalEasyJSON ΒΆ added in v0.15.0

func (v *UpdateIndexRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*UpdateIndexRequest) UnmarshalJSON ΒΆ added in v0.15.0

func (v *UpdateIndexRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type UpdateStatus ΒΆ

type UpdateStatus string

UpdateStatus is the status of an update.

const (
	// UpdateStatusUnknown is the default UpdateStatus, should not exist
	UpdateStatusUnknown UpdateStatus = "unknown"
	// UpdateStatusEnqueued means the server know the update but didn't handle it yet
	UpdateStatusEnqueued UpdateStatus = "enqueued"
	// UpdateStatusProcessed means the server has processed the update and all went well
	UpdateStatusProcessed UpdateStatus = "processed"
	// UpdateStatusFailed means the server has processed the update and an error has been reported
	UpdateStatusFailed UpdateStatus = "failed"
)

type Version ΒΆ

type Version struct {
	CommitSha  string    `json:"commitSha"`
	BuildDate  time.Time `json:"buildDate"`
	PkgVersion string    `json:"pkgVersion"`
}

Version is the type that represents the versions in MeiliSearch

func (Version) MarshalEasyJSON ΒΆ added in v0.13.1

func (v Version) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Version) MarshalJSON ΒΆ added in v0.13.1

func (v Version) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Version) UnmarshalEasyJSON ΒΆ added in v0.13.1

func (v *Version) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Version) UnmarshalJSON ΒΆ added in v0.13.1

func (v *Version) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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