Search code examples
mysqlruby-on-railssolrsunspot

JRuby on Rails and Solr indexing


I am having trouble with indexing in Rails with JRuby and Sunspot. I have an additional database that contains reference data, and a model associated with one of the tables. This is what my database.yml looks like:

# regular stuff
# ...
# reference database
snomed:
  adapter: jdbcmysql
  encoding: utf8
  hostname: localhost
  database: snomedct
  username: user
  password: pass
  socket: /tmp/mysql.sock
  pool: 5
  timeout: 5000

And this is what my model for that database looks like:

class SnomedMaster < ActiveRecord::Base

  establish_connection "snomed"
  self.table_name = "curr_description_f"

  attr_accessible :effectivetime, :active, :moduleid, :conceptid, :languagecode, :typeid, :term, :casesignificanceid 

  searchable do
    text :term
  end

end

However, when I try to index the fields by running SnomedMaster.index in rails console or rake sunspot:reindex, it does not work. The problem seems to be here (from the trace log):

SELECT `curr_description_f`.* FROM `curr_description_f` WHERE (`curr_description_f`.`` >= 0) ORDER BY `curr_description_f`.`` ASC LIMIT 50
ActiveRecord::JDBCError: Unknown column 'curr_description_f.' in 'where clause': SELECT  `curr_description_f`.* FROM `curr_description_f`  WHERE (`curr_description_f`.`` >= 0) ORDER BY `curr_description_f`.`` ASC LIMIT 50

I don't know why sunspot wants to access column *curr_description_f*...

Thanks


Solution

  • Solved it on my own. The WHERE clause wants to call:

    WHERE (`curr_description_f`.`id` >= 0)
    

    Basically, because of the malformed sqldump, my database had a string id for primary key, and the key wasn't even assigned to my model. That's why it was empty. So I re-created the tables with INT as a primary key, and then added an additional line to my model:

    self.primary_key = "id"