思考Sphinx和范围的问题

时间:2010-11-24 16:52:34

标签: ruby-on-rails sphinx thinking-sphinx named-scope

现在几个小时我试图让sphinx示波器工作失败。

我想要范围ActsAsTaggableOn的标签。在我的模型中(可标记)我尝试了以下范围:

# This normal scope works
scope :tagged, lambda {
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
}

# fails! (can't convert ActiveRecord::Relation into Hash)
sphinx_scope :tagged do
  joins(:taggings => :tag).
  where("tags.name = 'consequatur'")
end

对旧条件的另一次尝试:

# works with normal scope (returns one record)
scope :tagged, :joins => :taggings, :conditions => {"taggings.tag_id" => 74}

# fails! (returns nothing)
sphinx_scope(:tagged) do
  {:joins => :taggings, :conditions => {"taggings.tag_id" => 74}}
end

如何使这些范围有效?是否有其他方式来存档该任务?我想只搜索那些用特定标签标记的模型。

0 个答案:

没有答案