ExTypesense behaviour (ExTypesense v2.0.1)

View Source

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:

Schema and field types for Ecto

The code below is when you're using it with Ecto schema. Skip this if you just want plain old maps

defmodule App.Person do
  use Ecto.Schema
  @behaviour ExTypesense

  defimpl Jason.Encoder, for: __MODULE__ do
    def encode(value, opts) do
      value
      |> Map.take([:id, :persons_id, :name, :age])
      |> 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 :age, :integer
    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: "age", type: "integer"}
        ]
    }
  end
end

Summary

Callbacks

A callback function for creating the schema fields in Typesense.

Functions

Callbacks

get_field_types()

(since 1.0.0)
@callback get_field_types() :: map()

A callback function for creating the schema fields in Typesense.

Where to add

This function should be added in the Ecto Schema that you will be use to import to Typesense.

defmodule MyApp.Accounts.User do
  use Ecto.Schema
  @behaviour ExTypesense

  #... Lots of user-related code + Ecto schema

  @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: "age", type: "integer"}
        ]
    }
  end

Functions

api_stats()

(since 1.0.0)

See ExTypesense.Cluster.api_stats/0.

api_stats(opts)

(since 1.0.0)

See ExTypesense.Cluster.api_stats/1.

clear_cache()

(since 1.0.0)

See ExTypesense.Cluster.clear_cache/0.

clear_cache(opts)

(since 1.0.0)

See ExTypesense.Cluster.clear_cache/1.

clone_collection(src_coll, new_coll)

(since 1.0.0)

See ExTypesense.Collection.clone_collection/2.

clone_collection(src_coll, new_coll, opts)

(since 1.0.0)

See ExTypesense.Collection.clone_collection/3.

cluster_metrics()

(since 1.0.0)

See ExTypesense.Cluster.cluster_metrics/0.

cluster_metrics(opts)

(since 1.0.0)

See ExTypesense.Cluster.cluster_metrics/1.

compact_db()

(since 1.0.0)

See ExTypesense.Cluster.compact_db/0.

compact_db(opts)

(since 1.0.0)

See ExTypesense.Cluster.compact_db/1.

create_analytics_event(body)

(since 1.0.0)

See ExTypesense.Analytics.create_analytics_event/1.

create_analytics_event(body, opts)

(since 1.0.0)

See ExTypesense.Analytics.create_analytics_event/2.

create_analytics_rule(body)

(since 1.0.0)

See ExTypesense.Analytics.create_analytics_rule/1.

create_analytics_rule(body, opts)

(since 1.0.0)

See ExTypesense.Analytics.create_analytics_rule/2.

create_collection(schema)

(since 1.0.0)

See ExTypesense.Collection.create_collection/1.

create_collection(schema, opts)

(since 1.0.0)

See ExTypesense.Collection.create_collection/2.

create_collection_with_alias(schema)

(since 1.0.0)

See ExTypesense.Collection.create_collection_with_alias/1.

create_collection_with_alias(schema, opts)

(since 1.0.0)

See ExTypesense.Collection.create_collection_with_alias/2.

create_key(body)

(since 1.0.0)

See ExTypesense.Key.create_key/1.

create_key(body, opts)

(since 1.0.0)

See ExTypesense.Key.create_key/2.

create_model(body)

(since 1.0.0)

See ExTypesense.Conversation.create_model/1.

create_model(body, opts)

(since 1.0.0)

See ExTypesense.Conversation.create_model/2.

create_snapshot(opts)

(since 1.0.0)

See ExTypesense.Cluster.create_snapshot/1.

debug()

(since 1.0.0)

See ExTypesense.Debug.debug/0.

debug(opts)

(since 1.0.0)

See ExTypesense.Debug.debug/1.

delete_all_documents(collection_name)

(since 1.0.0)

See ExTypesense.Document.delete_all_documents/1.

delete_all_documents(collection_name, opts)

(since 1.0.0)

See ExTypesense.Document.delete_all_documents/2.

delete_analytics_rule(rule_name)

(since 1.0.0)

See ExTypesense.Analytics.delete_analytics_rule/1.

delete_analytics_rule(rule_name, opts)

(since 1.0.0)

See ExTypesense.Analytics.delete_analytics_rule/2.

delete_collection_alias(alias_name)

(since 1.0.0)

See ExTypesense.Collection.delete_collection_alias/1.

delete_collection_alias(alias_name, opts)

(since 1.0.0)

See ExTypesense.Collection.delete_collection_alias/2.

delete_document(document)

(since 1.0.0)

See ExTypesense.Document.delete_document/1.

delete_document(coll_name, doc_id)

(since 1.0.0)

See ExTypesense.Document.delete_document/2.

delete_document(coll_name, doc_id, opts)

(since 1.0.0)

See ExTypesense.Document.delete_document/3.

delete_documents_by_query(collection_name, opts)

(since 1.0.0)

See ExTypesense.Document.delete_documents_by_query/2.

delete_key(key_id)

(since 1.0.0)

See ExTypesense.Key.delete_key/1.

delete_key(key_id, opts)

(since 1.0.0)

See ExTypesense.Key.delete_key/2.

delete_model(model_id)

(since 1.0.0)

See ExTypesense.Conversation.delete_model/1.

delete_model(model_id, opts)

(since 1.0.0)

See ExTypesense.Conversation.delete_model/2.

delete_override(coll_name, ovr_id)

(since 1.0.0)

See ExTypesense.Curation.delete_override/2.

delete_override(coll_name, ovr_id, opts)

(since 1.0.0)

See ExTypesense.Curation.delete_override/3.

delete_preset(preset_id)

(since 1.0.0)

See ExTypesense.Preset.delete_preset/1.

delete_preset(preset_id, opts)

(since 1.0.0)

See ExTypesense.Preset.delete_preset/2.

delete_stopword(stop_id)

(since 1.0.0)

See ExTypesense.Stopwords.delete_stopword/1.

delete_stopword(stop_id, opts)

(since 1.0.0)

See ExTypesense.Stopwords.delete_stopword/2.

delete_synonym(coll_name, syn_id)

(since 1.0.0)

See ExTypesense.Synonym.delete_synonym/2.

delete_synonym(coll_name, syn_id, opts)

(since 1.0.0)

See ExTypesense.Synonym.delete_synonym/3.

drop_collection(name)

(since 1.0.0)

See ExTypesense.Collection.drop_collection/1.

drop_collection(name, opts)

(since 1.0.0)

See ExTypesense.Collection.drop_collection/2.

export_documents(coll_name)

(since 1.0.0)

See ExTypesense.Document.export_documents/1.

export_documents(coll_name, opts)

(since 1.0.0)

See ExTypesense.Document.export_documents/2.

get_analytics_rule(rule_name)

(since 1.0.0)

See ExTypesense.Analytics.get_analytics_rule/1.

get_analytics_rule(rule_name, opts)

(since 1.0.0)

See ExTypesense.Analytics.get_analytics_rule/2.

get_collection(name)

(since 1.0.0)

See ExTypesense.Collection.get_collection/1.

get_collection(coll_name, opts)

(since 1.0.0)

See ExTypesense.Collection.get_collection/2.

get_collection_alias(alias_name)

(since 1.0.0)

See ExTypesense.Collection.get_collection_alias/1.

get_collection_alias(alias_name, opts)

(since 1.0.0)

See ExTypesense.Collection.get_collection_alias/2.

get_document(coll_name, doc_id)

(since 1.0.0)

See ExTypesense.Document.get_document/2.

get_document(coll_name, doc_id, opts)

(since 1.0.0)

See ExTypesense.Document.get_document/3.

get_key(key_id)

(since 1.0.0)

See ExTypesense.Key.get_key/1.

get_key(key_id, opts)

(since 1.0.0)

See ExTypesense.Key.get_key/2.

get_model(model_id)

(since 1.0.0)

See ExTypesense.Conversation.get_model/1.

get_model(model_id, opts)

(since 1.0.0)

See ExTypesense.Conversation.get_model/2.

get_override(coll_name, ovr_id)

(since 1.0.0)

See ExTypesense.Curation.get_override/2.

get_override(coll_name, ovr_id, opts)

(since 1.0.0)

See ExTypesense.Curation.get_override/3.

get_preset(preset_id)

(since 1.0.0)

See ExTypesense.Preset.get_preset/1.

get_preset(preset_id, opts)

(since 1.0.0)

See ExTypesense.Preset.get_preset/2.

get_schema_changes()

(since 1.0.0)

See ExTypesense.Cluster.get_schema_changes/0.

get_schema_changes(opts)

(since 1.0.0)

See ExTypesense.Cluster.get_schema_changes/1.

get_stemming_dictionary(dictionary_id)

(since 1.0.0)

See ExTypesense.Stemming.get_stemming_dictionary/1.

get_stemming_dictionary(dictionary_id, opts)

(since 1.0.0)

See ExTypesense.Stemming.get_stemming_dictionary/2.

get_stopword(stop_id)

(since 1.0.0)

See ExTypesense.Stopwords.get_stopword/1.

get_stopword(stop_id, opts)

(since 1.0.0)

See ExTypesense.Stopwords.get_stopword/2.

get_synonym(coll_name, syn_id)

(since 1.0.0)

See ExTypesense.Synonym.get_synonym/2.

get_synonym(coll_name, syn_id, opts)

(since 1.0.0)

See ExTypesense.Synonym.get_synonym/3.

health()

(since 1.0.0)

See ExTypesense.Cluster.health/0.

health(opts)

(since 1.0.0)

See ExTypesense.Cluster.health/1.

import_documents(coll_name, documents)

(since 1.0.0)

See ExTypesense.Document.import_documents/2.

import_documents(coll_name, documents, opts)

(since 1.0.0)

See ExTypesense.Document.import_documents/3.

import_stemming_dictionary(body, opts)

(since 1.0.0)

See ExTypesense.Stemming.import_stemming_dictionary/2.

index_document(document)

(since 1.0.0)

See ExTypesense.Document.index_document/1.

index_document(collection_name, document)

(since 1.0.0)

See ExTypesense.Document.index_document/2.

index_document(collection_name, document, opts)

(since 1.0.0)

See ExTypesense.Document.index_document/3.

list_analytics_rules()

(since 1.0.0)

See ExTypesense.Analytics.list_analytics_rules/0.

list_analytics_rules(opts)

(since 1.0.0)

See ExTypesense.Analytics.list_analytics_rules/1.

list_collection_aliases()

(since 1.0.0)

See ExTypesense.Collection.list_collection_aliases/0.

list_collection_aliases(opts)

(since 1.0.0)

See ExTypesense.Collection.list_collection_aliases/1.

list_collections()

(since 1.0.0)

See ExTypesense.Collection.list_collections/0.

list_collections(opts)

(since 1.0.0)

See ExTypesense.Collection.list_collections/1.

list_keys()

(since 1.0.0)

See ExTypesense.Key.list_keys/0.

list_keys(opts)

(since 1.0.0)

See ExTypesense.Key.list_keys/1.

list_models()

(since 1.0.0)

See ExTypesense.Conversation.list_models/0.

list_models(opts)

(since 1.0.0)

See ExTypesense.Conversation.list_models/1.

list_overrides(coll_name)

(since 1.0.0)

See ExTypesense.Curation.list_overrides/1.

list_overrides(coll_name, opts)

(since 1.0.0)

See ExTypesense.Curation.list_overrides/2.

list_presets()

(since 1.0.0)

See ExTypesense.Preset.list_presets/0.

list_presets(opts)

(since 1.0.0)

See ExTypesense.Preset.list_presets/1.

list_stemming_dictionaries()

(since 1.0.0)

See ExTypesense.Stemming.list_stemming_dictionaries/0.

list_stemming_dictionaries(opts)

(since 1.0.0)

See ExTypesense.Stemming.list_stemming_dictionaries/1.

list_stopwords()

(since 1.0.0)

See ExTypesense.Stopwords.list_stopwords/0.

list_stopwords(opts)

(since 1.0.0)

See ExTypesense.Stopwords.list_stopwords/1.

list_synonyms(coll_name)

(since 1.0.0)

See ExTypesense.Synonym.list_synonyms/1.

list_synonyms(coll_name, opts)

(since 1.0.0)

See ExTypesense.Synonym.list_synonyms/2.

multi_search(searches)

(since 1.0.0)

See ExTypesense.Search.multi_search/1.

multi_search(searches, opts)

(since 1.0.0)

See ExTypesense.Search.multi_search/2.

multi_search_ecto(searches)

(since 1.0.0)

See ExTypesense.Search.multi_search_ecto/1.

multi_search_ecto(searches, opts)

(since 1.0.0)

See ExTypesense.Search.multi_search_ecto/2.

search(coll_name, opts)

(since 1.0.0)

See ExTypesense.Search.search/2.

search_ecto(coll_name, opts)

(since 1.0.0)

See ExTypesense.Search.search_ecto/2.

toggle_slow_request_log(config)

(since 1.0.0)

See ExTypesense.Cluster.toggle_slow_request_log/1.

toggle_slow_request_log(config, opts)

(since 1.0.0)

See ExTypesense.Cluster.toggle_slow_request_log/2.

update_collection_fields(name, fields)

(since 1.0.0)

See ExTypesense.Collection.update_collection_fields/2.

update_collection_fields(name, fields, opts)

(since 1.0.0)

See ExTypesense.Collection.update_collection_fields/3.

update_document(document)

(since 1.0.0)

See ExTypesense.Document.update_document/1.

update_document(document, opts)

(since 1.0.0)

See ExTypesense.Document.update_document/2.

update_documents_by_query(coll_name, body, opts)

(since 1.0.0)

See ExTypesense.Document.update_documents_by_query/3.

update_model(model_id, body)

(since 1.0.0)

See ExTypesense.Conversation.update_model/2.

update_model(model_id, body, opts)

(since 1.0.0)

See ExTypesense.Conversation.update_model/3.

upsert_analytics_rule(rule_name, body)

(since 1.0.0)

See ExTypesense.Analytics.upsert_analytics_rule/2.

upsert_analytics_rule(rule_name, body, opts)

(since 1.0.0)

See ExTypesense.Analytics.upsert_analytics_rule/3.

upsert_collection_alias(alias_name, coll_name)

(since 1.0.0)

See ExTypesense.Collection.upsert_collection_alias/2.

upsert_collection_alias(alias_name, coll_name, opts)

(since 1.0.0)

See ExTypesense.Collection.upsert_collection_alias/3.

upsert_override(coll_name, ovr_id, body)

(since 1.0.0)

See ExTypesense.Curation.upsert_override/3.

upsert_override(coll_name, ovr_id, body, opts)

(since 1.0.0)

See ExTypesense.Curation.upsert_override/4.

upsert_preset(preset_id, body)

(since 1.0.0)

See ExTypesense.Preset.upsert_preset/2.

upsert_preset(preset_id, body, opts)

(since 1.0.0)

See ExTypesense.Preset.upsert_preset/3.

upsert_stopword(stop_id, body)

(since 1.0.0)

See ExTypesense.Stopwords.upsert_stopword/2.

upsert_stopword(stop_id, body, opts)

(since 1.0.0)

See ExTypesense.Stopwords.upsert_stopword/3.

upsert_synonym(coll_name, syn_id, body)

(since 1.0.0)

See ExTypesense.Synonym.upsert_synonym/3.

upsert_synonym(coll_name, syn_id, body, opts)

(since 1.0.0)

See ExTypesense.Synonym.upsert_synonym/4.

vote()

(since 1.0.0)

See ExTypesense.Cluster.vote/0.

vote(opts)

(since 1.0.0)

See ExTypesense.Cluster.vote/1.