Using: Rails 3.1.1
I am trying to create a search engine in my application that browses a large database (apprx 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 this 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%')
Clues and troubleshooting:
This happens only for large search results, I have not been able to distinguish a number but it crashes when it should have returned 920 results but it does NOT crash when returning 6 results!
My conclusion of the above is either that it cannot keep all the 920 results in the memory OR that there is some type of row that makes it crash and the more results, the more likely it is that it will contain that type of row. I am leaning more towards the first conclusion.
I cannot troubleshoot it very well because it crashes (with the same error code) when I try to run:
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, am I having a memory type of problem? What can I do to trouble shoot this further and/or solve the problem?
Using: Mac OS X 10.7.2. 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'
Edit 2012-03-06 Additional trouble shooting:
I tried with
fp2 = FeededProduct.limit(60000)
to create a really big array of hits and it worked fine. So I guess that rules out my guess that the fp variable cannot hold a certain amount of items.
The core of the problem seems to be that if I use the:
fp = FeededProduct.where("name LIKE '%blue%' OR description LIKE '%blue%' OR category LIKE '%blue%'")
I cannot use the fp-variable for anything afterwards without the application crashing.
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' – Phiona