jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
585 stars 228 forks source link

Help needed - Searching using Postgres full text search #374

Closed francescob closed 2 years ago

francescob commented 3 years ago

Hi, first of all thanks for the very nice work on this gem. I'm trying to implement a custom search using the pg_search gem (https://github.com/Casecommons/pg_search) which builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search. I'm defining my column like this:

title: { source: "LifeCycleMethod.title", searchable: true, cond: full_text},

and then defined the full_text method like this:

  def full_text
    ->(column, value)  do
      ::Arel::Nodes::SqlLiteral.new(LifeCycleMethod.full_text_search(value).to_sql)
    end

  end

but I'm getting this error:

ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: subquery must return only one column

The search scope alone is working correctly, so I think I'm probably using it wrong inside my Datatable class, and I hope you can help me

n-rodriguez commented 2 years ago

Why not using https://github.com/Casecommons/pg_search#pg_search_scope in get_raw_records?