Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pat/ts-datetime-delta

Manage delta indexes via datetime columns for Thinking Sphinx
https://github.com/pat/ts-datetime-delta

Last synced: about 7 hours ago
JSON representation

Manage delta indexes via datetime columns for Thinking Sphinx

Awesome Lists containing this project

README

        

h1. Datetime Deltas for Thinking Sphinx

h2. Installation

You'll need Thinking Sphinx 1.3.0 or later (v3 is now supported since the 2.0.0 release of this gem).

gem install ts-datetime-delta

In your Gemfile, you can use it like so:

gem 'ts-datetime-delta', '~> 2.0.1',

:require => 'thinking_sphinx/deltas/datetime_delta'

Or if you're still on Rails 2, then put this in your @environment.rb@ file with the rest of your gem dependencies:

config.gem 'ts-datetime-delta',

:lib => 'thinking_sphinx/deltas/datetime_delta'
:version => '>= 2.0.1'

No matter which version of Rails, you'll need to add the following line to the bottom of your @Rakefile@:

require 'thinking_sphinx/deltas/datetime_delta/tasks'

h2. Usage

For the indexes you want to use this delta approach, make sure you set that up in your index definition. For Thinking Sphinx v3, that'll look like this:

ThinkingSphinx::Index.define(:book,

:with => :active_record,
:delta => ThinkingSphinx::Deltas::DatetimeDelta
) do
# ...
end

But for Thinking Sphinx v1/v2, it belongs within your @define_index@ blocks:

define_index do

# ...

set_property :delta => :datetime
end

If you want to use a column other than @updated_at@, you can specify it using the @:column@ option. The same goes for the threshold, which defaults to one day.

Again, Thinking Sphinx v3 expects these options outside the block:

ThinkingSphinx::Index.define(:book,

:with => :active_record,
:delta => ThinkingSphinx::Deltas::DatetimeDelta,
:delta_options => {:threshold => 1.hour, :column => :changed_at}
) do
# ...
end

But Thinking Sphinx v1/v2 it goes within the @define_index@ block:

set_property :delta => :datetime,

:threshold => 1.hour,
:column => :changed_at

Then, while your Rails application is running, you'll need to run the delta indexing rake task regularly - as often as your threshold, allowing for some time for the indexing to actually happen.

For example, if you're going to run the delta indexing task every hour, I would recommend setting your threshold to 70 minutes.

To ensure this rake task is called regularly, it's best to set it up as a recurring task via cron or similar tools.

rake thinking_sphinx:index:delta

The shorthand version is:

rake ts:in:delta

h2. Contributors

* "W. Andrew Loe III":http://andrewloe.com/ - Environment variable for disabling merging.
* "Kirill Maximov":http://kirblog.idetalk.com - Handling nil timestamp column values for toggled checks.
* "Timo Virkkala":https://github.com/weetu - Thinking Sphinx v3 compatibility,fix for null timestamps.
* "Cedric Maion":https://github.com/cmaion - Fix for keeping custom options persisted.

h2. Copyright

Copyright (c) 2009-2014 Pat Allan, and released under an MIT Licence.