View Source Glific.Searches (Glific v5.1.6)

The Searches context.

Link to this section Summary

Functions

Add permission specific to searches, in this case we want to restrict the visibility of contact ids where the contact is the main query table

Returns an %Ecto.Changeset{} for tracking search changes.

Given a jsonb string, typically either from the database, or maybe via graphql convert the string keys to atoms

Returns the count of searches, using the same filter as list_saved_searches

Creates a search.

Deletes a search.

Gets a single search.

Returns the list of searches.

Execute a saved search, if term is sent in, it is added to the saved search. Either return conversations or count

Full text search interface via Postgres

Search across multiple tables, and return a multiple context result back to the frontend. First step in emulating a whatsapp search

Link to this section Functions

Link to this function

add_permission(query, user)

View Source
@spec add_permission(Ecto.Query.t(), Glific.Users.User.t()) :: Ecto.Query.t()

Add permission specific to searches, in this case we want to restrict the visibility of contact ids where the contact is the main query table

Link to this function

change_saved_search(search, attrs \\ %{})

View Source
@spec change_saved_search(Glific.Searches.SavedSearch.t(), map()) ::
  Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking search changes.

examples

Examples

iex> change_saved_search(search)
%Ecto.Changeset{data: %Search{}}
@spec convert_to_atom(map()) :: map()

Given a jsonb string, typically either from the database, or maybe via graphql convert the string keys to atoms

Link to this function

count_saved_searches(args)

View Source
@spec count_saved_searches(map()) :: integer()

Returns the count of searches, using the same filter as list_saved_searches

Link to this function

create_saved_search(attrs)

View Source
@spec create_saved_search(map()) ::
  {:ok, Glific.Searches.SavedSearch.t()} | {:error, Ecto.Changeset.t()}

Creates a search.

examples

Examples

iex> create_saved_search(%{field: value})
{:ok, %SavedSearch{}}

iex> create_saved_search(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_saved_search(search)

View Source
@spec delete_saved_search(Glific.Searches.SavedSearch.t()) ::
  {:ok, Glific.Searches.SavedSearch.t()} | {:error, Ecto.Changeset.t()}

Deletes a search.

examples

Examples

iex> delete_saved_search(search)
{:ok, %SavedSearch{}}

iex> delete_saved_search(search)
{:error, %Ecto.Changeset{}}
@spec get_saved_search!(integer()) :: Glific.Searches.SavedSearch.t()

Gets a single search.

Raises Ecto.NoResultsError if the SavedSearch does not exist.

examples

Examples

iex> get_saved_search!(123)
%SavedSearch{}

iex> get_saved_search!(456)
** (Ecto.NoResultsError)
Link to this function

list_saved_searches(args)

View Source
@spec list_saved_searches(map()) :: [Glific.Searches.SavedSearch.t()]

Returns the list of searches.

examples

Examples

iex> list_saved_searches()
[%SavedSearch{}, ...]
Link to this function

saved_search_count(args)

View Source
@spec saved_search_count(map()) :: [Glific.Conversations.Conversation.t()] | integer()

Execute a saved search, if term is sent in, it is added to the saved search. Either return conversations or count

Link to this function

search(args, count \\ false)

View Source
@spec search(map(), boolean()) :: [Glific.Conversations.Conversation.t()] | integer()

Full text search interface via Postgres

Link to this function

search_multi(term, args)

View Source
@spec search_multi(String.t(), map()) :: Glific.Searches.Search.t()

Search across multiple tables, and return a multiple context result back to the frontend. First step in emulating a whatsapp search

Link to this function

update_saved_search(search, attrs)

View Source
@spec update_saved_search(Glific.Searches.SavedSearch.t(), map()) ::
  {:ok, Glific.Searches.SavedSearch.t()} | {:error, Ecto.Changeset.t()}

Updates a search.

examples

Examples

iex> update_saved_search(search, %{field: new_value})
{:ok, %SavedSearch{}}

iex> update_saved_search(search, %{field: bad_value})
{:error, %Ecto.Changeset{}}