Arthur Chan
2009-Feb-02 01:27 UTC
simple_autocomplete and find: same inputs but diff order
I''ve used the the simple_autocomplete plugins to search a City tables with 2millions records. However, I modified the :order parameters of the "find" function in the plugin so that "San Francisco, US" will always pop up first. Something weird tho, whenever I restart the server, the suggestions are correct in the first time; but then the :order does not work. It is weird that the same inputs can generate different results. Is it something related to caching or any other clues? thanks!!! Arthur -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thomas R. Koll
2009-Feb-02 11:31 UTC
Re: simple_autocomplete and find: same inputs but diff order
Hi, could you post the relevant code where you change the behaviour of the find and :order ? cioa, tom On Feb 2, 2:27 am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> However, I modified the :order parameters of the "find" function in the > plugin so that "San Francisco, US" will always pop up first.-- Thomas R. "TomK32" Koll <> http://ananasblau.com just a geek trying to change the world http://github.com/TomK32 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Arthur Chan
2009-Feb-03 01:22 UTC
Re: simple_autocomplete and find: same inputs but diff order
Thomas r. Koll wrote:> Hi, > > could you post the relevant code where you change the behaviour of > the find and :order ? > > cioa, tom >Hi Tom, I modified the autocomplete_for function in autocomplete.rb <code> # arthur: override the find_order options find_options = { :conditions => [ "LOWER(#{method}) LIKE ?", ''%''+params[:q].to_s.downcase + ''%'' ], :order => options.delete(:find_order) || "#{method} ASC", # arthur, allow customization of find order :limit => options[:limit] || 10 }.merge!(options) # arthur, customize find methods find_method = find_options.delete(:find_method) if options[:find_method] @items = object.to_s.camelize.constantize.send(options[:find_method], params[:q].to_s.downcase, find_options) else @items = object.to_s.camelize.constantize.find(:all, find_options) end </code> Therefore, in my controller, <code> #autocomplete_for :city, :city, :limit => 15 autocomplete_for :city, :city, :limit => 10, :find_method => "autocomplete_for_ccr", :find_order => "priority DESC, AccentCity, country, region" do |items| items.map{|item| "#{item.ccr(:capitalize=>true)}|#{item.cr}|#{item.country}"}.join("\n") end </code> I supposed that the suggestions will be ordered by the priority field in my cities table, but it is not always true. On the other hand, I use jQuery autocomplete as the javascript plugins. Arthur -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Arthur Chan
2009-Feb-03 03:13 UTC
Re: simple_autocomplete and find: same inputs but diff order
More info for the problem: The plugins runs fine in development mode but production mode only! Thanks, Arthur -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thomas R. Koll
2009-Feb-03 16:20 UTC
Re: simple_autocomplete and find: same inputs but diff order
Hi, I dare to ask but is the data the same in dev and prod? A second thing, there''s a bit difference between merge and merge! please try without the ! And last but not least: I think these two lines are wrong, but I''m not sure what should be used for the if statement find_method = find_options.delete(:find_method) if options[:find_method] ciao, tom -- Thomas R. "TomK32" Koll <> http://ananasblau.com just a geek trying to change the world http://github.com/TomK32 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---