TantivyEx.Index (TantivyEx v0.4.1)
View SourceIndex management for TantivyEx.
An index is a collection of segments that contain documents and their associated search indices.
Summary
Functions
Creates a new index in the specified directory.
Creates a new index in RAM.
Opens an existing index at the specified path.
Opens an existing index at the specified path, or creates it if it doesn't exist.
Types
@type t() :: reference()
Functions
@spec create_in_dir(String.t(), TantivyEx.Schema.t()) :: {:ok, t()} | {:error, String.t()}
Creates a new index in the specified directory.
The directory will be created if it doesn't exist. The index metadata and segment files will be stored in this directory.
Parameters
path: The filesystem path where the index should be createdschema: The schema defining the structure of documents
Examples
iex> schema = TantivyEx.Schema.new()
iex> schema = TantivyEx.Schema.add_text_field(schema, "title", :text_stored)
iex> {:ok, index} = TantivyEx.Index.create_in_dir("/tmp/my_index", schema)
iex> is_reference(index)
true
@spec create_in_ram(TantivyEx.Schema.t()) :: {:ok, t()} | {:error, String.t()}
Creates a new index in RAM.
This creates an in-memory index that doesn't persist to disk. Useful for testing or temporary indices.
Parameters
schema: The schema defining the structure of documents
Examples
iex> schema = TantivyEx.Schema.new()
iex> schema = TantivyEx.Schema.add_text_field(schema, "title", :text_stored)
iex> {:ok, index} = TantivyEx.Index.create_in_ram(schema)
iex> is_reference(index)
true
Opens an existing index at the specified path.
This function attempts to open an index that already exists at the given path. If the index doesn't exist, it will return an error.
Parameters
path: The filesystem path where the existing index is located
Examples
iex> {:ok, index} = TantivyEx.Index.open("/tmp/existing_index")
iex> is_reference(index)
true
@spec open_or_create(String.t(), TantivyEx.Schema.t()) :: {:ok, t()} | {:error, String.t()}
Opens an existing index at the specified path, or creates it if it doesn't exist.
This is the recommended function for most use cases as it handles both opening existing indices and creating new ones with a single API call. The directory will be created if it doesn't exist.
Parameters
path: The filesystem path where the index should be opened/createdschema: The schema defining the structure of documents (used only when creating)
Examples
iex> schema = TantivyEx.Schema.new()
iex> schema = TantivyEx.Schema.add_text_field(schema, "title", :text_stored)
iex> {:ok, index} = TantivyEx.Index.open_or_create("/tmp/my_index", schema)
iex> is_reference(index)
true
# Subsequent calls will open the existing index
iex> {:ok, same_index} = TantivyEx.Index.open_or_create("/tmp/my_index", schema)
iex> is_reference(same_index)
true