Matt.C.Wagner@wellsfargo.com
2006-Jan-06 17:09 UTC
[Rails] Help with TextSearch :all and MySQL
Hi, I really need help with making the ''searches_on :all'' in Duane Johnson''s TextSearch work with MySQL (not sure if it works with other db''s). http://wiki.rubyonrails.com/rails/pages/TextSearch I realize that there are other search packages out there. But this particular solution best fits my small needs of searching a small database. I''ve gotten it to work when specifying the specific table column names: searches_on :title :address :foobar But due to the nature of my application which switches primary db tables based on user choice, I really need the dynamism of ''searches_on :all'' to work so that search functionality works with any table (where column names differ). I''ve been studying the code of Duane''s ''search.rb'', but cannot find the bug that stops '':all'' from working. Can somebody please suggest a fix? Thank you! Matt -- Matt C. Wagner Information Security Analyst Network Intrusion Detection Security Operations Center Corporate Information Security Wells Fargo Bank
On Jan 6, 2006, at 10:09 AM, <Matt.C.Wagner@wellsfargo.com> <Matt.C.Wagner@wellsfargo.com> wrote:> Hi, > > I really need help with making the ''searches_on :all'' in Duane > Johnson''s > TextSearch work with MySQL (not sure if it works with other db''s). > > http://wiki.rubyonrails.com/rails/pages/TextSearch > > I realize that there are other search packages out there. But this > particular solution best fits my small needs of searching a small > database. > > I''ve gotten it to work when specifying the specific table column > names: > > searches_on :title :address :foobar > > But due to the nature of my application which switches primary db > tables > based on user choice, I really need the dynamism of ''searches_on :all'' > to work so that search functionality works with any table (where > column > names differ). > > I''ve been studying the code of Duane''s ''search.rb'', but cannot find > the > bug that stops '':all'' from working. > > Can somebody please suggest a fix? > > Thank you! > > Matt >Hi Matt, I''m not sure what the exact problem is, but I do have one suggestion: try removing the ''searches_on'' altogether and see if the default "just works". If I remember correctly, the searches_on was an afterthought because my particular need was to search everything automatically, like yours. If that doesn''t work, can you help me understand what''s happening (or not happening), e.g. logs or otherwise? It might help if you could send some query strings to the log, too--just to see what it''s doing underneath. Duane Johnson (canadaduane) http://blog.inquirylabs.com/
Matt.C.Wagner@wellsfargo.com
2006-Jan-06 18:02 UTC
[Rails] Help with TextSearch :all and MySQL
Duane Johnson wrote:> If that doesn''t work, can you help me understand what''s happening > (or not happening), e.g. logs or otherwise? It might help if you > could send some query strings to the log, too--just to see what it''s > doing underneath.Duane, Thanks for responding! Removing ''searches_on'' all together didn''t work. It gives this error: ----------------------------------- ArgumentError in Foobar#search wrong number of arguments (1 for 0) RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/lib/search.rb:18:in `type'' #{RAILS_ROOT}/lib/search.rb:18:in `searchable_fields'' #{RAILS_ROOT}/lib/search.rb:18:in `select'' #{RAILS_ROOT}/lib/search.rb:18:in `searchable_fields'' #{RAILS_ROOT}/lib/search.rb:55:in `search'' #{RAILS_ROOT}/app/controllers/foobar_controller.rb:58:in `search'' ----------------------------------- The only query showing my MySQL query log from this error is: SHOW FIELDS FROM foobar When I specify the fields for searches_on, the query log shows the additional query: SELECT * FROM foobar WHERE ((UCASE(title) LIKE ''%SEARCHSTRING%'' OR UCASE(name) LIKE ''%SEARCHSTRING%'' OR UCASE(blah) LIKE ''%SEARCHSTRING%'' If it matter, I''m using MySQL 5.0. But I don''t think that should matter here. Thank you Duane. Matt -- Matt C. Wagner Information Security Analyst Network Intrusion Detection Security Operations Center Corporate Information Security Wells Fargo Bank
On Jan 6, 2006, at 11:02 AM, <Matt.C.Wagner@wellsfargo.com> <Matt.C.Wagner@wellsfargo.com> wrote:> Duane Johnson wrote: >> If that doesn''t work, can you help me understand what''s happening >> (or not happening), e.g. logs or otherwise? It might help if you >> could send some query strings to the log, too--just to see what it''s >> doing underneath. > > Duane, > > Thanks for responding! > > Removing ''searches_on'' all together didn''t work. It gives this error: > > ----------------------------------- > ArgumentError in Foobar#search > > wrong number of arguments (1 for 0) > > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > > #{RAILS_ROOT}/lib/search.rb:18:in `type'' > #{RAILS_ROOT}/lib/search.rb:18:in `searchable_fields'' > #{RAILS_ROOT}/lib/search.rb:18:in `select'' > #{RAILS_ROOT}/lib/search.rb:18:in `searchable_fields'' > #{RAILS_ROOT}/lib/search.rb:55:in `search'' > #{RAILS_ROOT}/app/controllers/foobar_controller.rb:58:in `search'' > ----------------------------------- > > The only query showing my MySQL query log from this error is: > > SHOW FIELDS FROM foobar > > When I specify the fields for searches_on, the query log shows the > additional query: > > SELECT * FROM foobar WHERE ((UCASE(title) LIKE ''%SEARCHSTRING%'' OR > UCASE(name) LIKE ''%SEARCHSTRING%'' OR UCASE(blah) LIKE ''%SEARCHSTRING%'' >Is it causing an error because of the lack of closing parens?> If it matter, I''m using MySQL 5.0. But I don''t think that should > matter > here. >Not sure. I don''t think so either, though. Nothing special going on in the query. Just to make sure we''re on the same page, I''ve attached the latest search.rb file that I have. I think it''s slightly different from the one you''re using, because the error wasn''t on the same line. Could you check this one? Duane Johnson (canadaduane) http://blog.inquirylabs.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: search.rb Type: text/x-ruby-script Size: 3527 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060106/d0070c18/search.bin
Matt.C.Wagner@wellsfargo.com
2006-Jan-06 19:03 UTC
[Rails] Help with TextSearch :all and MySQL
Duane Johnson wrote:>> When I specify the fields for searches_on, the query log shows the >> additional query: >> >> SELECT * FROM foobar WHERE ((UCASE(title) LIKE ''%SEARCHSTRING%'' OR >> UCASE(name) LIKE ''%SEARCHSTRING%'' OR UCASE(blah) LIKE >> ''%SEARCHSTRING%'' > > Is it causing an error because of the lack of closing parens?Sorry, the lack of closing parens in the above query was my fault from when I was trying to sanitize the query before posting to the public. When the error occurs, MySQL does not even see the above search query. It only receives the SHOW FIELDS query. The above query is received when I specify the columns for searches_on (eg. ''searches_on :title :name :blah'' vs. ''searches_on :all'')> Just to make sure we''re on the same page, I''ve attached the latest > search.rb file that I have. I think it''s slightly different from the > one you''re using, because the error wasn''t on the same line. Could > you check this one?OK. I''m using this new ''search.rb'', but still get an error. My model has: ---------------------- require_dependency "search" class Foobar < ActiveRecord::Base end ---------------------- Here is the error: ---------------------- NoMethodError in Foobar#search undefined method `validate_options'' for Foobar:Class RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/bas e.rb:991:in `method_missing'' #{RAILS_ROOT}/lib/search.rb:50:in `search'' #{RAILS_ROOT}/app/controllers/foobar_controller.rb:58:in `search'' ---------------------- The error is the same with or without ''searches_on :all'' in the model file. Where do you have ''validate_options'' defined? Thanks Duane. Matt -- Matt C. Wagner Information Security Analyst Network Intrusion Detection Security Operations Center Corporate Information Security Wells Fargo Bank
Matt.C.Wagner@wellsfargo.com
2006-Jan-06 19:09 UTC
[Rails] Help with TextSearch :all and MySQL
Duane, When I comment-out the ''validate_options'' lines in self.search, it works. I''m relieved! :) The ''validate_options'' should still be fixed. But at least it works with ''searches_on :all'' or without it. After the ''validate_options'' problem is solved, it would be good to please update the ''search.rb'' code on the Rails wiki: http://wiki.rubyonrails.com/rails/pages/TextSearch Thank you very much for your help! Matt Wagner, Matt C. wrote:> Here is the error: > > ---------------------- > NoMethodError in Foobar#search > > undefined method `validate_options'' for Foobar:Class > > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > >c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/bas e.rb:991:in> `method_missing'' #{RAILS_ROOT}/lib/search.rb:50:in `search'' > #{RAILS_ROOT}/app/controllers/foobar_controller.rb:58:in `search'' > ---------------------- > > The error is the same with or without ''searches_on :all'' in the model > file. > > Where do you have ''validate_options'' defined?-- Matt C. Wagner Information Security Analyst Network Intrusion Detection Security Operations Center Corporate Information Security Wells Fargo Bank
On Jan 6, 2006, at 12:09 PM, <Matt.C.Wagner@wellsfargo.com> <Matt.C.Wagner@wellsfargo.com> wrote:> Duane, > > When I comment-out the ''validate_options'' lines in self.search, it > works. > > I''m relieved! :) > > The ''validate_options'' should still be fixed. But at least it works > with > ''searches_on :all'' or without it. > > After the ''validate_options'' problem is solved, it would be good to > please update the ''search.rb'' code on the Rails wiki: > > http://wiki.rubyonrails.com/rails/pages/TextSearch > > Thank you very much for your help! > > Matt > > > Wagner, Matt C. wrote: >> Here is the error: >> >> ---------------------- >> NoMethodError in Foobar#search >> >> undefined method `validate_options'' for Foobar:Class >> >> RAILS_ROOT: ./script/../config/.. >> Application Trace | Framework Trace | Full Trace >> >> > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > active_record/bas > e.rb:991:in >> `method_missing'' #{RAILS_ROOT}/lib/search.rb:50:in `search'' >> #{RAILS_ROOT}/app/controllers/foobar_controller.rb:58:in `search'' >> ---------------------- >> >> The error is the same with or without ''searches_on :all'' in the model >> file. >> >> Where do you have ''validate_options'' defined?Hi Matt, Thanks for your patience with this. I''m working from an older code base (Rails 0.13) and so there are some differences I didn''t expect. It turns out that validate_options is now part of the Hash class: http://dev.rubyonrails.org/changeset/2167 So you should be able to replace that call with options.assert_valid_keys(:keys, :go, :here) I''ll update the wiki. Thanks! Duane Johnson (canadaduane) http://blog.inquirylabs.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060106/a3754ac5/attachment.html