Skip to content

Instantly share code, notes, and snippets.

@jodosha
Created April 3, 2012 14:24
Show Gist options
  • Save jodosha/2292395 to your computer and use it in GitHub Desktop.
Save jodosha/2292395 to your computer and use it in GitHub Desktop.
# Example #1: Person
person = Node.create({
type: 'person',
uri: 'http://people.com/people/23',
attrs: { birth_date: Time.parse('June 23, 1982').to_date }
})
Node.tire.search(load: true) { filter :range, 'attrs.birth_date' => { lte: Time.zone.now } }.size # => 0
# Example #2: Country
country = Node.create({
type: 'country',
key: 'IT',
attrs: { name: 'Italy' }
})
Node.tire.search(load: true) { filter :term, 'attrs.title' => 'Italy' }.size # => 0
class Node
include Mongoid::Document
include Tire::Model::Search
include Tire::Model::Callbacks
field :type
field :key
field :uri
field :attrs, type: Hash, default: {}
mapping do
indexes :id, index: :not_analized
indexes :type, analyzer: 'keyword'
indexes :key, analyzer: 'keyword'
indexes :uri, analyzer: 'keyword'
indexes :attrs, type: 'object'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment