У меня есть приложение, в котором мне нужно реализовать функцию граненого поиска в одном из полей связанных моделей, и оно, похоже, не работает.Вот краткий контекст: есть 3 модели, над которыми я работаю: 1. Продукт 2. Атрибуты 3. ProductAttributes.Пожалуйста, смотрите код spnippets ниже:
class Product < ActiveRecord::Base
...
has_many :attribute_products
has_many :attributes, :through => :attribute_products, :class_name => 'Attribute'
has_one :brand, :class_name => "ProductAttribute", :conditions => "product_attributes.attribute_id IN (Select id from attributes where name = 'Brand')"
has_one :model, :class_name => "ProductAttribute", :conditions => "product_attributes.attribute_id IN (Select id from attributes where name = 'Model')"
....
define_index do
indexes :name
indexes description
indexes brand(:attribute_value), :as => :brand, :facet => true
indexes model(:attribute_value), :as => :model, :facet => true
has product_category_id, :type => :integer, :facet => true
where "products.online = 1 AND products.product_category_id IN (SELECT id FROM product_categories WHERE product_categories.parent_category_id IS NOT NULL)"
end
...
end
-----------------------------------------------------------------------
class AttributeProduct < ActiveRecord::Base
# => Since attribute is already taken, renaming the association method to prod_attr
belongs_to :attribute,
belongs_to :product
...
end
------------------------------------------------------------------
class Attribute < ActiveRecord::Base
has_many :attribute_products
has_many :products, :through => :attribute_products
....
end
------------------------------------------------------------------
Я определил соотношение 1: 1 между «продуктом» и «брендом» и между «продуктом» и «моделью».Затем я определяю индексы для обоих и делаю их фасетами.
Теперь в модели Продукта поиск по марке возвращает результаты, но поиск по названию модели не возвращает никакого результата.1008 * В моем понимании «модельный» контент индексируется.Результаты приведены ниже:
Product.facets(:conditions => {:brand => "Calvin"})
{:model=>{"U2716"=>7}, :product_category_id=>{6=>1, 2=>6}, :cost=>{1=>3, 2=>4}, :brand=>{"Calvin Klein"=>7}}
---------------------------------------------------------------------
>> Product.facets(:conditions => {:model => "U2716"})
{:model=>{}, :product_category_id=>{}, :cost=>{}, :brand=>{}}
Не знаете, что мне не хватает?