Adds ActiveRecord-like query interface for Tire models
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
goodyear.gemspec

README.md

Goodyear

Adds ActiveRecord-like query interface to Tire.

Installation

Add this line to your application's Gemfile:

gem 'goodyear'

And then execute:

$ bundle

Or install it yourself as:

$ gem install goodyear

Usage

class SomeModel < Tire
    include Goodyear::ElasticQuery
end

Better persistence via dynamic attributes.

Including Goodyear::Persistence in your model means you don't have to worry about defining everything with Tire's #property method.

class SomeModel < Tire
    include Goodyear::ElasticQuery
    include Goodyear::Persistence
end

Query Builder

where()

SomeModel.where( published: true, topic: "goats")

or()

SomeModel.where(status: 'inactive').or.where( retired: true)

sort()

Orders results by field

SomeModel.where( published: true, name: "Candy").sort(:score, :desc)

fields()

Specify fields to include in results

SomeModel.where( published: true, name: "Candy").fields(:published, :name, :score)

first()

Sets size to 1 and fetches the first result. Returns SomeModel

SomeModel.where( published: true, name: "Candy").first

last()

Returns the last result

SomeModel.where( published: true).last

fetch()

Exectues the query and returns TireCollection

SomeModel.where( published: true).size(100).sort(:score, :desc)

routing(id)

Sets routing to id in search options and returns SomeModel

SomeModel.routing(10).where( published: true)

count

Sets search_type to 'count' in search options, fetches and returns total

SomeModel.where( published: true).count

search_options(options = {})

Sets search options. Overwrites previously set values

SomeModel.search_options(routing: 1, search_type: 'count').where( published: true).fetch

Scopes

Add chainable scopes just like you do in ActiveRecord.

class SomeModel
  include Tire::Model::Persistence
  include ActiveRecord::Callbacks
  include Goodyear::ElasticQuery
  include Goodyear::Persistence
...
  scope :published, -> { where published: true }
end

Facets

Terms facet

SomeModel.where(created_at: 1.year.ago).facet('top_users') { terms 'users', size: 50 }

Or maybe a date histogram facet:

SomeModel.facet('stats') { date :created_at, interval: "1m", 
                           pre_zone_adjust_large_interval: true, 
                           time_zone: "-0500"}

Query Filters

SomeModel.where(width: 10).filter(:range,  {height: { gte: 10, lte: 200} })

There's also a convenience method for Exists filters.

SomeModel.has_field?(:width).where(width:10)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request