ruby-on-railsactiverecordfull-text-searchthinking-sphinx

ThinkingSphinx & callback doesnt update index after creating record


# index
ThinkingSphinx::Index.define :review, with: :active_record do
  indexes title, sortable: true
  indexes body
  indexes author.username, as: :author, sortable: true

  has author_id, created_at, updated_at
end

# model
class Review < ApplicationRecord
  ...

  ThinkingSphinx::Callbacks.append(
    self, :behaviours => [:sql]
  )

end

The new record doesnt appear in the search, the indexes dont update themselves.
VIA: https://freelancing-gods.com/thinking-sphinx/v5/indexing.html#callbacks

When you delete a record, it disappears from the search, but I'm not sure if it has something to do with updating the index, since the index files do not change.

If I run an update through rake, the new entry appears in the search.
In another project, the indexes were updated through tasks in whenever.

Or basic SQL indexes don't know how to update the index when new records are added?

If so, then which is better to choose sql with deltas or real_time for a small project?

Sphinx 2.2.11-id64-release (95ae9a6)
rails (6.1.7.2) & PostgreSQL
thinking-sphinx (5.5.1)

Solution

  • https://github.com/pat/thinking-sphinx/blob/13d0db24ce14a45bc6757b79760bb341d0185360/lib/thinking_sphinx/callbacks/appender.rb#L26

    add_core_callbacks are only called on :destroy
    And it turns out I need to use sql with delta or real_time