From f0db4bdf493eefce7d3ff6a45aa421cbb0ba338f Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 23 Jun 2025 16:34:12 -0500 Subject: [PATCH] Add controller example This shows how to search in a controller with pagination and render the results. --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 0ce97b6..4caf3f0 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,23 @@ Typesense.configuration = { } ``` +### Pagination & Search in a controller with Pagy + +```ruby +class ProductsController < ApplicationController + def index + # If `params[:q]` is blank, Typesense will automatically use "*" to return all documents + @pagy, @products = Product.search(params[:q], "name,description") + end +end +``` + +```erb +

Search results for <%= params[:q] %>

+<%= render @products %> +<%== pagy_nav(@pagy) if @pagy.pages > 1 %> +``` + ## Testing To run the test suite: