Sha256: b6ee3e828eb2c6cc5ef644aa6236a27b0bfbf5a5b1e0c15727e79ecba46d71b5

Contents?: true

Size: 1.81 KB

Versions: 101

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
#
require 'spec_helper'

describe 'Search#max_allocations' do

  it 'offers the option max_allocations' do
    index = Picky::Index.new :dynamic_weights do
      category :text1
      category :text2
    end

    index.add Struct.new(:id, :text1, :text2).new(1, 'hello world', 'hello world')

    try = Picky::Search.new index

    try.search('hello world').allocations.size.should == 4
    try.search('hello world').ids.should == [1,1,1,1]

    try_again = Picky::Search.new index do
      max_allocations 2
    end

    try_again.search('hello world').allocations.size.should == 2
    try_again.search('hello world').ids.should == [1,1]

    try_again.max_allocations 1

    try_again.search('hello world').allocations.size.should == 1
    try_again.search('hello world').ids.should == [1]
  end

  it 'gets faster' do
    index = Picky::Index.new :dynamic_weights do
      category :text1
      category :text2
      category :text3
      category :text4
    end

    thing = Struct.new :id, :text1, :text2, :text3, :text4
    index.add thing.new(1, 'hello world', 'hello world', 'hello world', 'hello world')
    index.add thing.new(2, 'hello world', 'hello world', 'hello world', 'hello world')
    index.add thing.new(3, 'hello world', 'hello world', 'hello world', 'hello world')
    index.add thing.new(4, 'hello world', 'hello world', 'hello world', 'hello world')
    index.add thing.new(5, 'hello world', 'hello world', 'hello world', 'hello world')
    index.add thing.new(6, 'hello world', 'hello world', 'hello world', 'hello world')

    try = Picky::Search.new index

    threshold = performance_of do
      try.search 'hello world'
    end

    try_again = Picky::Search.new index do
      max_allocations 1
    end

    performance_of do
      try_again.search 'hello world'
    end.should < (threshold*2/3)
  end

end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
picky-4.24.0 spec/functional/max_allocations_spec.rb
picky-4.23.2 spec/functional/max_allocations_spec.rb
picky-4.23.1 spec/functional/max_allocations_spec.rb
picky-4.23.0 spec/functional/max_allocations_spec.rb
picky-4.22.0 spec/functional/max_allocations_spec.rb
picky-4.21.2 spec/functional/max_allocations_spec.rb
picky-4.21.1 spec/functional/max_allocations_spec.rb
picky-4.21.0 spec/functional/max_allocations_spec.rb
picky-4.20.2 spec/functional/max_allocations_spec.rb
picky-4.20.1 spec/functional/max_allocations_spec.rb
picky-4.20.0 spec/functional/max_allocations_spec.rb
picky-4.19.7 spec/functional/max_allocations_spec.rb
picky-4.19.6 spec/functional/max_allocations_spec.rb
picky-4.19.5 spec/functional/max_allocations_spec.rb
picky-4.19.4 spec/functional/max_allocations_spec.rb
picky-4.19.3 spec/functional/max_allocations_spec.rb
picky-4.19.2 spec/functional/max_allocations_spec.rb
picky-4.19.1 spec/functional/max_allocations_spec.rb
picky-4.19.0 spec/functional/max_allocations_spec.rb
picky-4.18.0 spec/functional/max_allocations_spec.rb