ExRedi v0.1.0 ExRedi View Source

Documentation for ExRedi.

Link to this section Summary

Types

Document format for multi-ops

Error returned from a failed operation

RediSearch field definition

Document ID

The name of your RediSearch index

Operation options

RediSearch query string

RediSearch schema definition

Functions

Adds a document to the index

Adds a document to the index from an existing HASH key in Redis

Adds multiple document to the index via Redis ‘MULTI’

Adds a suggestion string to an auto-complete suggestion dictionary

Runs a search query and performs aggregate transformations on the results

Creates an index with the given spec

Deletes a document from the index

Deletes a string from a suggestion index

Deletes all the keys associated with the index

Checks if the index exists

Prints the execution plan for a query

Returns the full contents of a document

Gets completion suggestions for a prefix

Returns information and statistics on the index

Returns the full contents of multiple documents

Searches the index with the given query, returning either documents or ids

Gets the size of an auto-complete suggestion dictionary

Returns the distinct tags indexed in a Tag field

Link to this section Types

Document format for multi-ops

Link to this type error() View Source
error() :: {:error, binary()}

Error returned from a failed operation

RediSearch field definition

Document ID

The name of your RediSearch index

Operation options

RediSearch query string

RediSearch schema definition

Link to this section Functions

Link to this function add(index, id, fields, opts \\ []) View Source
add(index(), id(), fields(), opts()) :: :ok | error()

Adds a document to the index.

More Info

Example

iex> ExRedi.add("myIdx", "1", ["title", "foo", "body", "bar"])
:ok
Link to this function add_hash(index, id, opts \\ []) View Source
add_hash(index(), id(), opts()) :: :ok | error()

Adds a document to the index from an existing HASH key in Redis.

More Info

Examples

iex> Redix.command(:ex_redi, ["HMSET", "doc-1", "title", "hello world"])
{:ok, "OK"}
iex> ExRedi.add_hash("myIdx", "doc-1")
:ok

iex> ExRedi.add_hash("myIdx", "nothing-here")
{:error, "Could not load document"}
Link to this function add_multi(index, docs, opts \\ []) View Source
add_multi(index(), [doc()], opts()) :: [:ok, ...] | error()

Adds multiple document to the index via Redis ‘MULTI’.

More Info

Example

iex> docs = [
...>   {"1", ["title", "foo", "body", "hello"]},
...>   {"2", ["title", "bar", "body", "world"]}
...> ]
...> ExRedi.add_multi("myIdx", docs)
[:ok, :ok]
Link to this function add_suggestion(key, string, opts \\ []) View Source
add_suggestion(key :: binary(), string :: binary(), opts()) ::
  integer() | error()

Adds a suggestion string to an auto-complete suggestion dictionary.

More Info

Link to this function aggregate(index, query, opts \\ []) View Source
aggregate(index(), query(), opts()) :: list() | error()

Runs a search query and performs aggregate transformations on the results.

More Info

Overview

Link to this function create(index, schema, opts \\ []) View Source
create(index(), schema(), opts()) :: :ok | error()

Creates an index with the given spec.

More Info

Examples

iex> ExRedi.create("myIdx", ["title", "TEXT", "WEIGHT", "5.0", "body", "TEXT"])
:ok

iex> ExRedi.create("myIdx", ["title", "TEXT"])
{:error, "Index already exists. Drop it first!"}
Link to this function del(index, id) View Source
del(index(), id()) :: integer() | error()

Deletes a document from the index.

Returns 1 if the document was removed from the index, otherwise 0.

More Info

Examples

iex> ExRedi.del("myIdx", "1")
1

iex> ExRedi.del("myIdx", "nothing-here")
0
Link to this function delete_suggestion(key, string) View Source
delete_suggestion(key :: binary(), string :: binary()) :: integer() | error()

Deletes a string from a suggestion index.

Returns 1 if the string was removed, otherwise 0.

More Info

Link to this function drop(index) View Source
drop(index()) :: :ok | error()

Deletes all the keys associated with the index.

More Info

Examples

iex> ExRedi.create("myIdx", ["title", "TEXT"])
:ok
iex> ExRedi.drop("myIdx")
:ok
iex> ExRedi.info("myIdx")
{:error, "Unknown Index name"}

iex> ExRedi.drop("notMyIdx")
{:error, "Unknown Index name"}
Link to this function exists?(index) View Source
exists?(index()) :: boolean()

Checks if the index exists.

Examples

iex> exists?("myIdx")
true

iex> exists?("notMyIdx")
false
Link to this function explain(index, query) View Source
explain(index(), query()) :: :ok | error()

Prints the execution plan for a query

More Info

Link to this function get(index, id) View Source
get(index(), id()) :: map() | error()

Returns the full contents of a document.

More Info

Link to this function get_suggestion(key, prefix, opts \\ []) View Source
get_suggestion(key :: binary(), prefix :: binary(), opts()) :: list() | error()

Gets completion suggestions for a prefix.

More Info

Returns information and statistics on the index.

More Info

Example

iex> ExRedi.info(“myIdx”) %{

"bytes_per_record_avg" => "...",
"doc_table_size_mb" => "...",
"fields" => [...],
...

}

Link to this function mget(index, ids) View Source
mget(index(), [id()]) :: [map()] | error()

Returns the full contents of multiple documents.

More Info

Link to this function search(index, query, opts \\ []) View Source
search(index(), query(), opts()) :: [map()] | error()

Searches the index with the given query, returning either documents or ids.

More Info

Syntax

Link to this function suggestion_length(key) View Source
suggestion_length(key :: binary()) :: integer() | error()

Gets the size of an auto-complete suggestion dictionary.

More Info

Link to this function tag_vals(index, field) View Source
tag_vals(index(), field :: binary()) :: list() | error()

Returns the distinct tags indexed in a Tag field.

More Info