View Source ExTypesense behaviour (ExTypesense v0.3.5)
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
Link to this section Summary
Link to this section Callbacks
@callback get_field_types() :: any()
Link to this section Functions
Link to this function