Rodrigo Alvarez
2006-Oct-22 00:32 UTC
[Ferret-talk] Rails association and multiple indexes
Hi! If I have two models, Product and Manufacturer, of course Product belongs_to :manufacturer. A search engine would allow a user to look for a product by its name or manufacturer. Is it better to define a method like: def searchable_field "#{name} #{manufacturer.name}" end and add it as indexable field (acts_as_ferret :fields => [''searchable_field''])... Or maybe that it is more advisable to index different fields: Product < ActiveRecord::Base acts_as_ferret :fields => [''name'', ''manufacturer_name''] def manufacturer_name "#{manufacturer.name}" end end Thanks in advance. -- Posted via http://www.ruby-forum.com/.
On 10/22/06, Rodrigo Alvarez <papipo at gmail.com> wrote:> Hi! > > If I have two models, Product and Manufacturer, of course Product > belongs_to :manufacturer. > > A search engine would allow a user to look for a product by its name or > manufacturer. Is it better to define a method like: > > def searchable_field > "#{name} #{manufacturer.name}" > end > > and add it as indexable field (acts_as_ferret :fields => > [''searchable_field''])... > > Or maybe that it is more advisable to index different fields: > > Product < ActiveRecord::Base > acts_as_ferret :fields => [''name'', ''manufacturer_name''] > > def manufacturer_name > "#{manufacturer.name}" > end > end > > Thanks in advance.Hi Rodrigo, It''s better to index individual fields. You can easily search both fields like this: "name|manufacturer_name:(#{query})" I can''t really think of any advantages to putting buth fields into the one search field. -- Dave Balmain http://www.davebalmain.com/