【问题标题】:ThinkingSphinx Polymorphic relation problem | rails 3.1ThinkingSphinx 多态关系问题 |导轨 3.1
【发布时间】:2011-09-23 08:57:03
【问题描述】:

我无法使用 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

【问题讨论】:

    标签: ruby-on-rails-3.1 thinking-sphinx polymorphic-associations polymorphism


    【解决方案1】:

    正如 Twitter 上的回答,此问题已在 TS 的最新版本 2.0.7 中得到修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多