【问题标题】:Postgres hstore and Rails sunspot solrPostgres hstore 和 Rails 太阳黑子 solr
【发布时间】:2013-10-23 04:28:54
【问题描述】:

我有一个严重依赖于 postgres 中的 hstore 类型的应用程序。我似乎无法克服的问题是使 hstore 在太阳黑子中可搜索。这是我正在处理的一些代码

class Post < ActiveRecord::Base 
  # properties is type hstore
  %w[price condition website].each do |key| 
    store_accessor :properties, key 
  end 
 ... 
  searchable :auto_index => false, :auto_remove => false do 
    text :title, :boost => 5.0 
    integer :category 
    integer :subcategory 
    # this is whats giving me the problem
    string :properties["price"] 
  end
end

我尝试添加不同的类型,但似乎没有任何效果。这是一个还不支持的功能吗?

【问题讨论】:

    标签: ruby-on-rails postgresql solr sunspot-rails sunspot-solr


    【解决方案1】:

    Hstore 基本上是一个散列,它存储键和值,因此您所要做的就是遍历键并查找它们。

    这是工作代码:

    searchable :auto_index => false, :auto_remove => false do 
      text :title, :boost => 5.0 
      integer :category 
      integer :subcategory 
      %w[price condition website].each do |key|
        string key.to_sym do
          properties[key]
        end
      end
    end
    

    希望将来他们会支持

    hstore :properties
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 2014-03-29
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多