Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with rails 4.1 #158

Closed
morgoth opened this issue Feb 19, 2014 · 3 comments
Closed

Doesn't work with rails 4.1 #158

morgoth opened this issue Feb 19, 2014 · 3 comments

Comments

@morgoth
Copy link

morgoth commented Feb 19, 2014

I have simple definitiion in my rails app:

class User < AR
  include PgSearch
  pg_search_scope :full_name_search, against: [:first_name, :last_name]
end

When I run:

User.full_name_search("stefan").count

I get error:

   (0.6ms)  SELECT COUNT("users".*, ((ts_rank((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))), (to_tsquery('simple', ''' ' || 'stefan' || ' ''')), 0))) AS pg_search_rank) FROM "users"  WHERE (((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'stefan' || ' '''))))
PG::SyntaxError: ERROR:  syntax error at or near "AS"
LINE 1: ...uery('simple', ''' ' || 'stefan' || ' ''')), 0))) AS pg_sear...
                                                             ^
: SELECT COUNT("users".*, ((ts_rank((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))), (to_tsquery('simple', ''' ' || 'stefan' || ' ''')), 0))) AS pg_search_rank) FROM "users"  WHERE (((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'stefan' || ' '''))))
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  syntax error at or near "AS"
LINE 1: ...uery('simple', ''' ' || 'stefan' || ' ''')), 0))) AS pg_sear...
                                                             ^
: SELECT COUNT("users".*, ((ts_rank((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))), (to_tsquery('simple', ''' ' || 'stefan' || ' ''')), 0))) AS pg_search_rank) FROM "users"  WHERE (((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'stefan' || ' '''))))
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `async_exec'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `block in exec_no_cache'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `exec_no_cache'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:947:in `select'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:31:in `select_all'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/connection_adapters/abstract/query_cache.rb:69:in `select_all'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/relation/calculations.rb:254:in `execute_simple_calculation'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/relation/calculations.rb:216:in `perform_calculation'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/relation/calculations.rb:111:in `calculate'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.1.0.rc1/lib/active_record/relation/calculations.rb:26:in `count'
    from (irb):6
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/console.rb:90:in `start'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/console.rb:9:in `start'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/wojtek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'

It might be related to rails/rails#13648

@morgoth
Copy link
Author

morgoth commented Feb 19, 2014

Working example of SQL query in rails 4.0:

User.full_name_search("stefan").count
   (1.7ms)  SELECT COUNT(*) FROM "users" WHERE (((to_tsvector('simple', coalesce("users"."first_name"::text, '')) || to_tsvector('simple', coalesce("users"."last_name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'stefan' || ' '''))))
=> 3

@amarshall
Copy link
Contributor

Seems like a possible duplicate of #153.

@morgoth
Copy link
Author

morgoth commented Feb 20, 2014

After investigation, I found that this was bug in will_paginate gem (which I was using altogether with pg_search). I was trying to fix internals of will_paginate, but it was to hard :-( - I switched to kaminari and all is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants