spec/cloud_sesame_spec.rb in CloudSesame-0.5.5 vs spec/cloud_sesame_spec.rb in CloudSesame-0.6.0

- old
+ new

@@ -1,163 +1,166 @@ -require 'spec_helper' -require 'ruby-prof' -require 'benchmark' +# require 'spec_helper' +# require 'ruby-prof' +# require 'benchmark' -describe CloudSesame do +# describe CloudSesame do - # AWS initializer - # ======================================================= - require 'yaml' - YAML.load_file('aws.yml').each do |key, value| - ENV["AWS_#{ key }"] = value - end +# # AWS initializer +# # ======================================================= +# require 'yaml' +# YAML.load_file('aws.yml').each do |key, value| +# ENV["AWS_#{ key }"] = value +# end - # Domain Initializer /config/initializers/cloudsearch.rb - # ======================================================= - require 'cloud_sesame' +# # Domain Initializer /config/initializers/cloudsearch.rb +# # ======================================================= +# require 'cloud_sesame' - CloudSesame::Domain::Client.configure do |config| - config.access_key = ENV['AWS_ACCESS_KEY_ID'] - config.secret_key = ENV['AWS_SECRET_ACCESS_KEY'] - end +# CloudSesame::Domain::Client.configure do |config| +# config.access_key = ENV['AWS_ACCESS_KEY_ID'] +# config.secret_key = ENV['AWS_SECRET_ACCESS_KEY'] +# end - # Usage Example - # ======================================================= - class Product - include CloudSesame +# # Usage Example +# # ======================================================= +# class Product +# include CloudSesame - def self.greeting - "hello world!" - end +# def self.greeting +# "hello world!" +# end - define_cloudsearch do - # Product CloudSesame Config - config.endpoint = ENV['AWS_ENDPOINT'] - config.region = ENV['AWS_REGION'] +# define_cloudsearch do +# # Product CloudSesame Config +# config.endpoint = ENV['AWS_ENDPOINT'] +# config.region = ENV['AWS_REGION'] - default_size 100 +# turn_on_cache - define_sloppiness 3 +# default_size 100 - define_fuzziness do - max_fuzziness 3 - min_char_size 6 - fuzzy_percent 0.17 - end +# define_sloppiness 3 - field :searchable_text, query: { weight: 2 } - field :description, query: true - field :tags , as: :text1, default: -> { "men" } +# define_fuzziness do +# max_fuzziness 3 +# min_char_size 6 +# fuzzy_percent 0.17 +# end - field :affiliate_advertiser_ext_id, facet: { size: 50 } - field :currency, facet: true - field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' } - field :manufacturer_name, facet: { size: 50 } - field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' } - field :category_string, facet: { sort: 'bucket', size: 10_000 } - field :created_at, default: -> { Time.now } +# field :searchable_text, query: { weight: 2 } +# field :description, query: true +# field :tags , default: -> { "men" } - end +# field :affiliate_advertiser_ext_id, facet: { size: 50 } +# field :currency, facet: true +# field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' } +# field :manufacturer_name, facet: { size: 50 } +# field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' } +# field :category_string, facet: { sort: 'bucket', size: 10_000 } +# field :created_at, default: -> { Time.now } - end +# end +# end - # @tags = [1, 2] - # n = 10_000 - # q = nil - # result = RubyProf.profile do - # n.times do - # q = Product.cloudsearch.query("black jacket").sort(price: :asc).page(1).size(1000) - # .price { gt 100 } - # .and { - # or! { - # tags *@tags - # tags - # tags nil - # and! { - # tags.not "3", "4" - # } - # and!.not { - # tags.start_with "5", "6" - # tags.not.start_with("7") - # tags.not.near("8", distance: 7) - # tags start_with("9"), near("10") - # tags term("11", boost: 2) - # tags.not phrase "12" - # } - # or!.not { - # price(25..100) - # price 100...200 - # price gte(200).lt(300) - # price gte(300) - # } - # or! { - # created_at Date.today - 7 - # created_at gte(Date.today) - # created_at gte(Date.today).lt(Date.today + 3) - # } - # } - # } - # q.applied_filters - # end - # end - # printer = RubyProf::FlatPrinter.new(result) - # printer.print(STDOUT, {}) +# # @tags = [1, 2] +# # n = 10_000 +# # q = nil +# # result = RubyProf.profile do +# # n.times do +# # q = Product.cloudsearch.query("black jacket").sort(price: :asc).page(1).size(1000) +# # .price { gt 100 } +# # .and { +# # or! { +# # tags *@tags +# # tags +# # tags nil +# # and! { +# # tags.not "3", "4" +# # } +# # and!.not { +# # tags.start_with "5", "6" +# # tags.not.start_with("7") +# # tags.not.near("8", distance: 7) +# # tags start_with("9"), near("10") +# # tags term("11", boost: 2) +# # tags.not phrase "12" +# # } +# # or!.not { +# # price(25..100) +# # price 100...200 +# # price gte(200).lt(300) +# # price gte(300) +# # } +# # or! { +# # created_at Date.today - 7 +# # created_at gte(Date.today) +# # created_at gte(Date.today).lt(Date.today + 3) +# # } +# # } +# # } - class Coupon - include CloudSesame +# # q.applied_filters - VALID_COUPON_RANK = 20 +# # end +# # end +# # printer = RubyProf::FlatPrinter.new(result) +# # printer.print(STDOUT, {}) - define_cloudsearch do - config.endpoint = ENV['AWS_ENDPOINT'] - config.region = ENV['AWS_REGION'] +# # class Coupon +# # include CloudSesame - default_size 10 +# # VALID_COUPON_RANK = 20 - define_sloppiness 3 +# # define_cloudsearch do +# # config.endpoint = ENV['AWS_ENDPOINT'] +# # config.region = ENV['AWS_REGION'] - define_fuzziness do - max_fuzziness 3 - min_char_size 6 - fuzzy_percent 0.17 - end +# # default_size 10 - field :end_date, as: :date1 - field :rank, as: :num1, default: -> { gte VALID_COUPON_RANK } - field :searchable_text, query: true - field :affiliate_advertiser_search_ext_id, as: :string1, facet: { size: 50 } - field :countries, as: :string_array1 - field :deal_types, as: :string_array2, facet: {} - field :tags, as: :string_array3, facet: {} - field :type, default: -> { 'Catalog::CouponSearchable' } - end +# # define_sloppiness 3 - end +# # define_fuzziness do +# # max_fuzziness 3 +# # min_char_size 6 +# # fuzzy_percent 0.17 +# # end - q = Coupon.cloudsearch.builder +# # field :end_date, as: :date1 +# # field :rank, as: :num1, default: -> { gte VALID_COUPON_RANK } +# # field :searchable_text, query: true +# # field :affiliate_advertiser_search_ext_id, as: :string1, facet: { size: 50 } +# # field :countries, as: :string_array1 +# # field :deal_types, as: :string_array2, facet: {} +# # field :tags, as: :string_array3, facet: {} +# # field :type, default: -> { 'Catalog::CouponSearchable' } +# # end - binding.pry +# # end - # class ProductController +# # q = Coupon.cloudsearch.builder - # def load_userq - # @name = "scott" - # end +# # binding.pry - # def greeting - # "hello world!" - # end +# # class ProductController - # def search - # load_user - # q = Product.cloudsearch.and { - # binding.pry - # } - # end +# # def load_userq +# # @name = "scott" +# # end - # end +# # def greeting +# # "hello world!" +# # end - # test = ProductController.new - # test.search -end +# # def search +# # load_user +# # q = Product.cloudsearch.and { +# # binding.pry +# # } +# # end + +# # end + +# # test = ProductController.new +# # test.search +# end