2013-10-23 95 views
1

我有一個應用程序在很大程度上依賴於postgres中的hstore類型。我似乎無法解決的問題是讓hstore在黑子中搜索。這裏是我正在努力的一些代碼Postgres hstore和Rails太陽黑子solr

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 

我試過添加不同的類型,但似乎沒有任何工作。這是一個尚未支持的功能嗎?

回答

0

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 
支持