I could not create index with thinking_sphinx for the simple polymorphic schema below. (Note: I am able to create index from has_many models but I want to create my indexes from 'belongs_to' model (Comment).)
For simplicity, I created a sample project which has the schema:
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
My sample models and index are:
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
I have 1 article with 1 comment and 1 photo with 1 comment, for the test. The problem is I could not create index with ruby '1.9.2', rails '3.1.0' and thinking_sphinx '2.0.5'. Note, I tried creating index with both 0.99 and 2.0.1 beta releases of sphinx.
I also tried article.title and photo.title for the problematic line. Waiting for working answers.
The error:
(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
if I try with the code below:
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
I am getting t开发者_如何转开发he error below:
(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
As answered on Twitter, this is fixed in the latest release of TS, 2.0.7.
精彩评论