Skip to content

Commit

Permalink
! Redis realtime mode, + Lots of specs for Redis realtime
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Feb 7, 2013
1 parent 0fc0e34 commit 3375659
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/lib/picky/backends/redis.rb
Expand Up @@ -61,7 +61,7 @@ def create_configuration bundle
# [id] # => [:sym1, :sym2]
#
def create_realtime bundle
List.new client, "#{bundle.identifier}:realtime", realtime: realtime
List.new client, "#{PICKY_ENVIRONMENT}:#{bundle.identifier}:realtime", realtime: realtime
end

# Does the Redis version already include
Expand Down Expand Up @@ -137,7 +137,7 @@ def weight combinations
# else
# class << self
# def weight combinations
combinations.score
combinations.score
# end
# end
# end
Expand Down Expand Up @@ -217,7 +217,7 @@ def generate_intermediate_result_id
module Scripting
def ids combinations, amount, offset
identifiers = combinations.inject([]) do |identifiers, combination|
identifiers << "#{combination.identifier}"
identifiers << "#{PICKY_ENVIRONMENT}:#{combination.identifier}"
end

# Assume it's using EVALSHA.
Expand Down
224 changes: 224 additions & 0 deletions server/spec/functional/realtime_spec.rb
Expand Up @@ -473,5 +473,229 @@ def initialize id, title, author
end
end
end

context 'special index' do
let(:index) do
Picky::Index.new(:books) do
backend Picky::Backends::Redis.new(realtime: true)
key_format :to_s # TODO Make key format dependent on backend?
category :title
category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
end
end
let(:books) { Picky::Search.new index }

before(:each) do
index.add Book.new('one', 'Title', 'Author')
end

context 'single category updating' do
it 'finds the first entry' do
books.search('title:Titl').ids.should == ['one']
end

it 'allows removing a single category and leaving the others alone' do
index[:title].remove 'one'

books.search('Title').ids.should == []
books.search('Author').ids.should == ['one']
end

it 'allows adding a single category and leaving the others alone' do
index[:title].add Book.new('two', 'Newtitle', 'Newauthor')

books.search('Title').ids.should == ['one']
books.search('Newtitle').ids.should == ['two']

books.search('Author').ids.should == ['one']
books.search('Newauthor').ids.should == []
end

it 'allows replacing a single category and leaving the others alone' do
index[:title].replace Book.new('one', 'Replaced', 'Notindexed')

books.search('Title').ids.should == []
books.search('Replaced').ids.should == ['one']

books.search('Notindexed').ids.should == []
books.search('Author').ids.should == ['one']
end
end

context 'with partial' do
it 'finds the first entry' do
books.search('Titl').ids.should == ['one']
end

it 'allows removing something' do
index.remove "one"
end
it 'is not findable anymore after removing' do
books.search('Titl').ids.should == ['one']

index.remove "one"

books.search('Titl').ids.should == []
end

it 'allows adding something' do
index.add Book.new('two', 'Title2', 'Author2')
end
it 'is findable after adding' do
books.search('Titl').ids.should == ['one']

index.add Book.new('two', 'Title New', 'Author New')

books.search('Titl').ids.should == ['two', 'one']
end

it 'allows replacing something' do
index.replace Book.new('one', 'Title New', 'Author New')
end
it 'is findable after replacing' do
books.search('Ne').ids.should == []

index.replace Book.new('one', 'Title New', 'Author New')

books.search('Ne').ids.should == ['one', 'one']
end
it 'handles more complex cases' do
books.search('Ne').ids.should == []

index.replace Book.new('one', 'Title New', 'Author New')

books.search('title:Ne').ids.should == ['one']
end
it 'handles more complex cases' do
index.remove "one"

books.search('Titl').ids.should == []

index.replace Book.new('one', 'Title New', 'Author New')

books.search('title:Ne').ids.should == ['one']
end
end

context 'non-partial' do
it 'finds the first entry' do
books.search('Titl').ids.should == ['one']
end

it 'allows removing something' do
index.remove "one"
end
it 'is not findable anymore after removing' do
books.search('Titl').ids.should == ['one']

index.remove :one

books.search('Titl').ids.should == []
end

it 'allows adding something' do
index.add Book.new("two", "Title2", "Author2")
end
it 'is findable after adding' do
books.search('Titl').ids.should == ['one']

index.add Book.new("two", "Title New", "Author New")

books.search('Titl').ids.should == ['two', 'one']
end

it 'allows replacing something' do
index.replace Book.new("one", "Title New", "Author New")
end
it 'is findable after replacing' do
books.search('Ne').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('Ne').ids.should == ['one', 'one']
end
it 'handles more complex cases' do
books.search('Ne').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('title:Ne').ids.should == ['one']
end
it 'handles more complex cases' do
index.remove "one"

books.search('Titl').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('title:Ne').ids.should == ['one']
end
end

context 'similarity' do
it 'finds the first entry' do
books.search('Authr~').ids.should == ['one']
end

it 'allows removing something' do
index.remove "one"
end
it 'is not findable anymore after removing' do
books.search('Authr~').ids.should == ['one']

index.remove "one"

books.search('Authr~').ids.should == []
end

it 'allows adding something' do
index.add Book.new("two", "Title2", "Author2")
end
it 'is findable after adding' do
books.search('Authr~').ids.should == ['one']

index.add Book.new("two", "Title New", "Author New")

books.search('Authr~').ids.should == ['two', 'one']
end

it 'allows replacing something' do
index.replace Book.new("one", "Title New", "Author New")
end
it 'is findable after replacing' do
books.search('Nuw~').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('Nuw~').ids.should == ['one']
end
it 'handles more complex cases' do
books.search('Now~').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('author:Now~').ids.should == ['one']
end
it 'handles more complex cases' do
index.remove "one"

books.search('Athr~').ids.should == []

index.replace Book.new("one", "Title New", "Author New")

books.search('author:Athr~').ids.should == ['one']
end
it 'handles more complex cases' do
books.search('Athr~').ids.should == ['one']

index.replace Book.new("two", "Title New", "Author New")
index.add Book.new("three", "TTL", "AUTHR")

# Note: Allocations are [:two, :one], then [:three].
#
books.search('author:Athr~').ids.should == ['two', 'one', 'three']
end
end
end

end

0 comments on commit 3375659

Please sign in to comment.