### Start Typesense instance with Docker Compose Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md Navigates to the cloned repository and starts the Typesense instance in detached mode. ```bash cd ex_typesense docker compose up -d ``` -------------------------------- ### Example Docker Compose Configuration Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md A sample docker-compose.yml file for setting up a local Typesense instance with specified image, ports, volumes, and commands. ```yaml services: typesense: image: docker.io/typesense/typesense:30.1 container_name: typesense restart: on-failure ports: - "8107:8107" # internal status - "8108:8108" # typesense server volumes: - ./typesense-data:/data - ./typesense-analytics-data:/analytics-data command: --data-dir=/data --api-key=xyz --enable-search-analytics=true --analytics-dir=/analytics-data --analytics-flush-interval=60 --analytics-minute-rate-limit=100 --enable-cors ``` -------------------------------- ### Install Docker using one-line script (Linux) Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md Installs Docker Engine by configuring package repositories. Not recommended for production use. ```bash curl -sSL https://get.docker.com/ | sh ``` -------------------------------- ### Configure ExTypesense with Runtime Configuration Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Set ExTypesense credentials and connection details in `config/runtime.exs` for production environments. This example shows configuration for a local instance. ```elixir # e.g. config/runtime.exs if config_env() == :prod do # if you'll use this in prod environment config :open_api_typesense, api_key: "xyz", host: "localhost", port: 8108, scheme: "http" ... ``` -------------------------------- ### Commit Changes Source: https://github.com/jaeyson/ex_typesense/blob/main/CONTRIBUTING.md Commit your changes with a clear and concise message. The example shows a message related to managing backups and restores. ```bash git commit -am 'manage backups and restores (snapshots)' ``` -------------------------------- ### Verify Typesense Installation Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md Checks the health status of the local Typesense instance by accessing the health endpoint. ```bash curl http://localhost:8108/health ``` -------------------------------- ### Add ExTypesense Dependency to mix.exs Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Add the ExTypesense library to your project's dependencies in `mix.exs`. You can choose to install from the Hex package manager or directly from the GitHub repository. ```elixir def deps do [ # From default Hex package manager {:ex_typesense, "~> 2.3"} # Or from GitHub repository, if you want the latest greatest from main branch {:ex_typesense, git: "https://github.com/jaeyson/ex_typesense.git"} ] end ``` -------------------------------- ### List Collections with Connection Options (v2) Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Demonstrates the v2 syntax for listing collections, where the connection is passed as an option. This is the recommended way to pass connection details in v2 and later. ```elixir ExTypesense.list_collections(conn: conn) ``` -------------------------------- ### Clone ex_typesense Repository Source: https://github.com/jaeyson/ex_typesense/blob/main/CONTRIBUTING.md Clone the ex_typesense repository to your local machine and navigate into the project directory. This is the first step for making contributions. ```bash git clone git@github.com:your_username/ex_typesense.git && cd ex_typesense ``` -------------------------------- ### List Collections with Connection Options (v2 - alternative) Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md An alternative v2 syntax for listing collections, where connection and other options are combined in a list. This approach is useful when multiple options need to be passed. ```elixir opts = [limit: 1, conn: conn] ExTypesense.list_collections(opts) ``` -------------------------------- ### List Collections (pre-v2 syntax) Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Illustrates the pre-v2 syntax for listing collections, where the connection and options are passed as separate arguments. This syntax is deprecated in v2 and later. ```elixir ExTypesense.list_collections(conn, opts) ``` -------------------------------- ### Run Local Typesense Instance with Docker Compose Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Use Docker Compose to quickly spin up a local Typesense instance for development and testing purposes. ```bash docker compose up -d ``` -------------------------------- ### View Typesense Instance Logs Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md Displays logs from all Docker Compose services or specifically from the Typesense container. ```bash # logs from all instances docker compose logs -f # or specifically Typesense docker container logs --follow --tail 50 typesense ``` -------------------------------- ### Clone ex_typesense repository Source: https://github.com/jaeyson/ex_typesense/blob/main/guides/running_local_typesense.md Clones the ex_typesense GitHub repository to your local machine. ```bash git clone https://github.com/jaeyson/ex_typesense.git ``` -------------------------------- ### Create a New Branch Source: https://github.com/jaeyson/ex_typesense/blob/main/CONTRIBUTING.md Create a new branch for your feature or bug fix. Use a descriptive name for the branch, such as 'manage-backups-and-restores'. ```bash git checkout -b manage-backups-and-restores ``` -------------------------------- ### Custom HTTP Client Implementation Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Implement the OpenApiTypesense.Client behavior to define a custom HTTP request handler. This snippet shows how to construct the URL, set headers including the API key and content type, and encode the request body. ```elixir defmodule MyApp.CustomClient do @behaviour OpenApiTypesense.Client @impl OpenApiTypesense.Client def request(conn, params) do url = %URI{ scheme: conn.scheme, host: conn.host, port: conn.port, path: params.url, query: URI.encode_query(params[:query] || %{}) } |> URI.to_string() request = %HTTPoison.Request{method: params.method, url: url} request = if params[:request] do [{content_type, _schema}] = params.request headers = [ {"X-TYPESENSE-API-KEY", conn.api_key} {"Content-Type", content_type} ] %{request | headers: headers} else request end request = if params[:body] do %{request | body: Jason.encode!(params.body)} else request end HTTPoison.request!(request) end end ``` -------------------------------- ### Configure ExTypesense for Cloud Hosted Instance Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Configure ExTypesense with credentials obtained from a cloud-hosted Typesense instance. Ensure to use the correct host, port (usually 443), and scheme (https). ```elixir config :open_api_typesense, api_key: "credential", # Admin API key host: "111222333aaabbbcc-9.x9.typesense.net", # Nodes port: 443, scheme: "https" ``` -------------------------------- ### OpenApiTypesense Configuration Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Configure the OpenApiTypesense library with essential connection details and specify the custom client module. Ensure the API key, host, and port are correctly set for your Typesense instance. ```elixir config :open_api_typesense, api_key: "xyz", # Admin API key host: "localhost", # Nodes port: 8108, scheme: "http", client: MyApp.CustomClient # <- add this ``` -------------------------------- ### Search with Manually Constructed Connection Map Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Perform a search using a manually constructed map for connection details. This is useful for ad-hoc connections or when credentials are not stored in a structured format. ```elixir conn = %{ host: "127.0.0.1", api_key: "xyz", port: 8108, scheme: "http" } ExTypesense.health(conn: conn) ``` -------------------------------- ### Search with Dynamic Credentials from Ecto Schema Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Perform a search operation using credentials dynamically fetched from an Ecto schema. The `conn` map must match the `OpenApiTypesense.Connection.t()` structure. ```elixir # NOTE: create a collection and import documents # first before using the command below ExTypesense.search(collection_name, query, conn: conn) ``` -------------------------------- ### Add Cache and Retry Options to Client Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Demonstrates how to add cache and retry options to the built-in Req client for Typesense requests. This allows for customizing request behavior like retries and caching. ```elixir ExTypesense.get_collection("companies", req: [retry: false, cache: true]) ``` -------------------------------- ### Configure Non-Default Finch Adapter Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Shows how to configure ExTypesense to use a non-default Finch adapter by specifying a custom Finch pool in the application configuration. This is useful when multiple Finch pools are in use. ```elixir config :open_api_typesense, api_key: "XXXXXX", #... options: [finch: MyApp.CustomFinch] # <- add options ``` -------------------------------- ### Create Collection using Ecto Schema Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Defines an Ecto schema for a 'Person' and configures it for ExTypesense, including field types and default sorting. This is used to create a Typesense collection. ```elixir defmodule Person do use Ecto.Schema @behaviour ExTypesense # In this example, we're adding `persons_id` # that points to the id of `persons` schema. defimpl Jason.Encoder, for: __MODULE__ do def encode(value, opts) do value |> Map.take([:id, :persons_id, :name, :country]) |> Enum.map(fn {key, val} -> cond do key === :id -> {key, to_string(Map.get(value, :id))} key === :persons_id -> {key, Map.get(value, :id)} true -> {key, val} end end) |> Enum.into(%{}) |> Jason.Encode.map(opts) end end schema "persons" do field(:name, :string) field(:country, :string) field(:persons_id, :integer, virtual: true) end @impl ExTypesense def get_field_types do name = __MODULE__.__schema__(:source) primary_field = name <> "_id" %{ name: name, default_sorting_field: primary_field, fields: [ %{name: primary_field, type: "int32"}, %{name: "name", type: "string"}, %{name: "country", type: "string"} ] } end end ``` ```elixir ExTypesense.create_collection(Person) ``` -------------------------------- ### Create Collection using Map Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Creates a Typesense collection using a map that defines the collection's name, fields, and default sorting field. This is an alternative to using an Ecto schema. ```elixir schema = %{ name: "companies", fields: [ %{name: "company_name", type: "string"}, %{name: "companies_id", type: "int32"}, %{name: "country", type: "string"} ], default_sorting_field: "companies_id" } ExTypesense.create_collection(schema) ``` -------------------------------- ### Index Single Document using Ecto Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Indexes a single document into Typesense using an Ecto record. Assumes the 'Post' Ecto schema and a 'Repo' are available. ```elixir Post |> Repo.get!(123) |> ExTypesense.index_document() ``` -------------------------------- ### Test ExTypesense Connection Health Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Verify that the ExTypesense client can connect to the Typesense server by calling the `health/0` function. This is a good way to test your configuration. ```elixir ExTypesense.health() ``` -------------------------------- ### Index Multiple Documents using Ecto Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Indexes multiple documents into Typesense from an Ecto query result. Assumes the 'Post' Ecto schema and a 'Repo' are available. ```elixir Post |> Repo.all() |> ExTypesense.import_documents() ``` -------------------------------- ### Index Multiple Documents using List of Maps Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Indexes multiple documents into Typesense from a list of maps. The collection name must be explicitly provided. ```elixir multiple_documents = [ %{ company_name: "Boca Cola", doc_companies_id: 827, country: "SG" }, %{ company_name: "Motor, Inc.", doc_companies_id: 549, country: "TW" } ] ExTypesense.import_documents("companies", multiple_documents) ``` -------------------------------- ### Push New Branch Source: https://github.com/jaeyson/ex_typesense/blob/main/CONTRIBUTING.md Push the newly created branch to the remote repository. This makes your changes available for creating a pull request. ```bash git push -u origin manage-backups-and-restores ``` -------------------------------- ### Index Single Document using Map Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Indexes a single document into Typesense using a map. The collection name can be explicitly provided or inferred from the document map if it contains a 'collection_name' key. ```elixir document = %{ collection_name: "companies", company_name: "Test", doc_companies_id: 103, country: "AL" } ExTypesense.index_document(document) # or explicitly pass the collection name document = %{ company_name: "Test", doc_companies_id: 103, country: "AL" } ExTypesense.index_document("companies", document) ``` -------------------------------- ### Search Documents Source: https://github.com/jaeyson/ex_typesense/blob/main/README.md Searches for documents in a Typesense collection using a map of search parameters. The collection can be specified by its name or by an Ecto module. ```elixir params = %{q: "John Doe", query_by: "name"} # using string collection name ExTypesense.search(schema.name, params) # or module name ExTypesense.search(Person, params) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.