XU XUv0.16.0

#github.com/xulang-org/packages/meilisearch

import: meilisearch #github.com/xulang-org/packages/meilisearch

counts: 4 functions, 18 methods, 4 types, 0 constants, 0 method sets

External 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

Examples · API declarations

Examples

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

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@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]")
}

API declarations

client

XuAPI
pub fn client(endpoint string, api_key string) MeiliClient

Purpose

Execute client.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)

Returns

MeiliClient — a value of this type

pool

XuAPI
pub fn pool(endpoint string, api_key string, max_conns int) MeiliPool

Purpose

Execute pool.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)
max_conns int
max_conns (int)

Returns

MeiliPool — a value of this type

struct MeiliClient

XuAPI
pub struct MeiliClient {
    pub host string
    pub port int
    pub secure bool
    pub api_key string
}

Purpose

Meilisearch Client session maintaining connection and operations.

Public fields

host string
host
port int
port
secure bool
field (bool)
api_key string
field (string)

new_client

XuAPI
pub fn new_client(endpoint string, api_key string) MeiliClient

Purpose

Construct client.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)

Returns

MeiliClient — a value of this type

(MeiliClient) connect

XuAPI
pub fn (c MeiliClient) connect() int

Purpose

Establish network connection to the target server endpoint. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).

Returns

int — a value of this type

(MeiliClient) do_request_on_fd

XuAPI
pub fn (c MeiliClient) do_request_on_fd(fd int, method string, path string, body string) string

Purpose

Operation on MeiliClient: do request on fd. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).
fd int
file descriptor (int)
method string
method (string)
path string
filesystem path (string)
body string
body (string)

Returns

string — result string

(MeiliClient) do_request

XuAPI
pub fn (c MeiliClient) do_request(method string, path string, body string) string

Purpose

Operation on MeiliClient: do request. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).
method string
method (string)
path string
filesystem path (string)
body string
body (string)

Returns

string — result string

(MeiliClient) health

XuAPI
pub fn (c MeiliClient) health() bool

Purpose

Execute health on MeiliClient.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).

Returns

bool — true or false

(MeiliClient) create_index

XuAPI
pub fn (c MeiliClient) create_index(uid string, primary_key string) bool

Purpose

Operation on MeiliClient: create index. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).
uid string
uid (string)
primary_key string
primary_key (string)

Returns

bool — true or false

(MeiliClient) delete_index

XuAPI
pub fn (c MeiliClient) delete_index(uid string) bool

Purpose

Operation on MeiliClient: delete index. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).
uid string
uid (string)

Returns

bool — true or false

(MeiliClient) add_documents

XuAPI
pub fn (c MeiliClient) add_documents(uid string, json_docs string) bool

Purpose

Operation on MeiliClient: add documents. Throws on failure; handle the error or propagate it to the caller.

Parameters

c MeiliClient
The MeiliClient instance used by this call (value receiver).
uid string
uid (string)
json_docs string
json_docs (string)

Returns

bool — true or false

struct MeiliPool

XuAPI
pub struct MeiliPool {
    pub client MeiliClient
    pub state chan pool.State
    pub max_idle int
}

Purpose

Meilisearch Connection pool manager scheduling reusable socket connections.

Public fields

client MeiliClient
field (MeiliClient)
state chan pool.State
field (channel; type chan pool.State)
max_idle int
field (int)

open_pool

XuAPI
pub fn open_pool(endpoint string, api_key string, max_idle int) MeiliPool

Purpose

Open pool.

Parameters

endpoint string
endpoint (string)
api_key string
api_key (string)
max_idle int
max_idle (int)

Returns

MeiliPool — a value of this type

See usage example

(&MeiliPool) dup

XuAPI
pub fn (p &MeiliPool) dup() MeiliPool

Purpose

Copies configuration while sharing the connection and close lifecycle.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).

Returns

MeiliPool — a value of this type

(&MeiliPool) get_conn

XuAPI
pub fn (p &MeiliPool) get_conn() int

Purpose

Operation on &MeiliPool: read conn.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).

Returns

int — a value of this type

(&MeiliPool) put_conn

XuAPI
pub fn (p &MeiliPool) put_conn(fd int)

Purpose

Operation on &MeiliPool: put connection.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).
fd int
file descriptor (int)

Returns

This call does not return a value.

(&MeiliPool) discard_conn

XuAPI
pub fn (p &MeiliPool) discard_conn(fd int)

Purpose

Operation on &MeiliPool: discard connection.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).
fd int
file descriptor (int)

Returns

This call does not return a value.

(&MeiliPool) health

XuAPI
pub fn (p &MeiliPool) health() bool

Purpose

Execute health on &MeiliPool.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).

Returns

bool — true or false

(&MeiliPool) create_index

XuAPI
pub fn (p &MeiliPool) create_index(uid string, primary_key string) bool

Purpose

Operation on &MeiliPool: create index. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).
uid string
uid (string)
primary_key string
primary_key (string)

Returns

bool — true or false

(&MeiliPool) delete_index

XuAPI
pub fn (p &MeiliPool) delete_index(uid string) bool

Purpose

Operation on &MeiliPool: delete index. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).
uid string
uid (string)

Returns

bool — true or false

(&MeiliPool) add_documents

XuAPI
pub fn (p &MeiliPool) add_documents(uid string, json_docs string) bool

Purpose

Operation on &MeiliPool: add documents. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).
uid string
uid (string)
json_docs string
json_docs (string)

Returns

bool — true or false

(&MeiliPool) close

XuAPI
pub fn (p &MeiliPool) close()

Purpose

Operation on &MeiliPool: close the resource.

Parameters

p &MeiliPool
The MeiliPool instance used by this call (borrow).

Returns

This call does not return a value.

struct SearchHit

XuAPI
pub struct SearchHit {
    pub id int
    pub title string
    pub raw string
}

Purpose

Structure encapsulating id, title, raw.

Public fields

id int
field (int)
title string
field (string)
raw string
field (string)

struct SearchResult

XuAPI
pub struct SearchResult {
    pub query string
    pub total_hits int
    pub hits []SearchHit
}

Purpose

Structure encapsulating query, total_hits, hits.

Public fields

query string
field (string)
total_hits int
field (int)
hits []SearchHit
field ([]SearchHit)