Using pg_search 0.6.0 with will_paginate will encounter error "Cannot visit Arel::Nodes::InfixOperation"
Steps to reproduce:
- Run rails console
- In the console, run SomeModel.search('something').paginate(page: 1), in which the search result should return many enough records to trigger the pagination (default is returning 31 records above). The error will appear.
pg_search 0.6.0 has this problem, but 0.5.7 does not.
I am also having this issue, the only difference being I am not using will_paginate but kaminari instead. I'm not sure it is related to the pagination based on my test:
To reproduce:
In controller:
@results = PgSearch.multisearch(params[:query])
In view:
<%= @results.inspect %>
Error:
Cannot visit Arel::Nodes::InfixOperation
I'm having the same issue. Using Kaminari + pg_search 0.6.0.
I have the same problem. Just in rails console: ModelName.my_search(some_text)
So probably pagination gems are not a cause.
Same for me... Using kaminari reproduces exactly the same error. PostgreSQL 9.1 here.
My current configuration:
pg_search_scope :find_by_name, against: [:station_name], using: [:tsearch]
What I call inside controller:
Station.where(company_id: current_user.company.id).find_by_name("E401")
If called directly from Rails console this is the result query:
SELECT "stations".*, ((ts_rank((to_tsvector('simple', coalesce("stations"."station_name"::text, ''))), (to_tsquery('simple', ''' ' || 'E401' || ' ''')), 0))) AS pg_search_rank FROM "stations" WHERE (((to_tsvector('simple', coalesce("stations"."station_name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'E401' || ' ''')))) ORDER BY pg_search_rank DESC, "stations"."id" ASC
This search returns no elements. In the real worls scenario, I pass the resulting array to Kaminari do the dirty pagination job, which does the mess:
TypeError - Cannot visit Arel::Nodes::InfixOperation:
Thanks for the error report! As you may have noticed from the changelog, 0.6.0 is the first release in an attempt to move away from SQL string manipulation and replace the internals with pure Arel nodes.
I won't have a chance to dig into this issue until probably Friday at the earliest. When I do, I will be sure to add test coverage for the popular pagination libraries so that this sort of thing doesn't happen again in the future.
For now, I advise everyone to stick to 0.5.7. Thanks for the prompt reports, everyone, it really helps!
I am also having the same issue with 0.6.0. Here is a stack trace if this gives a clue:
arel (3.0.2) lib/arel/visitors/visitor.rb:25:in `rescue in visit'
arel (3.0.2) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.2) lib/arel/visitors/to_sql.rb:200:in `visit_Arel_Nodes_Grouping'
arel (3.0.2) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.2) lib/arel/visitors/to_sql.rb:200:in `visit_Arel_Nodes_Grouping'
arel (3.0.2) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.2) lib/arel/visitors/to_sql.rb:136:in `block in visit_Arel_Nodes_SelectCore'
arel (3.0.2) lib/arel/visitors/to_sql.rb:136:in `map'
arel (3.0.2) lib/arel/visitors/to_sql.rb:136:in `visit_Arel_Nodes_SelectCore'
arel (3.0.2) lib/arel/visitors/to_sql.rb:121:in `block in visit_Arel_Nodes_SelectStatement'
arel (3.0.2) lib/arel/visitors/to_sql.rb:121:in `map'
arel (3.0.2) lib/arel/visitors/to_sql.rb:121:in `visit_Arel_Nodes_SelectStatement'
arel (3.0.2) lib/arel/visitors/visitor.rb:19:in `visit'
arel (3.0.2) lib/arel/visitors/visitor.rb:5:in `accept'
arel (3.0.2) lib/arel/visitors/to_sql.rb:19:in `accept'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
activerecord (3.2.11) lib/active_record/querying.rb:38:in `block in find_by_sql'
activerecord (3.2.11) lib/active_record/explain.rb:40:in `logging_query_plan'
activerecord (3.2.11) lib/active_record/querying.rb:37:in `find_by_sql'
newrelic_rpm (3.5.5.38) lib/new_relic/agent/method_tracer.rb:491:in `block in find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
newrelic_rpm (3.5.5.38) lib/new_relic/agent/method_tracer.rb:240:in `trace_execution_scoped'
newrelic_rpm (3.5.5.38) lib/new_relic/agent/method_tracer.rb:486:in `find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
activerecord (3.2.11) lib/active_record/relation.rb:171:in `exec_queries'
activerecord (3.2.11) lib/active_record/relation.rb:160:in `block in to_a'
activerecord (3.2.11) lib/active_record/explain.rb:40:in `logging_query_plan'
activerecord (3.2.11) lib/active_record/relation.rb:159:in `to_a'
will_paginate (3.0.4) lib/will_paginate/active_record.rb:127:in `block in to_a'
will_paginate (3.0.4) lib/will_paginate/collection.rb:96:in `create'
will_paginate (3.0.4) lib/will_paginate/active_record.rb:126:in `to_a'
activerecord (3.2.11) lib/active_record/relation.rb:498:in `inspect'
app/views/web_site_searches/index.html.erb:10:in `_app_views_web_site_searches_index_html_erb__2371381435013224786_70156604222220'
We are also having the same problem - Cannot visit Arel::Nodes::InfixOperation
I've been able to minimize the issue. It's in a call to .count on the scope deep within will_paginate.
So it looks like across the board, counts are not working. I will look into this more soon.
This is the same issue as https://github.com/ernie/squeel/issues/122 and https://github.com/ernie/ransack/pull/127
I've written a fix and am working on getting it released.
This fix has been released in 0.6.1. Please let me know if it works. Thanks!
It works, thanks!