View Source ExTypesense behaviour (ExTypesense v0.4.1)

Public API functions to interact with Typesense.

If you want to implement field types for your Ecto schema, you may need to encode the schema and add the callback get_field_types/0:

# this example module can be found at: lib/ex_typesense/test_schema/person.ex
defmodule App.Person do
  @behaviour ExTypesense

  defimpl Jason.Encoder, for: __MODULE__ do
    def encode(value, opts) do
      value
      |> Map.take([:id, :person_id, :name, :age])
      |> Enum.map(fn {key, val} ->
        cond do
          key === :id -> {key, to_string(Map.get(value, :id))}
          key === :person_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 :age, :integer
    field :person_id, :integer, virtual: true
  end

  def get_field_types do
    %{
      default_sorting_field: "person_id",
      fields:
        [
          %{name: "person_id", type: "int32"},
          %{name: "name", type: "string"},
          %{name: "age", type: "integer"}
        ]
    }
  end
end

Summary

Functions

Callbacks

Link to this callback

get_field_types()

View Source (since 0.1.0)
@callback get_field_types() :: any()

Functions

Link to this function

api_stats(conn \\ Connection.new())

View Source (since 0.1.0)

See ExTypesense.Cluster.api_stats/1.

Link to this function

cluster_metrics(conn \\ Connection.new())

View Source (since 0.1.0)

See ExTypesense.Cluster.cluster_metrics/1.

Link to this function

create_collection(conn \\ Connection.new(), schema)

View Source (since 0.1.0)

See ExTypesense.Collection.create_collection/2.

Link to this function

create_document(conn \\ Connection.new(), document)

View Source (since 0.1.0)

See ExTypesense.Document.create_document/2.

Link to this function

delete_collection_alias(conn \\ Connection.new(), alias_name)

View Source (since 0.1.0)

See ExTypesense.Collection.delete_collection_alias/2.

Link to this function

delete_document(document)

View Source (since 0.1.0)
This function is deprecated. use delete_document_by_id/3.

See ExTypesense.Document.delete_document/1.

Link to this function

delete_document(collection_name, document_id)

View Source (since 0.1.0)
This function is deprecated. use delete_document_by_struct/2.

See ExTypesense.Document.delete_document/2.

Link to this function

delete_document_by_id(conn \\ Connection.new(), collection_name, document_id)

View Source (since 0.1.0)

See ExTypesense.Document.delete_document_by_id/3.

Link to this function

delete_document_by_struct(conn \\ Connection.new(), struct)

View Source (since 0.1.0)

See ExTypesense.Document.delete_document_by_struct/2.

Link to this function

drop_collection(conn \\ Connection.new(), collection_name)

View Source (since 0.1.0)

See ExTypesense.Collection.drop_collection/2.

Link to this function

get_collection(conn \\ Connection.new(), name)

View Source (since 0.1.0)

See ExTypesense.Collection.get_collection/2.

Link to this function

get_collection_alias(conn \\ Connection.new(), alias_name)

View Source (since 0.1.0)

See ExTypesense.Collection.get_collection_alias/2.

Link to this function

get_collection_name(conn \\ Connection.new(), alias_name)

View Source (since 0.1.0)

See ExTypesense.Collection.get_collection_name/2.

Link to this function

get_document(conn \\ Connection.new(), collection_name, document_id)

View Source (since 0.1.0)

See ExTypesense.Document.get_document/3.

Link to this function

health(conn \\ Connection.new())

View Source (since 0.1.0)

See ExTypesense.Cluster.health/1.

Link to this function

index_multiple_documents(conn \\ Connection.new(), documents)

View Source (since 0.1.0)

See ExTypesense.Document.index_multiple_documents/2.

Link to this function

list_collection_aliases(conn \\ Connection.new())

View Source (since 0.1.0)

See ExTypesense.Collection.list_collection_aliases/1.

Link to this function

list_collections(conn \\ Connection.new())

View Source (since 0.1.0)

See ExTypesense.Collection.list_collections/1.

Link to this function

search(conn \\ Connection.new(), module_or_collection_name, params)

View Source (since 0.1.0)

See ExTypesense.Search.search/3.

Link to this function

update_collection_fields(conn \\ Connection.new(), collection_name, fields)

View Source (since 0.1.0)

See ExTypesense.Collection.update_collection_fields/3.

Link to this function

update_document(conn \\ Connection.new(), document)

View Source (since 0.1.0)

See ExTypesense.Document.update_document/2.

Link to this function

update_multiple_documents(conn \\ Connection.new(), documents)

View Source (since 0.1.0)

See ExTypesense.Document.update_multiple_documents/2.

Link to this function

upsert_collection_alias(conn \\ Connection.new(), alias_name, collection_name)

View Source (since 0.1.0)

See ExTypesense.Collection.upsert_collection_alias/3.

Link to this function

upsert_document(conn \\ Connection.new(), document)

View Source (since 0.1.0)

See ExTypesense.Document.upsert_document/2.

Link to this function

upsert_multiple_documents(conn \\ Connection.new(), documents)

View Source (since 0.1.0)

See ExTypesense.Document.upsert_multiple_documents/2.