Search code examples
ruby-on-railsruby-on-rails-3indextank

URI::InvalidURIError bad URI(is not URI?): using Tanker


I am using IndexTank and the Tanker gem to implement full text search on my Rails application, but I get an error (URI::InvalidURIError bad URI(is not URI?)) when trying to use the search_tank method on my index.

This is the controller method where I get the error

def search
  if params[:query]
    @posts = Post.search_tank(params[:query], :page => 1, :per_page => 10)
  else
    @posts = []
  end
end

This is the part of my Post model where I define the index

if ENV['RAILS_ENV'] === "production"
    index = 'idx'
else
    index = 'test'
end

tankit index do
    indexes :title
    indexes :description
end

# define the callbacks to update or delete the index
after_save :update_tank_indexes
after_destroy :delete_tank_indexes

The search_tank method works when I test it in the rails console. Other posts seem to suggest that this might be related to the routes set in config/routes.rb. All I have set is this.

root :to => 'public#index'
match ':controller(/:action(/:id))(.:format)'

I have searched around for an answer but I am a bit stumped. Any help would be greatly appreciated.


Solution

  • That's a URI.parse exception, it means some url is incorrectly specified or generated. Are you sure you set up the config correctly? From the readme at https://github.com/kidpollo/tanker you need to do:

    Initialization

    If you’re using Rails, config/initializers/tanker.rb is a good place for this:

    YourAppName::Application.config.index_tank_url = 'http://:[email protected]'
    

    If you are not using rails you can put this somewhere before you load your models

    Tanker.configuration = {:url => 'http://:[email protected]' }
    

    You would probably want to have fancier configuration depending on your environment. Be sure to copy and paste the correct url provided by the IndexTank Dashboard

    If you've already done that, please double check the urls for typos.