> ## Documentation Index
> Fetch the complete documentation index at: https://nikita-shkoda.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Fastest path to a working search: install, configure, define a model, and run your first query.

<Info>
  <strong>Prerequisites</strong>

  <ul>
    <li>Ruby 3.1+ and Rails 6.1+ in your host app</li>
    <li>A reachable Typesense node (host/port/protocol); default port is 8108</li>
    <li><code>TYPESENSE\_API\_KEY</code> set in your environment (never commit secrets)</li>
    <li>An existing Typesense collection and schema; see <a href="/projects/search-engine-for-typesense/v30/schema">Schema</a></li>
  </ul>
</Info>

<Steps>
  <Step title="Add gem to Gemfile">
    ```ruby theme={null}
    # Gemfile
    gem "search-engine-for-typesense"
    ```

    Then run Bundler to install dependencies in your host app.
  </Step>

  <Step title="Run installer">
    ```bash theme={null}
    rails g search_engine:install
    ```

    This will create a new initializer in `config/initializers/search_engine.rb`.

    See <a href="/projects/search-engine-for-typesense/v30/dx#generators-%26-console-helpers">Generators & Console helpers</a> for more details.
  </Step>

  <Step title="Configure the initializer">
    ```ruby theme={null}
    # config/initializers/search_engine.rb
    SearchEngine.configure do |c|
      c.host = ENV.fetch("TYPESENSE_HOST", "localhost")
      c.port = 8108
      c.protocol = "http"
      c.api_key = ENV.fetch("TYPESENSE_API_KEY")
      c.default_query_by = "name, description"
    end
    ```

    * <code>host</code>/<code>port</code>/<code>protocol</code>: where your Typesense node is reachable; defaults are safe for localhost.
    * <code>api\_key</code>: read from <code>ENV.fetch("TYPESENSE\_API\_KEY")</code> so secrets never live in code.
    * <code>default\_query\_by</code>: default fields used when you do not pass <code>query\_by</code> explicitly.

    See <a href="/projects/search-engine-for-typesense/v30/configuration">Configuration</a> for all options and ENV mapping.
  </Step>

  <Step title="Define a minimal model">
    ```ruby theme={null}
    class SearchEngine::Book < SearchEngine::Base
      collection "books"
      attribute :id, :integer
      attribute :title, :string
    end

    SearchEngine::Book.where(title: "ruby").select(:id, :title).limit(5).to_a
    ```

    Ensure your Typesense <code>books</code> collection exists with at least <code>id</code> (int64) and <code>title</code> (string).

    You can also use a <a href="/projects/search-engine-for-typesense/v30/dx#generators-%26-console-helpers">Generator</a> to create a new model:

    ```bash theme={null}
    rails g search_engine:model Book --collection books --attrs id:integer title:string
    ```

    This will create a new model in `app/models/search_engine/book.rb`.
  </Step>

  <Step title="Index data (optional convenience)">
    You can let the model orchestrate schema and indexing:

    ```ruby theme={null}
    # Create collection + apply schema if needed, reindex, retention cleanup
    SearchEngine::Book.index_collection

    # Index a specific partition (collection must exist and be in-sync)
    SearchEngine::Book.index_collection(partition: publisher_id)
    ```

    See <a href="/projects/search-engine-for-typesense/v30/indexer#model-indexation-index_collection">Indexer</a> for details.
  </Step>

  <Step title="Rebuild a partition directly (optional)">
    For one-off reindexing by key, call the model-level helper:

    ```ruby theme={null}
    SearchEngine::Book.rebuild_partition!(partition: publisher_id)
    SearchEngine::Book.rebuild_partition!(partition: publisher_id, into: "optional_physical_collection")
    ```

    See <a href="/projects/search-engine-for-typesense/v30/indexer#partitioning">Indexer → Partitioning</a> for the partitioning DSL.
  </Step>

  <Step title="First query (curl-free)">
    Open <code>rails console</code> and paste the trailing line from the snippet above. It runs against Typesense
    and returns up to 5 <code>Book</code> records with only <code>id</code> and <code>title</code> hydrated. This uses the Relation → Client stack under the hood.
  </Step>
</Steps>

## Request flow

```mermaid theme={null}
sequenceDiagram
  autonumber
  participant App
  participant Relation
  participant Compiler
  participant Client
  participant Typesense

  App->>Relation: chain where/select/limit
  Relation->>Compiler: compile params
  Compiler->>Client: request(url, body, url_opts)
  Client->>Typesense: POST /collections/.../documents/search
  Typesense-->>Client: hits JSON
  Client-->>App: map → Results
```

## Next steps

* <a href="/projects/search-engine-for-typesense/v30/multi-search">Multi‑search</a>: run multiple searches in one network call.
* <a href="/projects/search-engine-for-typesense/v30/joins">JOINs</a>: join related collections and select nested fields.
* <a href="/projects/search-engine-for-typesense/v30/grouping">Grouping</a>: group results and aggregate with counts.

## Troubleshooting

* Missing <code>TYPESENSE\_API\_KEY</code>: set the ENV var before boot; see
  <a href="/projects/search-engine-for-typesense/v30/configuration#env-mapping">Configuration → ENV mapping</a>. Tip: the CLI doctor checks this.
* Connection refused or timeout: verify <code>host</code>/<code>port</code>/<code>protocol</code>; see the
  <a href="/projects/search-engine-for-typesense/v30/cli#doctor-flow">CLI → Doctor</a>.
* Unknown field errors: declare attributes on the model or adjust selection; see
  <a href="/projects/search-engine-for-typesense/v30/field-selection#guardrails-errors">Field selection → Guardrails</a>.

## Related links

* <a href="/projects/search-engine-for-typesense/v30/installation">Installation</a>
* <a href="/projects/search-engine-for-typesense/v30/configuration">Configuration</a>
* <a href="/projects/search-engine-for-typesense/v30/client">Client</a>
* <a href="/projects/search-engine-for-typesense/v30/observability">Observability</a> — events, logging subscriber, OpenTelemetry
* <a href="/projects/search-engine-for-typesense/v30/dx">DX</a> — helpers: <code>dry\_run!</code>, <code>to\_params\_json</code>, <code>to\_curl</code>
* <a href="/projects/search-engine-for-typesense/v30/relation">Relation</a> — chaining DSL used above
