client
pub fn client(endpoint string, api_key string) MeiliClientPurpose
Execute client.
Parameters
endpointstring- endpoint (string)
api_keystring- api_key (string)
Returns
MeiliClient — a value of this type
#github.com/xulang-org/packages/meilisearchExternal package `meilisearch #github.com/xulang-org/packages/meilisearch`, provided by github.com/xulang-org/packages.
github.com/xulang-org/packages · 1.17.2 · Install and use
These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.
51_standalone_meilisearch/main.xu@main
meilisearch #github.com/xulang-org/packages/meilisearch
#errors
#strings
fn verify_meilisearch_pool_and_models() {
println("--- 1. Testing Meilisearch Protocol & Pool ---")
$p := meilisearch.open_pool("http://127.0.0.1:7700", "masterKey", 5)
// 1. Connection Reuse
fd1 := p.get_conn()
if fd1 < 0 {
println(" [FAIL] Failed to connect to Meilisearch server")
<<
}
println(" Borrow 1 fd: " + str(fd1))
p.put_conn(fd1)
fd2 := p.get_conn()
if fd2 < 0 {
println(" [FAIL] Failed to re-borrow Meilisearch connection")
<<
}
println(" Borrow 2 (after return) fd: " + str(fd2))
if fd1 == fd2 {
println(" [PASS] Connection reused successfully (fd " + str(fd1) + " == " + str(fd2) + ")")
} else {
println(" [WARN] Different fd: " + str(fd1) + " vs " + str(fd2))
}
// 2. Concurrency
fd3 := p.get_conn()
if fd3 < 0 {
println(" [FAIL] Failed to borrow concurrent connection")
<<
}
println(" Borrow 3 (concurrently) fd: " + str(fd3))
if fd2 != fd3 {
println(" [PASS] Concurrently allocated distinct fds (" + str(fd2) + " != " + str(fd3) + ")")
} else {
println(" [FAIL] Expected distinct fds for concurrent connections!")
}
p.put_conn(fd2)
p.put_conn(fd3)
// 3. Real Operations via Pool
h := p.health()
if h {
println(" [PASS] Meilisearch health check: available")
} else {
println(" [FAIL] Meilisearch health check failed")
}
p.create_index("books", "id") >>> (err) {
println(" [FAIL] Failed to create index: " + err.msg())
p.close()
<<
}
docs := "[{\"id\":101,\"title\":\"Antigravity Architecture\"},{\"id\":102,\"title\":\"Compiler Design\"}]"
p.add_documents("books", docs) >>> (err) {
println(" [FAIL] Failed to add documents: " + err.msg())
p.close()
<<
}
println(" [PASS] Meilisearch index & docs added via pool")
p.close()
println(" [PASS] Meilisearch Pool closed cleanly.")
}
fn main() {
println("=== Xu Meilisearch Native Driver Verification ===\n")
verify_meilisearch_pool_and_models()
println("\n[MEILISEARCH VERIFICATION 100% COMPLETED]")
}clientpub fn client(endpoint string, api_key string) MeiliClientExecute client.
endpoint stringapi_key stringMeiliClient — a value of this type
poolpub fn pool(endpoint string, api_key string, max_conns int) MeiliPoolExecute pool.
endpoint stringapi_key stringmax_conns intMeiliPool — a value of this type
struct MeiliClientpub struct MeiliClient {
pub host string
pub port int
pub secure bool
pub api_key string
}Meilisearch Client session maintaining connection and operations.
host stringport intsecure boolapi_key stringnew_clientpub fn new_client(endpoint string, api_key string) MeiliClientConstruct client.
endpoint stringapi_key stringMeiliClient — a value of this type
(MeiliClient) connectpub fn (c MeiliClient) connect() intEstablish network connection to the target server endpoint. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).int — a value of this type
(MeiliClient) do_request_on_fdpub fn (c MeiliClient) do_request_on_fd(fd int, method string, path string, body string) stringOperation on MeiliClient: do request on fd. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).fd intmethod stringpath stringbody stringstring — result string
(MeiliClient) do_requestpub fn (c MeiliClient) do_request(method string, path string, body string) stringOperation on MeiliClient: do request. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).method stringpath stringbody stringstring — result string
(MeiliClient) healthpub fn (c MeiliClient) health() boolExecute health on MeiliClient.
c MeiliClientMeiliClient instance used by this call (value receiver).bool — true or false
(MeiliClient) create_indexpub fn (c MeiliClient) create_index(uid string, primary_key string) boolOperation on MeiliClient: create index. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).uid stringprimary_key stringbool — true or false
(MeiliClient) delete_indexpub fn (c MeiliClient) delete_index(uid string) boolOperation on MeiliClient: delete index. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).uid stringbool — true or false
(MeiliClient) add_documentspub fn (c MeiliClient) add_documents(uid string, json_docs string) boolOperation on MeiliClient: add documents. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).uid stringjson_docs stringbool — true or false
(MeiliClient) searchpub fn (c MeiliClient) search(uid string, query string, limit int) SearchResultOperation on MeiliClient: binary search. Throws on failure; handle the error or propagate it to the caller.
c MeiliClientMeiliClient instance used by this call (value receiver).uid stringquery stringlimit intSearchResult — a value of this type
struct MeiliPoolpub struct MeiliPool {
pub client MeiliClient
pub state chan pool.State
pub max_idle int
}Meilisearch Connection pool manager scheduling reusable socket connections.
client MeiliClientstate chan pool.Statemax_idle intopen_poolpub fn open_pool(endpoint string, api_key string, max_idle int) MeiliPoolOpen pool.
endpoint stringapi_key stringmax_idle intMeiliPool — a value of this type
(&MeiliPool) duppub fn (p &MeiliPool) dup() MeiliPoolCopies configuration while sharing the connection and close lifecycle.
p &MeiliPoolMeiliPool instance used by this call (borrow).MeiliPool — a value of this type
(&MeiliPool) get_connpub fn (p &MeiliPool) get_conn() intOperation on &MeiliPool: read conn.
p &MeiliPoolMeiliPool instance used by this call (borrow).int — a value of this type
(&MeiliPool) put_connpub fn (p &MeiliPool) put_conn(fd int)Operation on &MeiliPool: put connection.
p &MeiliPoolMeiliPool instance used by this call (borrow).fd intThis call does not return a value.
(&MeiliPool) discard_connpub fn (p &MeiliPool) discard_conn(fd int)Operation on &MeiliPool: discard connection.
p &MeiliPoolMeiliPool instance used by this call (borrow).fd intThis call does not return a value.
(&MeiliPool) healthpub fn (p &MeiliPool) health() boolExecute health on &MeiliPool.
p &MeiliPoolMeiliPool instance used by this call (borrow).bool — true or false
(&MeiliPool) create_indexpub fn (p &MeiliPool) create_index(uid string, primary_key string) boolOperation on &MeiliPool: create index. Throws on failure; handle the error or propagate it to the caller.
p &MeiliPoolMeiliPool instance used by this call (borrow).uid stringprimary_key stringbool — true or false
(&MeiliPool) delete_indexpub fn (p &MeiliPool) delete_index(uid string) boolOperation on &MeiliPool: delete index. Throws on failure; handle the error or propagate it to the caller.
p &MeiliPoolMeiliPool instance used by this call (borrow).uid stringbool — true or false
(&MeiliPool) add_documentspub fn (p &MeiliPool) add_documents(uid string, json_docs string) boolOperation on &MeiliPool: add documents. Throws on failure; handle the error or propagate it to the caller.
p &MeiliPoolMeiliPool instance used by this call (borrow).uid stringjson_docs stringbool — true or false
(&MeiliPool) searchpub fn (p &MeiliPool) search(uid string, query string, limit int) SearchResultOperation on &MeiliPool: binary search. Throws on failure; handle the error or propagate it to the caller.
p &MeiliPoolMeiliPool instance used by this call (borrow).uid stringquery stringlimit intSearchResult — a value of this type
(&MeiliPool) closepub fn (p &MeiliPool) close()Operation on &MeiliPool: close the resource.
p &MeiliPoolMeiliPool instance used by this call (borrow).This call does not return a value.
struct SearchHitpub struct SearchHit {
pub id int
pub title string
pub raw string
}Structure encapsulating id, title, raw.
id inttitle stringraw stringstruct SearchResultpub struct SearchResult {
pub query string
pub total_hits int
pub hits []SearchHit
}Structure encapsulating query, total_hits, hits.
query stringtotal_hits inthits []SearchHit