Sha256: 25fcab7aa11a8e65ff6722431836f0686562d4ae09b46fec613aa3036c4c4724

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
#
require 'spec_helper'
require 'ostruct'

describe "Results" do

  let(:index1) { Picky::Index.new :results1 }
  let(:index2) { Picky::Index.new :results2 }
  let(:try) { Picky::Search.new index1, index2 }

  # Test the enumerator abilities.
  #
  it 'can enumerate through the allocations' do
    index1.category :text
    index2.category :text

    thing = OpenStruct.new id: 1, text: "ohai"
    other = OpenStruct.new id: 2, text: "ohai kthxbye"

    index1.add thing
    index1.add other
    index2.add thing

    # each
    #
    expected = [
      [2, 1],
      [1]
    ]
    try.search("text:ohai").each do |allocation|
      expected.shift.should == allocation.ids
    end

    # map
    #
    try.search("text:ohai").map(&:ids).should == [
      [2, 1],
      [1]
    ]
    try.search("text:ohai").map(&:score).should == [0.693, 0.0]
  end

  it 'can re-prepare with different parameters' do
    index1.category :text
    index2.category :text

    thing = OpenStruct.new id: 1, text: "ohai"
    other = OpenStruct.new id: 2, text: "ohai kthxbye"

    index1.add thing
    index1.add other
    index2.add thing

    results = try.search "text:ohai"
    results.ids.should == [2, 1, 1]

    results.prepare! nil, true
    results.ids.should == [2, 1]
    results.ids.object_id.should_not == results.ids.object_id # Not cached.
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

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