Using Litesearch breaks app

I have a Rails 7.2 app that is using Litestack. Everything works as it should but if I add Litesearch to my models and deploy to fly, the app crashes and I get this error in my logs:

2024-10-31T14:03:36.706 app[2874ee9b556578] dfw [info] /usr/local/bundle/ruby/3.3.0/bundler/gems/litestack-d0cc274f099d/lib/litestack/litesearch/model.rb:63:in `litesearch': undefined method `search_index' for an instance of SQLite3::Database (NoMethodError)
2024-10-31T14:03:36.706 app[2874ee9b556578] dfw [info] idx = get_connection.search_index(index_name) do |schema|
2024-10-31T14:03:36.706 app[2874ee9b556578] dfw [info] ^^^^^^^^^^^^^

If I comment out the Litesearch code (below) from my model and redeploy, the app works again.

  include Litesearch::Model
  litesearch do |schema|
    schema.fields [ :content ]
    schema.tokenizer :porter
  end

Has anyone encountered this before? How did you resolve it? Any input would be greatly appreciated!

After much trial and error, I finally got this resolved. Here’s what I did to get Litesearch to work:

  1. set LITESTACK_DATA_PATH="/data" in my Dockerfile

  2. update my database.yml file to:

    # SQLite. Versions 3.8.0 and up are supported.
    #   gem install sqlite3
    #
    #   Ensure the SQLite 3 gem is defined in your Gemfile
    #   gem "sqlite3"
    #
    # `Litesupport.root.join("data.sqlite3")` stores
    # application data in the path `./db/#{Rails.env}/data.sqlite3`
    #
    # `Litesupport.root(env).join(path)` stores
    # application data in the path `./db/#{env}/#{path}`
    #
    # idle_timeout should be set to zero, to avoid recycling sqlite connections
    # and losing the page cache
    #
    default: &default
      adapter: litedb
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      idle_timeout: 0
      database: <%= Litesupport.root.join("data.sqlite3") %>
    
    development:
      <<: *default
    
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      <<: *default
    
    # Warning: Make sure your production database path is on a persistent
    # volume, otherwise your application data could be deleted between deploys.
    #
    # You may also set the Litesupport.root in production via the
    # `LITESTACK_DATA_PATH` environment variable.
    production:
      <<: *default
    
  3. remove DATABASE_URL = 'sqlite3:///data/production.sqlite3' from my fly.toml file

Hopefully this helps someone else.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.