clients.meilisearch #
Meilisearch V Client
This is a simple V client for interacting with a self-hosted Meilisearch instance, enabling you to perform operations such as adding, retrieving, deleting, and searching documents within indexes.
Getting Started with Self-Hosted Meilisearch
To use this V client, ensure you have a self-hosted Meilisearch instance installed and running.
This quick start will walk you through installing Meilisearch, adding documents, and performing your first search.
Requirements
To follow this setup, you will need curl
installed
Setup and Installation
To install Meilisearch locally, run the following command:
##curl -L https://install.meilisearch.com | sh
Running Meilisearch
Start Meilisearch with the following command, replacing "aSampleMasterKey"
with your preferred master key:
##meilisearch --master-key='aSampleMasterKey'
Running the V Client Tests
This client includes various test cases that demonstrate common operations in Meilisearch, such as creating indexes, adding documents, retrieving documents, deleting documents, and performing searches. To run the tests, you can use the following commands:
##v -enable-globals -stats crystallib/clients/meilisearch/document_test.v
##v -enable-globals -stats crystallib/clients/meilisearch/index_test.v
Example: Getting Meilisearch Server Version
Here is a quick example of how to retrieve the Meilisearch server version using this V client:
import freeflowuniverse.crystallib.clients.meilisearch
mut client := meilisearch.get() or { panic(err) }
version := client.version() or { panic(err) }
println('Meilisearch version: $version')
This example connects to your local Meilisearch instance and prints the server version to verify your setup is correct.
Constants #
const version = '1.0.0'
fn get #
fn get(args_ ArgsGet) !&MeilisearchClient
fn heroscript_default #
fn heroscript_default() !string
Todo: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT
fn play #
fn play(args_ PlayArgs) !
fn switch #
fn switch(name string)
switch instance to be used for meilisearch
struct ArgsGet #
struct ArgsGet {
pub mut:
name string = 'default'
}
///////FACTORY
struct ClientConfig #
struct ClientConfig {
pub:
host string // Base URL of Meilisearch server (e.g., "http://localhost:7700")
api_key string // Master key or API key for authentication
timeout int = 30 // Request timeout in seconds
max_retry int = 3 // Maximum number of retries for failed requests
}
ClientConfig holds configuration for MeilisearchClient
struct CreateIndexArgs #
struct CreateIndexArgs {
pub mut:
uid string
primary_key string @[json: 'primaryKey']
}
CreateIndexArgs represents the arguments for creating an index
struct CreateIndexResponse #
struct CreateIndexResponse {
pub mut:
uid int @[json: 'taskUid']
index_uid string @[json: 'indexUid']
status string @[json: 'status']
type_ string @[json: 'type']
enqueued_at string @[json: 'enqueuedAt']
}
IndexCreation represents information about the index creation
struct DeleteIndexResponse #
struct DeleteIndexResponse {
pub mut:
uid int @[json: 'taskUid']
index_uid string @[json: 'indexUid']
status string @[json: 'status']
type_ string @[json: 'type']
enqueued_at string @[json: 'enqueuedAt']
}
DeleteIndexResponse represents information about the index deletion
struct DocumentsQuery #
struct DocumentsQuery {
pub mut:
limit int = 20
offset int
fields []string
filter string
sort []string
}
DocumentsQuery represents query parameters for document operations
struct EperimentalFeaturesArgs #
struct EperimentalFeaturesArgs {
pub mut:
vector_store bool @[json: 'vectorStore']
metrics bool @[json: 'metrics']
logs_route bool @[json: 'logsRoute']
contains_filter bool @[json: 'containsFilter']
edit_documents_by_function bool @[json: 'editDocumentsByFunction']
}
struct GetIndexResponse #
struct GetIndexResponse {
pub mut:
uid string @[json: 'uid']
created_at string @[json: 'createdAt']
updated_at string @[json: 'updatedAt']
primary_key string @[json: 'primaryKey']
}
IndexCreation represents information about the index creation
struct Health #
struct Health {
pub:
status string @[json: 'status']
}
Health represents the health status of the Meilisearch server
struct IndexSettings #
struct IndexSettings {
pub mut:
ranking_rules []string @[json: 'rankingRules']
distinct_attribute string @[json: 'distinctAttribute']
searchable_attributes []string @[json: 'searchableAttributes']
displayed_attributes []string @[json: 'displayedAttributes']
stop_words []string @[json: 'stopWords']
synonyms map[string][]string @[json: 'synonyms']
filterable_attributes []string @[json: 'filterableAttributes']
sortable_attributes []string @[json: 'sortableAttributes']
typo_tolerance TypoTolerance @[json: 'typoTolerance']
}
IndexSettings represents all configurable settings for an index
struct ListIndexArgs #
struct ListIndexArgs {
pub mut:
limit int = 20
offset int
}
ListIndexArgs represents the arguments for listing indexes
struct ListResponse #
struct ListResponse[T] {
pub mut:
results []T
total int
offset int
limit int
}
ListIndexResponse represents information about the index list
struct MeilisearchClient #
struct MeilisearchClient {
pub mut:
name string = 'default'
api_key string @[secret]
host string
}
THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
fn (MeilisearchClient) add_documents #
fn (mut client MeilisearchClient) add_documents[T](uid string, documents []T) !AddDocumentResponse
add_documents adds documents to an index
fn (MeilisearchClient) create_index #
fn (mut client MeilisearchClient) create_index(args CreateIndexArgs) !CreateIndexResponse
create_index creates a new index with the given UID
fn (MeilisearchClient) delete_all_documents #
fn (mut client MeilisearchClient) delete_all_documents(uid string) !DeleteDocumentResponse
delete_all_documents deletes all documents in an index
fn (MeilisearchClient) delete_document #
fn (mut client MeilisearchClient) delete_document(args DeleteDocumentArgs) !DeleteDocumentResponse
delete_document deletes one document by its id
fn (MeilisearchClient) delete_index #
fn (mut client MeilisearchClient) delete_index(uid string) !DeleteIndexResponse
delete_index deletes an index
fn (MeilisearchClient) enable_eperimental_feature #
fn (mut client MeilisearchClient) enable_eperimental_feature(args EperimentalFeaturesArgs) !EperimentalFeaturesArgs
fn (MeilisearchClient) facet_search #
fn (mut client MeilisearchClient) facet_search(uid string, args FacetSearchArgs) !FacetSearchResponse
fn (MeilisearchClient) get_displayed_attributes #
fn (mut client MeilisearchClient) get_displayed_attributes(uid string) ![]string
get_displayed_attributes retrieves displayed attributes of an index
fn (MeilisearchClient) get_distinct_attribute #
fn (mut client MeilisearchClient) get_distinct_attribute(uid string) !string
get_distinct_attribute retrieves distinct attribute of an index
fn (MeilisearchClient) get_document #
fn (mut client MeilisearchClient) get_document[T](args GetDocumentArgs) !T
get_document retrieves one document by its id
fn (MeilisearchClient) get_documents #
fn (mut client MeilisearchClient) get_documents[T](uid string, query DocumentsQuery) ![]T
get_documents retrieves documents with optional parameters
fn (MeilisearchClient) get_filterable_attributes #
fn (mut client MeilisearchClient) get_filterable_attributes(uid string) ![]string
get_filterable_attributes retrieves filterable attributes of an index
fn (MeilisearchClient) get_index #
fn (mut client MeilisearchClient) get_index(uid string) !GetIndexResponse
get_index retrieves information about an index
fn (MeilisearchClient) get_ranking_rules #
fn (mut client MeilisearchClient) get_ranking_rules(uid string) ![]string
get_ranking_rules retrieves ranking rules of an index
fn (MeilisearchClient) get_searchable_attributes #
fn (mut client MeilisearchClient) get_searchable_attributes(uid string) ![]string
get_searchable_attributes retrieves searchable attributes of an index
fn (MeilisearchClient) get_settings #
fn (mut client MeilisearchClient) get_settings(uid string) !IndexSettings
get_settings retrieves all settings of an index
fn (MeilisearchClient) get_sortable_attributes #
fn (mut client MeilisearchClient) get_sortable_attributes(uid string) ![]string
get_sortable_attributes retrieves sortable attributes of an index
fn (MeilisearchClient) get_stop_words #
fn (mut client MeilisearchClient) get_stop_words(uid string) ![]string
get_stop_words retrieves stop words of an index
fn (MeilisearchClient) get_synonyms #
fn (mut client MeilisearchClient) get_synonyms(uid string) !map[string][]string
get_synonyms retrieves synonyms of an index
fn (MeilisearchClient) get_typo_tolerance #
fn (mut client MeilisearchClient) get_typo_tolerance(uid string) !TypoTolerance
get_typo_tolerance retrieves typo tolerance settings of an index
fn (MeilisearchClient) health #
fn (mut client MeilisearchClient) health() !Health
health checks if the server is healthy
fn (MeilisearchClient) list_indexes #
fn (mut client MeilisearchClient) list_indexes(args ListIndexArgs) ![]GetIndexResponse
list_indexes retrieves all indexes
fn (MeilisearchClient) reset_displayed_attributes #
fn (mut client MeilisearchClient) reset_displayed_attributes(uid string) !string
reset_displayed_attributes resets displayed attributes of an index
fn (MeilisearchClient) reset_distinct_attribute #
fn (mut client MeilisearchClient) reset_distinct_attribute(uid string) !string
reset_distinct_attribute resets distinct attribute of an index
fn (MeilisearchClient) reset_filterable_attributes #
fn (mut client MeilisearchClient) reset_filterable_attributes(uid string) !string
reset_filterable_attributes resets filterable attributes of an index
fn (MeilisearchClient) reset_ranking_rules #
fn (mut client MeilisearchClient) reset_ranking_rules(uid string) !string
reset_ranking_rules resets ranking rules of an index to default values
fn (MeilisearchClient) reset_searchable_attributes #
fn (mut client MeilisearchClient) reset_searchable_attributes(uid string) !string
reset_searchable_attributes resets searchable attributes of an index
fn (MeilisearchClient) reset_settings #
fn (mut client MeilisearchClient) reset_settings(uid string) !string
reset_settings resets all settings of an index to default values
fn (MeilisearchClient) reset_sortable_attributes #
fn (mut client MeilisearchClient) reset_sortable_attributes(uid string) !string
reset_sortable_attributes resets sortable attributes of an index
fn (MeilisearchClient) reset_stop_words #
fn (mut client MeilisearchClient) reset_stop_words(uid string) !string
reset_stop_words resets stop words of an index
fn (MeilisearchClient) reset_synonyms #
fn (mut client MeilisearchClient) reset_synonyms(uid string) !string
reset_synonyms resets synonyms of an index
fn (MeilisearchClient) reset_typo_tolerance #
fn (mut client MeilisearchClient) reset_typo_tolerance(uid string) !string
reset_typo_tolerance resets typo tolerance settings of an index
fn (MeilisearchClient) search #
fn (mut client MeilisearchClient) search[T](uid string, args SearchArgs) !SearchResponse[T]
search performs a search query on an index
fn (MeilisearchClient) similar_documents #
fn (mut client MeilisearchClient) similar_documents(uid string, args SimilarDocumentsArgs) !SimilarDocumentsResponse
fn (MeilisearchClient) update_displayed_attributes #
fn (mut client MeilisearchClient) update_displayed_attributes(uid string, attributes []string) !string
update_displayed_attributes updates displayed attributes of an index
fn (MeilisearchClient) update_distinct_attribute #
fn (mut client MeilisearchClient) update_distinct_attribute(uid string, attribute string) !string
update_distinct_attribute updates distinct attribute of an index
fn (MeilisearchClient) update_documents #
fn (mut client MeilisearchClient) update_documents(uid string, documents string) !TaskInfo
update_documents updates documents in an index
fn (MeilisearchClient) update_filterable_attributes #
fn (mut client MeilisearchClient) update_filterable_attributes(uid string, attributes []string) !string
update_filterable_attributes updates filterable attributes of an index
fn (MeilisearchClient) update_ranking_rules #
fn (mut client MeilisearchClient) update_ranking_rules(uid string, rules []string) !string
update_ranking_rules updates ranking rules of an index
fn (MeilisearchClient) update_searchable_attributes #
fn (mut client MeilisearchClient) update_searchable_attributes(uid string, attributes []string) !string
update_searchable_attributes updates searchable attributes of an index
fn (MeilisearchClient) update_settings #
fn (mut client MeilisearchClient) update_settings(uid string, settings IndexSettings) !string
update_settings updates all settings of an index
fn (MeilisearchClient) update_sortable_attributes #
fn (mut client MeilisearchClient) update_sortable_attributes(uid string, attributes []string) !string
update_sortable_attributes updates sortable attributes of an index
fn (MeilisearchClient) update_stop_words #
fn (mut client MeilisearchClient) update_stop_words(uid string, words []string) !string
update_stop_words updates stop words of an index
fn (MeilisearchClient) update_synonyms #
fn (mut client MeilisearchClient) update_synonyms(uid string, synonyms map[string][]string) !string
update_synonyms updates synonyms of an index
fn (MeilisearchClient) update_typo_tolerance #
fn (mut client MeilisearchClient) update_typo_tolerance(uid string, typo_tolerance TypoTolerance) !string
update_typo_tolerance updates typo tolerance settings of an index
fn (MeilisearchClient) version #
fn (mut client MeilisearchClient) version() !Version
version gets the version of the Meilisearch server
struct MinWordSizeForTypos #
struct MinWordSizeForTypos {
pub mut:
one_typo int = 5 @[json: 'oneTypo']
two_typos int = 9 @[json: 'twoTypos']
}
MinWordSizeForTypos controls minimum word sizes for one/two typos
struct PlayArgs #
struct PlayArgs {
pub mut:
name string = 'default'
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
start bool
stop bool
restart bool
delete bool
configure bool // make sure there is at least one installed
}
struct TaskInfo #
struct TaskInfo {
pub:
uid int @[json: 'taskUid']
index_uid string @[json: 'indexUid']
status string @[json: 'status']
task_type string @[json: 'type']
details map[string]string @[json: 'details']
error string @[json: 'error']
duration string @[json: 'duration']
enqueued_at string @[json: 'enqueuedAt']
started_at string @[json: 'startedAt']
finished_at string @[json: 'finishedAt']
}
TaskInfo represents information about an asynchronous task
struct TypoTolerance #
struct TypoTolerance {
pub mut:
enabled bool = true @[json: 'enabled']
min_word_size_for_typos MinWordSizeForTypos @[json: 'minWordSizeForTypos']
disable_on_words []string @[json: 'disableOnWords']
disable_on_attributes []string @[json: 'disableOnAttributes']
}
TypoTolerance settings for controlling typo behavior
struct Version #
struct Version {
pub:
pkg_version string @[json: 'pkgVersion']
commit_sha string @[json: 'commitSha']
commit_date string @[json: 'commitDate']
}
Version represents version information of the Meilisearch server
- README
- Constants
- fn get
- fn heroscript_default
- fn play
- fn switch
- struct ArgsGet
- struct ClientConfig
- struct CreateIndexArgs
- struct CreateIndexResponse
- struct DeleteIndexResponse
- struct DocumentsQuery
- struct EperimentalFeaturesArgs
- struct GetIndexResponse
- struct Health
- struct IndexSettings
- struct ListIndexArgs
- struct ListResponse
- struct MeilisearchClient
- fn add_documents
- fn create_index
- fn delete_all_documents
- fn delete_document
- fn delete_index
- fn enable_eperimental_feature
- fn facet_search
- fn get_displayed_attributes
- fn get_distinct_attribute
- fn get_document
- fn get_documents
- fn get_filterable_attributes
- fn get_index
- fn get_ranking_rules
- fn get_searchable_attributes
- fn get_settings
- fn get_sortable_attributes
- fn get_stop_words
- fn get_synonyms
- fn get_typo_tolerance
- fn health
- fn list_indexes
- fn reset_displayed_attributes
- fn reset_distinct_attribute
- fn reset_filterable_attributes
- fn reset_ranking_rules
- fn reset_searchable_attributes
- fn reset_settings
- fn reset_sortable_attributes
- fn reset_stop_words
- fn reset_synonyms
- fn reset_typo_tolerance
- fn search
- fn similar_documents
- fn update_displayed_attributes
- fn update_distinct_attribute
- fn update_documents
- fn update_filterable_attributes
- fn update_ranking_rules
- fn update_searchable_attributes
- fn update_settings
- fn update_sortable_attributes
- fn update_stop_words
- fn update_synonyms
- fn update_typo_tolerance
- fn version
- struct MinWordSizeForTypos
- struct PlayArgs
- struct TaskInfo
- struct TypoTolerance
- struct Version