zig-search-engine

API reference

On this page 53

Every declaration below is extracted from zig-search-engine's source, with the doc comments as written there. A declaration listed without prose is public but undocumented in the source.

Root

types

const types = @import("types.zig")

http

const http = @import("http.zig")

Schema

const Schema = types.Schema

Field

const Field = types.Field

FieldType

const FieldType = types.FieldType

SearchParams

const SearchParams = types.SearchParams

Error

const Error = types.Error

typesense

const typesense = @import("drivers/typesense.zig")

Typesense

const Typesense = typesense.Typesense

TypesenseConfig

const TypesenseConfig = typesense.Config

SearchResponse

const SearchResponse = typesense.SearchResponse

DocBuilder

const DocBuilder = typesense.DocBuilder

types

FieldType

const FieldType = enum

typesenseName

fn typesenseName(self: FieldType) []const u8

Field

const Field = struct

Schema

const Schema = struct

Model-style declaration of a searchable collection.

SearchParams

const SearchParams = struct

Error

const Error = error

http

Response

const Response = struct

deinit

fn deinit(self: Response, allocator: std.mem.Allocator) void

ok

fn ok(self: Response) bool
const Header = struct

request

fn request(

appendJsonString

fn appendJsonString(list: *std.ArrayList(u8), allocator: std.mem.Allocator, s: []const u8) !void

Append s as a JSON string literal (with quotes) to list.

appendUrlEncoded

fn appendUrlEncoded(list: *std.ArrayList(u8), allocator: std.mem.Allocator, s: []const u8) !void

Append s percent-encoded (RFC 3986 unreserved characters pass through).

typesense

Config

const Config = struct

Typesense

const Typesense = struct

init

fn init(config: Config) Typesense

healthy

fn healthy(self: *const Typesense, allocator: std.mem.Allocator) bool

True when the engine answers on /health.

collectionExists

fn collectionExists(self: *const Typesense, allocator: std.mem.Allocator, name: []const u8) types.Error!bool

ensureCollection

fn ensureCollection(self: *const Typesense, allocator: std.mem.Allocator, schema: types.Schema) types.Error!void

Create the collection for schema if it doesn't exist. The schema's attribute groups map to Typesense field properties the same way the stacks driver maps a model's useSearch trait: searchable/displayed -> plain field filterable -> facet: true sortable -> sort: true All fields are optional except id (implicit in Typesense).

deleteCollection

fn deleteCollection(self: *const Typesense, allocator: std.mem.Allocator, name: []const u8) types.Error!void

upsertDocument

fn upsertDocument(self: *const Typesense, allocator: std.mem.Allocator, collection: []const u8, json_doc: []const u8) types.Error!void

Upsert one document (json_doc must be a complete JSON object with an "id" member — build it with DocBuilder).

importDocuments

fn importDocuments(self: *const Typesense, allocator: std.mem.Allocator, collection: []const u8, jsonl: []const u8) types.Error!void

Bulk upsert documents given as JSONL (one JSON object per line).

deleteDocument

fn deleteDocument(self: *const Typesense, allocator: std.mem.Allocator, collection: []const u8, id: []const u8) types.Error!void
fn search(self: *const Typesense, allocator: std.mem.Allocator, collection: []const u8, params: types.SearchParams) types.Error!SearchResponse

Run a search. The returned SearchResponse owns the parsed JSON; callers iterate hits() and must call deinit().

SearchResponse

const SearchResponse = struct

Parsed search response. hits() iterates the hit documents as JSON objects; string values are valid until deinit().

deinit

fn deinit(self: *SearchResponse) void

found

fn found(self: *const SearchResponse) u64

HitIterator

const HitIterator = struct

next

fn next(self: *HitIterator) ?std.json.ObjectMap

Returns the next hit's document object, skipping malformed hits.

hits

fn hits(self: *const SearchResponse) HitIterator

docString

fn docString(doc: std.json.ObjectMap, name: []const u8) []const u8

Convenience: string field of a hit document ("" when absent).

DocBuilder

const DocBuilder = struct

Incremental JSON object builder for documents.

init

fn init(allocator: std.mem.Allocator) DocBuilder

deinit

fn deinit(self: *DocBuilder) void

putString

fn putString(self: *DocBuilder, name: []const u8, value: []const u8) types.Error!void

putInt

fn putInt(self: *DocBuilder, name: []const u8, value: i64) types.Error!void

toOwned

fn toOwned(self: *DocBuilder) types.Error![]u8

Finish and return the JSON object. Caller owns the slice; the builder is reset to empty.