msearch

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexAttributeItem

type IndexAttributeItem struct {
	SearchableFields []string `json:"searchable_fields"`
	FilterableFields []string `json:"filterable_fields"`
	SortableFields   []string `json:"sortable_fields"`
	DisplayedFields  []string `json:"displayed_fields"`
}

type IndexConfigs

type IndexConfigs struct {
	ConfigData *configDataMap `json:"config_data"`
}

type Logger

type Logger interface {
	Debug(args ...any)
	Info(args ...any)
	Warn(args ...any)
	Error(args ...any)
	Panic(args ...any)

	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Panicf(format string, args ...any)
}

type MSearch

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

func NewMSearch

func NewMSearch(hostUrl string, key string, logger ...Logger) *MSearch

func (*MSearch) AddDoc

func (ms *MSearch) AddDoc(indexName string, docPtr any) error

AddDoc is a method that adds a document to the index specified by indexName. The docPtr parameter must be a pointer, otherwise an error will be returned. The method first checks if the docPtr is a pointer using reflection. If the check fails, an error is returned. Otherwise, the method calls the AddDocuments function on the corresponding index through the Meilisearch client. If there's an error during the AddDocuments call, the error is returned. Finally, the method calls WaitForTaskSuccess to wait for the task to complete, using the TaskUID from the response of the AddDocuments call. If the wait is successful, the method returns nil.

Note: This method depends on the MSearch.WaitForTaskSuccess method for waiting for the task to complete. Please refer to the documentation of that method for more details.

func (*MSearch) ApplyIndexConfigs

func (ms *MSearch) ApplyIndexConfigs(configData []byte) error

func (*MSearch) DelDoc

func (ms *MSearch) DelDoc(indexName string, docId string) error

DelDoc is a method that deletes a document with the specified docId from the index with the specified indexName. It makes a call to the MeiliSearch Index DeleteDocument() method using the client. It returns an error if an error occurs while deleting the document, otherwise it waits for the delete task to complete using the WaitForTaskSuccess() method and returns any error that occurs during waiting. The WaitForTaskSuccess() method waits for a task with a specified taskUID to complete. It polls for the status of the task every 50 milliseconds, increasing the wait time for the next check by doubling it, up to a maximum delay of 1 second. This is done to limit the number of calls to the GetTask function when the task takes a significant amount of time to complete.

func (*MSearch) DeleteAllDocuments added in v0.2.0

func (ms *MSearch) DeleteAllDocuments(indexName string) error

DeleteAllDocuments is a method that deletes all documents in the specified index.

func (*MSearch) GetDoc

func (ms *MSearch) GetDoc(indexName string, docId string, bindResult any) (bool, error)

func (*MSearch) Search

func (ms *MSearch) Search(indexName string, query string, options *meilisearch.SearchRequest) *meilisearch.SearchResponse

Search is a method that performs a search query on the specified index with the given query and options. It returns a *meilisearch.SearchResponse containing the search results. If there's an error occurring while performing the search query, it will log the error and return nil.

func (*MSearch) UpdateDoc

func (ms *MSearch) UpdateDoc(indexName string, docPtr any) error

UpdateDoc is a method that updates a document in the specified index with the given data. It first checks if the docPtr is a pointer and returns an error if it is not. It then calls the UpdateDocuments function of the client's Index with the docPtr. If there's an error during the update process, it returns the error. Finally, it calls WaitForTaskSuccess with the TaskUID from the response, to wait for the update task to complete.underlying concrete type

func (*MSearch) WaitForTaskSuccess

func (ms *MSearch) WaitForTaskSuccess(taskUID int64) error

WaitForTaskSuccess is a method that waits for a task with a specified taskUID to complete. It will return an error either if there's an error occurring while getting the task detail from the client or when the context deadline is exceeded (after 20 seconds).

This function starts by polling for the status of the task every 50 milliseconds, and every time the task status is retrieved, the wait time for the next check is doubled, up to a maximum delay of 1 second. This is done to limit the number of calls to the GetTask function, especially in cases where the task takes a significant amount of time to complete.

type SortOrder

type SortOrder int
const (
	ASC  SortOrder = 1
	DESC SortOrder = -1
)

Jump to

Keyboard shortcuts

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