给定架构:
create_table "letters", force: :cascade do |t|
t.string "title", limit: 255
t.text "content", limit: 16777215
t.date "issue_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "osha_id", limit: 4
t.string "status", limit: 255
end
指数/ letter_index.rb
ThinkingSphinx::Index.define :letter, :with => :real_time do
# fields
indexes title, :sortable => true
indexes content
indexes issue_date_as_string
# attributes
has status, :type => :string
has created_at, :type => :timestamp
has updated_at, :type => :timestamp
end
当我rake ts:regenerate
没有has status, :type => :string
行时,它会生成索引。
但是当我添加该行时,我会收到一些错误消息,其中最相关的似乎是
/home/tim/.rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in '<top (required)>'
Mysql2::Error: unknown column: 'status'
我对于错误试图告诉我的错误以及为什么它首先失败感到非常困惑。我错过了一些明显的东西吗?
[已编辑以添加更多信息]
完成错误输出(在转储数据库的内容之后):
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:93:in `rescue in query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:96:in `query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:73:in `execute'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:21:in `block (2 levels) in copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:39:in `block in take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/innertube-1.1.0/lib/innertube.rb:138:in `take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:37:in `take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:20:in `block in copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications.rb:164:in `block in instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications.rb:164:in `instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/logger.rb:3:in `log'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:19:in `copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:16:in `block in populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/relation/batches.rb:124:in `find_in_batches'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/querying.rb:9:in `find_in_batches'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:15:in `populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:3:in `populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:30:in `block in generate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:29:in `each'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:29:in `generate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/tasks.rb:28:in `block (2 levels) in <top (required)>'
/home/tim/.rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Mysql2::Error: unknown column: 'status'
/home/tim/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `_query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `block in query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `handle_interrupt'
/home/tim/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:121:in `results_for'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:88:in `query'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:73:in `execute'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:21:in `block (2 levels) in copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:39:in `block in take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/innertube-1.1.0/lib/innertube.rb:138:in `take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/connection.rb:37:in `take'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:20:in `block in copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications.rb:164:in `block in instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/notifications.rb:164:in `instrument'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/logger.rb:3:in `log'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/transcriber.rb:19:in `copy'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:16:in `block in populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/relation/batches.rb:124:in `find_in_batches'
/home/tim/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/querying.rb:9:in `find_in_batches'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:15:in `populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/real_time/populator.rb:3:in `populate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:30:in `block in generate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:29:in `each'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/rake_interface.rb:29:in `generate'
/home/tim/.rvm/gems/ruby-2.2.1/gems/thinking-sphinx-3.2.0/lib/thinking_sphinx/tasks.rb:28:in `block (2 levels) in <top (required)>'
/home/tim/.rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => ts:regenerate => ts:generate
(See full trace by running task with --trace)
进一步的无偿信息 - 这显示了我尝试过的各种事情,所有事情都因同一个unknown column
错误而失败:
ThinkingSphinx::Index.define :letter, :with => :real_time do
# fields
indexes title, :sortable => true
indexes content
#indexes issue_date
indexes issue_date_as_string # this one works!
#indexes status
#indexes status_as_string
#indexes osha_id
#indexes issue_date
# attributes
#has status, :type => :string
has created_at, :type => :timestamp
has updated_at, :type => :timestamp
end
*_as_string
方法只是在黑暗中拍摄:
模型/ letter.rb:
# experimental for thinking sphinx indexing on issue date
def issue_date_as_string
self.issue_date.to_s
end
def status_as_string
self.status.to_s
end
答案 0 :(得分:0)
欣赏所有额外的细节蒂姆。
我认为这里的问题与Thinking Sphinx中的一个错误有关,导致索引文件无法被ts:regenerate
正确清除,因此他们仍在使用旧架构(没有status
属性)。这意味着任何填充新数据的尝试都会遇到错误。
但是,我刚刚修复了这个bug,而Thinking Sphinx的v3.3.0版本包含了它。你可以升级(有no breaking changes)并查看是否能解决问题吗?