Ruby on rails 使用多态关联的pg_搜索时出现的问题

Ruby on rails 使用多态关联的pg_搜索时出现的问题,ruby-on-rails,ruby-on-rails-3,postgresql,pg-search,Ruby On Rails,Ruby On Rails 3,Postgresql,Pg Search,我的模型具有以下范围: class Cloth < ActiveRecord::Base include Ownerable has_many :cloth_tags, :dependent => :destroy pg_search_scope :full_search, associated_against: { cloth_tags: [:name, :brand_name] }, against: [:name, :descr

我的模型具有以下范围:

class Cloth < ActiveRecord::Base
  include Ownerable
  has_many :cloth_tags, :dependent => :destroy

  pg_search_scope :full_search,
    associated_against: {
      cloth_tags: [:name, :brand_name]
    },
    against: [:name, :description],
    ignoring: :accents,
    using: {
      tsearch: {
        dictionary: "spanish",
        any_word: true
      }
    }

有什么线索吗?提前感谢

我是pg_搜索的作者和维护者

不幸的是,在纯SQL中不可能沿着这个方向遍历多态关联,因此使用pg_搜索不可能进行这种搜索

您可以做的一件事是计算来自其他记录的文本,并将其缓存到Cloth表上的一列,然后根据该列进行搜索。无论何时Cloth上的多态外键更改,还是所有者记录上的内容更改,都必须小心地更新它


希望我可以改进错误消息,这样它就不会那么混乱了。谢谢你指出这一点。

你能在这里帮助我吗:)谢谢你的pg_搜索,@nertzy:-)我不明白为什么不能在纯SQL中遍历多态关联。我想在这里集思广益,所以如果我说的是错的,请告诉我。在上面的例子中,我们不能将join留在
ownerable\u id=Cloth.id和ownerable\u type='Cloth'
上吗?我们可以获取模型与
model.reflections
的关联,并可以向您的
ForeignColumn
添加一个“join_on”方法,该方法可以返回
foos.id=blahs.ownerable\u id和blahs.ownerable\u type='foos'
,具体取决于关联类型。嗨,这里有什么新闻吗?
module Ownerable

  extend ActiveSupport::Concern

  included do
    belongs_to :owner, :polymorphic => true
  end