Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save apavlyut/11401101 to your computer and use it in GitHub Desktop.
Save apavlyut/11401101 to your computer and use it in GitHub Desktop.
require 'tire'
require 'nobrainer'
NoBrainer.connect 'rethinkdb://server/company'
class Employee
include NoBrainer::Document
field :name
field :title
field :bio
# has_many :jobs
after_save do
employee = self
Tire.index 'bios' do
delete
create
store employee
refresh
end
end
validates :name, :presence => true
def to_indexed_json
{:name => self.name, :title => self.title, :bio => self.bio}.to_json
end
end
# pry or main or usage or whatever below
tony = Employee.create(name: 'Tony Tates', title: 'Gossip Dragon', bio: 'Pie is great.')
s = Tire.search('bios') do
query do
string 'pie'
end
end
# => [<Item name: "Tony Tates", title: "Gossip Dragon", bio: "Pie is great.",
# id: "519062d7cb759b91a3000001", _score: 0.11506981, _type: "document",
# _index: "bios", _version: nil, sort: nil, highlight: nil, _explanation: nil>]
# rad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment