ankane / searchjoy

Search analytics made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Searchkick Conversions

philjeffs opened this issue · comments

I'm trying to feed the conversions feature of Searchkick (https://github.com/ankane/searchkick#keep-getting-better) with Searchjoy data.

I'm tracking searches with the track: true convenience method, which is working great:

@podcasts = Podcast.search(params[:q], track: true)

But, I don't see anything in the documentation on how to add Searchjoy data to the Searchkick index. The Searchkick docs recommend creating a Search model but that already exists inside Searchjoy.

I'm using the follow which seems to work fine:

  def search_data
    {
      title: title,
      summary: summary,
      conversions: Searchjoy::Search.where(convertable_id: self.id).where(convertable_type: "Podcast").group("query").count
    }
  end

Is this correct or should I be using the polymorphic association (convertable) to connect my model to Searchjoy::Search?

I added this association, which seems a lot cleaner. Works well. A lot cleaner than the previous approach:

  has_many :searches, as: :convertable, class_name: "Searchjoy::Search"