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

Elasticsearch / Searchkick Itegration #352

Closed aximuseng closed 4 years ago

aximuseng commented 4 years ago

Recently upgraded from v 0.4 and also trying to integrate Elasticsearch. Seemed to work ok on v0.4 but breaks on v1.0.

Here is what I have:

  def get_raw_records
      query = params[:q].presence || "*"
      limit = params[:length].presence || "15"
      offset = params[:start].presence || nil

      # offset can't be 0 - breaks ElasticSearch

      offset = nil if offset == "0"

      policy_scope(Location).search(query, limit: limit, offset: offset)
#      policy_scope(Location).order(:location_category_id, :area_id)

  end

Searchkick ads a search method that returns your results. My controller now fails with:

undefined methodwhere' for #`

I am at the point that I may just build my own jbuilder structure to return the results and allow full control over the filters, pagnation etc.

I was going to start digging into the code but I am guessing ADR is chaining on a .where(... to the get_raw_records and obviously SearchKick does not like this.

n-rodriguez commented 4 years ago

I am guessing ADR is chaining on a .where(... to the get_raw_records and obviously SearchKick does not like this.

exactly

n-rodriguez commented 4 years ago

But you can implement your own adapter : https://github.com/jbox-web/ajax-datatables-rails/blob/master/lib/ajax-datatables-rails/orm/active_record.rb

n-rodriguez commented 4 years ago

Feel free to submit PR or ping me if you need help implementing the adapter.