Usage: Rails 3.1.1
I am trying to create a search engine in my application that scans a large database (about 100,000 items) for string matches.
I am using the following:
fp = FeededProduct.where("name LIKE '%blue%' OR description LIKE '%blue%' OR category LIKE '%blue%'")
for the search query for "blue".
When I run the equivalent search phrase in MySQL, it works fine, but when I try to run it in rails, it shows:
NoMethodError: undefined method `fields' for nil:NilClass: SELECT `feeded_products`.* FROM `feeded_products` WHERE (name LIKE '%blue%' OR description LIKE '%blue%' OR category LIKE '%blue%')
Troubleshooting and troubleshooting:
This happens only for large search results, I could not distinguish the number, but it failed when it should return 920 results, but it did NOT crash when returning 6 results!
My conclusion from the foregoing is that it cannot store all the results of 920 in memory OR that there is some type of row that causes it to fall, and the more results, the more likely it will contain this type row. I am more inclined to the first conclusion.
I cannot fix it very well because when I try to fail (with the same error code):
raise fp.inspect
It also crashes for:
fp.each do |prod| begin puts 'Do nothing' rescue puts 'Something crashed' end
but it does NOT crash for:
raise fp.count.inspect
So I have a memory problem? What can I do to solve the problem further and / or solve the problem?
Use: Mac OS X 10.7.2. a lion
Database: InnoDB
Adapter: Mysql2 (don't know which version)
Stack
ActiveRecord::StatementInvalid (NoMethodError: undefined method fields' for nil:NilClass: SELECT feeded_products`.* FROM feeded_products WHERE (name LIKE '%blue%' OR description LIKE '%blue%' OR category LIKE '%blue%')): app/controllers/search_results_controller.rb:190:in `show'
Change 2012-03-06 Additional problem:
to create a really big array of hits and it worked great. Therefore, I suppose that excludes my assumption that the fp variable cannot contain a certain number of elements.
The core of the problem seems to be if I use:
fp = FeededProduct.where("name LIKE '%blue%' OR description LIKE '%blue%' OR category LIKE '%blue%'")
I cannot use the fp variable for anything afterwards without crashing the application.