Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'mongoid'
- require 'tire'
- require 'pry'
- Mongoid.configure do |config|
- name = 'random_test'
- host = 'localhost'
- config.connect_to name
- end
- class SomethingWithTag
- include Mongoid::Document
- include Mongoid::Timestamps
- field :tags_array, type: Array
- include Tire::Model::Search
- include Tire::Model::Callbacks
- mapping do
- indexes :tags_array, type: :array, index: :not_analyzed
- end
- end
- Tire.index 'something_with_tags' do delete; create end
- SomethingWithTag.delete_all
- a = SomethingWithTag.new(tags_array: ["hello world"])
- a.save
- sleep 1
- puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello"] }.results.count
- puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["world"] }.results.count
- puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello", "world"] }.results.count
- puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello world"] }.results.count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement