Skip to content

Commit

Permalink
+ more specs for the unique option
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed May 13, 2012
1 parent 72e7a2f commit 4306517
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions server/spec/functional/unique_ids_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,34 @@
index.add thing.new(6, 'hello world', 'hello world', 'hello world', 'hello world')

things = Picky::Search.new index
# things.search('hello', 100, 0).ids.should == [
# 6, 5, 4, 3, 2, 1,
# 6, 5, 4, 3, 2, 1,
# 6, 5, 4, 3, 2, 1,
# 6, 5, 4, 3, 2, 1
# ]
things.search('hello', 100, 0).ids.should == [
6, 5, 4, 3, 2, 1,
6, 5, 4, 3, 2, 1,
6, 5, 4, 3, 2, 1,
6, 5, 4, 3, 2, 1
]
things.search('hello', 100, 0, unique: true).ids.should == [
6, 5, 4, 3, 2, 1
]
end

it 'works' do
index = Picky::Index.new :non_unique do
category :text1
category :text2
end

thing = Struct.new :id, :text1, :text2
index.add thing.new(1, 'one', 'two one')
index.add thing.new(2, 'two', 'three')
index.add thing.new(3, 'three', 'one')

things = Picky::Search.new index
things.search('one', 20, 0).ids.should == [3,1,1]
things.search('one', 20, 0).allocations.to_s.should == '[[:non_unique, 0.693, 2, [[:text2, "one", "one"]], [3, 1]], [:non_unique, 0.0, 1, [[:text1, "one", "one"]], [1]]]'

things.search('one', 20, 0, unique: true).ids.should == [3,1]
things.search('one', 20, 0, unique: true).allocations.to_s.should == '[[:non_unique, 0.693, 2, [[:text2, "one", "one"]], [3, 1]]]'
end

end

0 comments on commit 4306517

Please sign in to comment.