View Source ExTypesense behaviour (ExTypesense v0.4.0)
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
Callbacks
@callback get_field_types() :: any()
Functions
Link to this function
delete_collection_alias(conn \\ Connection.new(), alias_name)
View Source (since 0.1.0)
This function is deprecated. use delete_document_by_id/3.
This function is deprecated. use delete_document_by_struct/2.
Link to this function
delete_document_by_id(conn \\ Connection.new(), collection_name, document_id)
View Source (since 0.1.0)
Link to this function
delete_document_by_struct(conn \\ Connection.new(), struct)
View Source (since 0.1.0)
Link to this function
drop_collection(conn \\ Connection.new(), collection_name)
View Source (since 0.1.0)
Link to this function
get_collection_alias(conn \\ Connection.new(), alias_name)
View Source (since 0.1.0)
Link to this function
get_collection_name(conn \\ Connection.new(), alias_name)
View Source (since 0.1.0)
Link to this function
get_document(conn \\ Connection.new(), collection_name, document_id)
View Source (since 0.1.0)
Link to this function
index_multiple_documents(conn \\ Connection.new(), documents)
View Source (since 0.1.0)
Link to this function
search(conn \\ Connection.new(), module_or_collection_name, params)
View Source (since 0.1.0)
Link to this function
update_collection_fields(conn \\ Connection.new(), collection_name, fields)
View Source (since 0.1.0)
Link to this function
update_multiple_documents(conn \\ Connection.new(), documents)
View Source (since 0.1.0)
Link to this function
upsert_collection_alias(conn \\ Connection.new(), alias_name, collection_name)
View Source (since 0.1.0)
Link to this function