Hello guys, I''m pretty new to using AAF and am having a slight problem with using a condition. I have the following code @results = SupplierProduct.find_by_contents(params[:search], :conditions => [''area_id = ?'', @area]) and it seems the condition isn''t being applied. Does anyone have any pointers? Cheers, Alastair -- Posted via http://www.ruby-forum.com/.
On 8/26/06, Alastair Moore <rubyonrails at transmogrify.co.uk> wrote:> Hello guys, > > I''m pretty new to using AAF and am having a slight problem with using a > condition. I have the following code > > @results = SupplierProduct.find_by_contents(params[:search], :conditions > => [''area_id = ?'', @area]) > > and it seems the condition isn''t being applied. Does anyone have any > pointers? > > Cheers, > > AlastairI''m not sure if the find_by_contents method has a :contents parameter but even if it does, I''d personally do it just like this; @results = SupplierProduct.find_by_contents(params[:search] + " +area_id:#@area") cheers, Dave
On Sat, Aug 26, 2006 at 01:29:17AM +1000, David Balmain wrote:> On 8/26/06, Alastair Moore <rubyonrails at transmogrify.co.uk> wrote: > > Hello guys, > > > > I''m pretty new to using AAF and am having a slight problem with using a > > condition. I have the following code > > > > @results = SupplierProduct.find_by_contents(params[:search], :conditions > > => [''area_id = ?'', @area]) > > > > and it seems the condition isn''t being applied. Does anyone have any > > pointers? > > > > Cheers, > > > > Alastair > > I''m not sure if the find_by_contents method has a :contents parameter > but even if it does, I''d personally do it just like this; > > @results = SupplierProduct.find_by_contents(params[:search] + " > +area_id:#@area")that of course works if :area_id is an indexed field. If area_id is not indexed, the :conditions option can be used to limit the find call that retrieves the model instances via ActiveRecord. Note that you might get less results than expected when using :conditions, since AR filters records out that Ferret counted as a hit. correct usage: @results = SupplierProduct.find_by_contents(params[:search], {}, { :conditions => [] }) the first hash is for ferret-related options (like :limit, :offset and so on), the second for activeRecord options. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Jens Kraemer wrote:> that of course works if :area_id is an indexed field. > > If area_id is not indexed, the :conditions option can be used to limit > the find call that retrieves the model instances via ActiveRecord. Note > that you might get less results than expected when using :conditions, > since AR filters records out that Ferret counted as a hit. > > correct usage: > > @results = SupplierProduct.find_by_contents(params[:search], {}, { > :conditions => [] }) > > the first hash is for ferret-related options (like :limit, :offset and > so on), the second for activeRecord options. >Hi Jens and thanks for the help but I seem to be getting an error when I use the following - @results = MarketingProduct.find_by_contents(search_text, {}, :conditions => ''live = "t"'') I''m getting this error - You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.sort! #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:286:in `find_by_contents'' #{RAILS_ROOT}/app/controllers/marketing_controller.rb:21:in `results'' Any ideas what might be up? Thanks, Alastair -- Posted via http://www.ruby-forum.com/.
Hi! On Tue, Sep 05, 2006 at 09:49:29PM +0200, Alastair Moore wrote:> Jens Kraemer wrote: > > > that of course works if :area_id is an indexed field. > > > > If area_id is not indexed, the :conditions option can be used to limit > > the find call that retrieves the model instances via ActiveRecord. Note > > that you might get less results than expected when using :conditions, > > since AR filters records out that Ferret counted as a hit. > > > > correct usage: > > > > @results = SupplierProduct.find_by_contents(params[:search], {}, { > > :conditions => [] }) > > > > the first hash is for ferret-related options (like :limit, :offset and > > so on), the second for activeRecord options. > > > > Hi Jens and thanks for the help but I seem to be getting an error when I > use the following - > > @results = MarketingProduct.find_by_contents(search_text, {}, > :conditions => ''live = "t"'')that should read :conditions => [ "live=''t''" ] . the clause gets shifted from the array and ANDed with aaf''s own where clause, and any additional parameters get added to the conditions array that is the issued to ActiveRecord. But that doesn''t seem to be your exact problem... What version of aaf do you use ? From the line number that doesn''t seem to be latest trunk or the last version tagged stable ? cheers, Jens> I''m getting this error - > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.sort! > > #{RAILS_ROOT}/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:286:in > `find_by_contents'' > #{RAILS_ROOT}/app/controllers/marketing_controller.rb:21:in `results'' > > Any ideas what might be up? > > Thanks, > > Alastair > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk-- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66