/typesense

A lightweight Typesense client for Elixir

Primary LanguageElixirMIT LicenseMIT

Typesense

A lightweight Typesense client for Elixir.

Installation

If available in Hex, the package can be installed by adding typesense to your list of dependencies in mix.exs:

def deps do
  [
    {:typesense, "~> 0.2.0"}
  ]
end

Configuration

# config/config.exs
config :typesense,
  api_url: "https://search.example.com",
  api_key: "secret"

Usage

To create a Typesense Collection:

schema = %{
  name: "companies",
  fields: [
    %{name: "company_name", type: "string"},
    %{name: "num_employees", type: "int32"},
    %{name: "country", type: "string", facet: true},
  ],
  default_sorting_field: "num_employees"
}

Typesense.Collections.create(schema)

To index a Typesense Document:

document = %{
  id: "124",
  company_name: "Stark Industries",
  num_employees: 5215,
  country: "USA"
}

Typesense.Documents.create(collection, document)