Sha256: 78cbf76751ed43518aa42f8368572aa8b9aa1d044d87eb177fa2cc500cabb9da

Contents?: true

Size: 1.29 KB

Versions: 111

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
#
require 'spec_helper'

describe "Weights" do

  # This tests the weights option.
  #
  it 'can handle dynamic weights' do
    index = Picky::Index.new :dynamic_weights do
      category :text1, weight: Picky::Weights::Constant.new
      category :text2, weight: Picky::Weights::Constant.new(3.14)
      category :text3, weight: Picky::Weights::Dynamic.new { |str_or_sym| str_or_sym.size }
      category :text4 # Default
    end

    require 'ostruct'

    thing = OpenStruct.new id: 1, text1: "ohai", text2: "hello", text3: "world", text4: "kthxbye"
    other = OpenStruct.new id: 2, text1: "",     text2: "",      text3: "",      text4: "kthxbye"

    index.add thing
    index.add other

    try = Picky::Search.new index

    try.search("text1:ohai").allocations.first.score.should    == 0.0
    try.search("text2:hello").allocations.first.score.should   == 3.14
    try.search("text3:world").allocations.first.score.should   == 5
    try.search("text4:kthxbye").allocations.first.score.should == 0.693

    try_with_boosts = Picky::Search.new index do
      boost [:text1] => +7.65,
            [:text2] => +1.86
    end

    try_with_boosts.search("text1:ohai").allocations.first.score.should  == 7.65
    try_with_boosts.search("text2:hello").allocations.first.score.should == 5.00
  end

end

Version data entries

111 entries across 111 versions & 1 rubygems

Version Path
picky-4.31.3 spec/functional/dynamic_weights_spec.rb
picky-4.31.2 spec/functional/dynamic_weights_spec.rb
picky-4.31.1 spec/functional/dynamic_weights_spec.rb
picky-4.31.0 spec/functional/dynamic_weights_spec.rb
picky-4.30.0 spec/functional/dynamic_weights_spec.rb
picky-4.29.0 spec/functional/dynamic_weights_spec.rb
picky-4.28.1 spec/functional/dynamic_weights_spec.rb
picky-4.27.1 spec/functional/dynamic_weights_spec.rb
picky-4.27.0 spec/functional/dynamic_weights_spec.rb
picky-4.26.2 spec/functional/dynamic_weights_spec.rb
picky-4.26.1 spec/functional/dynamic_weights_spec.rb
picky-4.26.0 spec/functional/dynamic_weights_spec.rb
picky-4.25.3 spec/functional/dynamic_weights_spec.rb
picky-4.25.2 spec/functional/dynamic_weights_spec.rb
picky-4.25.1 spec/functional/dynamic_weights_spec.rb
picky-4.25.0 spec/functional/dynamic_weights_spec.rb
picky-4.24.0 spec/functional/dynamic_weights_spec.rb
picky-4.23.2 spec/functional/dynamic_weights_spec.rb
picky-4.23.1 spec/functional/dynamic_weights_spec.rb
picky-4.23.0 spec/functional/dynamic_weights_spec.rb