我无法使用thinking_sphinx为下面的简单多态模式创建索引。 (注意:我能够从has_many模型创建索引,但我想从'belongs_to'模型(注释)创建索引。)
为简单起见,我创建了一个具有架构的示例项目:
create_table "articles", :force => true do |t|
t.string "title"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "comments", :force => true do |t|
t.text "content"
t.integer "commentable_id"
t.string "commentable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "photos", :force => true do |t|
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
end
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Photo < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
define_index do
indexes commentable_type, :as => :commentable_type
has commentable_id, :type => :integer, :as => :commentable_id
indexes commentable.title
end
end
我有1篇文章,1条评论和1张带1条评论的照片,用于测试。问题是我无法使用ruby'1.9.2',rails'3.1.0'和thinking_sphinx'2.0.5'创建索引。注意,我尝试使用sphinx的0.99和2.0.1 beta版本创建索引。
我还尝试了article.title和photo.title来查找有问题的一行。等待工作答案。
错误:
(in /Users/mustafat/Desktop/xxx-meta/testlog)
Generating Configuration to /Users/mustafat/Desktop/xxx-meta/testlog/config/development.sphinx.conf
Sphinx 2.0.1-beta (r2792)
Copyright (c) 2001-2011, Andrew Aksyonoff
Copyright (c) 2008-2011, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/Users/mustafat/Desktop/xxx-meta/testlog/config/development.sphinx.conf'...
FATAL: no indexes found in config file '/Users/mustafat/Desktop/xxx-meta/testlog/config/development.sphinx.conf'
Failed to start searchd daemon. Check /Users/mustafat/Desktop/xxx-meta/testlog/log/searchd.log.
Failed to start searchd daemon. Check /Users/mustafat/Desktop/xxx-meta/testlog/log/searchd.log
如果我尝试使用以下代码:
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
define_index do
indexes commentable_type, :as => :commentable_type
has commentable_id, :type => :integer, :as => :commentable_id
indexes article.title
end
end
我收到以下错误:
(in /Users/mustafat/Desktop/xxx-meta/testlog)
Generating Configuration to /Users/mustafat/Desktop/xxx-meta/testlog/config/development.sphinx.conf
Sphinx 2.0.1-beta (r2792)
Copyright (c) 2001-2011, Andrew Aksyonoff
Copyright (c) 2008-2011, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/Users/mustafat/Desktop/xxx-meta/testlog/config/development.sphinx.conf'...
indexing index 'comment_core'...
ERROR: index 'comment_core': sql_range_query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `comments`.`id`, `comments`.`commentable_id` ORDER BY NULL' at line 1 (DSN=mysql://root:***@localhost:3306/xxx_testlog).
total 0 docs, 0 bytes
total 0.003 sec, 0 bytes/sec, 0.00 docs/sec
skipping non-plain index 'comment'...
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
Failed to start searchd daemon. Check /Users/mustafat/Desktop/xxx-meta/testlog/log/searchd.log.
Failed to start searchd daemon. Check /Users/mustafat/Desktop/xxx-meta/testlog/log/searchd.log
答案 0 :(得分:2)
正如在Twitter上所回答的那样,这在TS,2.0.7的最新版本中得到了修复。