Advertisement
Guest User

Untitled

a guest
Aug 5th, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.97 KB | None | 0 0
  1. require 'mongoid'
  2. require 'tire'
  3. require 'pry'
  4.  
  5. Mongoid.configure do |config|
  6.   name = 'random_test'
  7.   host = 'localhost'
  8.   config.connect_to name
  9. end
  10.  
  11.  
  12.  
  13. class SomethingWithTag
  14.   include Mongoid::Document
  15.   include Mongoid::Timestamps
  16.   field :tags_array, type: Array
  17.   include Tire::Model::Search
  18.   include Tire::Model::Callbacks
  19.   mapping do
  20.     indexes :tags_array, type: :array, index: :not_analyzed
  21.   end
  22. end
  23.  
  24. Tire.index 'something_with_tags' do delete; create end
  25. SomethingWithTag.delete_all
  26.  
  27.  
  28. a = SomethingWithTag.new(tags_array: ["hello world"])
  29. a.save
  30.  
  31. sleep 1
  32.  
  33. puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello"] }.results.count
  34. puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["world"] }.results.count
  35. puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello", "world"] }.results.count
  36.  
  37. puts SomethingWithTag.tire.search { filter :terms, :tags_array => ["hello world"] }.results.count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement