I have an application which relies heavily on the hstore type in postgres. The Issue I can't seem to get over is making the hstore searchable in sunspot. Here is some code I am working on

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

I have tried adding different types but nothing seems to work. Is this a feature not yet supported?

有帮助吗?

解决方案

Hstore is basically a hash it stores keys and values so all you have to do is iterate over the the keys and look them up.

Here is the working code:

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

hopefully in the future they'll have support for

hstore :properties
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top