用 sunspot 索引 jsonb 字段

indexing jsonb fields with sunspot

如何使用 sunspot 在 jsonb 字段中索引我需要的字段? 我有模特男:

 #<Man id: 1, name: "John Doe", type: "Man", r_id: "5734", fields: {"message"=>"hello world!", "sex"=>2, "uid"=>5734, "domain"=>"www.old-man.com"}, created_at: "2018-07-12 12:44:07", updated_at: "2018-07-12 12:44:07">

所以,我试图指示这样的可搜索字段:

  searchable do
      text :fields, stored: true
    end

它会索引所有字段。 但是如何将字段中的字段"message"指定为可搜索字段呢?

来自 gem documentation:

searchable do
  text :title, :body
  text :comments do
    comments.map { |comment| comment.body }
  end
  ...
end

这对你不起作用?

searchable do
  text :fields do
    fields["message"]
  end
end