picky 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,15 +13,20 @@ module Internals
13
13
  #
14
14
  class Basic
15
15
 
16
- attr_reader :namespace
16
+ attr_reader :namespace, :backend
17
17
 
18
18
  # An index cache takes a path, without file extension,
19
19
  # which will be provided by the subclasses.
20
20
  #
21
21
  def initialize namespace
22
22
  @namespace = namespace
23
-
24
- @backend = ::Redis.new
23
+
24
+ # TODO Turn this inside out such that people can pass in
25
+ # their own Redis instance.
26
+ #
27
+ # TODO Make the :db a real option.
28
+ #
29
+ @backend = ::Redis.new :db => 15
25
30
  end
26
31
 
27
32
  # Does nothing.
@@ -9,8 +9,9 @@ module Internals
9
9
  # Writes the hash into Redis.
10
10
  #
11
11
  def dump hash
12
+ redis = backend
12
13
  hash.each_pair do |key, value|
13
- @backend.hset namespace, key, value
14
+ redis.hset namespace, key, value
14
15
  end
15
16
  end
16
17
 
@@ -23,7 +24,7 @@ module Internals
23
24
  # Get a single value.
24
25
  #
25
26
  def member sym
26
- @backend.hget namespace, sym
27
+ backend.hget namespace, sym
27
28
  end
28
29
 
29
30
  end
@@ -20,7 +20,7 @@ module Internals
20
20
  # Delegate to the right collection.
21
21
  #
22
22
  def ids sym
23
- @index.collection sym
23
+ index.collection sym
24
24
  end
25
25
 
26
26
  # Delegate to the right member value.
@@ -28,13 +28,13 @@ module Internals
28
28
  # Note: Converts to float.
29
29
  #
30
30
  def weight sym
31
- @weights.member(sym).to_f
31
+ weights.member(sym).to_f
32
32
  end
33
33
 
34
34
  # Delegate to a member value.
35
35
  #
36
36
  def setting sym
37
- @configuration.member sym
37
+ configuration.member sym
38
38
  end
39
39
 
40
40
  end
@@ -32,10 +32,6 @@ module Sources
32
32
  options[:precision] || 1
33
33
  end
34
34
 
35
- def reset
36
- @min = 1.0/0
37
- end
38
-
39
35
  # Yield the data (id, text for id) for the given type and category.
40
36
  #
41
37
  def harvest type, category
@@ -45,9 +45,9 @@ describe Indexing::Indexes do
45
45
  indexes.should_receive(:find).once.with(:index, :category).and_return @index1
46
46
  end
47
47
  it 'indexes' do
48
- @index1.should_receive(:index).once.with
48
+ @index1.should_receive(:generate_caches).once.with
49
49
 
50
- indexes.generate_index_only :index, :category
50
+ indexes.generate_cache_only :index, :category
51
51
  end
52
52
  end
53
53
  context 'with index not found' do
@@ -55,9 +55,9 @@ describe Indexing::Indexes do
55
55
  indexes.should_receive(:find).once.with(:index, :category).and_return nil
56
56
  end
57
57
  it 'indexes' do
58
- @index1.should_receive(:index).never
58
+ @index1.should_receive(:generate_caches).never
59
59
 
60
- indexes.generate_index_only :index, :category
60
+ indexes.generate_cache_only :index, :category
61
61
  end
62
62
  end
63
63
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Internals::Generators::Partial::None do
4
4
 
5
+ it 'is not saved' do
6
+ described_class.new.saved?.should == false
7
+ end
5
8
  it "has the right superclass" do
6
9
  described_class.should < Internals::Generators::Partial::Strategy
7
10
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Index::Redis::StringHash do
4
+
5
+ let(:index) { described_class.new :some_namespace }
6
+
7
+ describe 'collection' do
8
+ it 'raises' do
9
+ expect { index.collection :anything }.to raise_error("Can't retrieve a collection from a StringHash. Use Index::Redis::ListHash.")
10
+ end
11
+ end
12
+ describe 'member' do
13
+ before(:each) do
14
+ @backend = stub :backend
15
+ index.stub! :backend => @backend
16
+ end
17
+ it 'delegates to the backend' do
18
+ @backend.should_receive(:hget).once.with :some_namespace, :some_symbol
19
+
20
+ index.member :some_symbol
21
+ end
22
+ it 'returns whatever it gets from the backend' do
23
+ @backend.should_receive(:hget).any_number_of_times.and_return :some_result
24
+
25
+ index.member(:anything).should == :some_result
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Index::Redis do
4
+
5
+ let(:config) do
6
+ index = stub :index, :name => :some_index
7
+ category = stub :category, :name => :some_category
8
+ Configuration::Index.new index, category
9
+ end
10
+ let(:redis) { described_class.new :some_name, config }
11
+
12
+ describe 'setting' do
13
+ it 'delegates to the configuration' do
14
+ configuration = stub :configuration
15
+ redis.stub! :configuration => configuration
16
+
17
+ configuration.should_receive(:member).once.with :some_sym
18
+
19
+ redis.setting :some_sym
20
+ end
21
+ it 'returns the value' do
22
+ configuration = stub :configuration
23
+ redis.stub! :configuration => configuration
24
+
25
+ configuration.should_receive(:member).any_number_of_times.and_return "some config"
26
+
27
+ redis.setting(:any).should == "some config"
28
+ end
29
+ end
30
+ describe 'weight' do
31
+ it 'delegates to the weights' do
32
+ weights = stub :weights
33
+ redis.stub! :weights => weights
34
+
35
+ weights.should_receive(:member).once.with :some_sym
36
+
37
+ redis.weight :some_sym
38
+ end
39
+ it 'returns a floated value' do
40
+ weights = stub :weights
41
+ redis.stub! :weights => weights
42
+
43
+ weights.should_receive(:member).any_number_of_times.and_return "1.0"
44
+
45
+ redis.weight(:any).should == 1.0
46
+ end
47
+ it 'returns a floated value' do
48
+ weights = stub :weights
49
+ redis.stub! :weights => weights
50
+
51
+ weights.should_receive(:member).any_number_of_times.and_return 1
52
+
53
+ redis.weight(:any).should == 1.0
54
+ end
55
+ end
56
+ describe 'ids' do
57
+ it 'delegates to the index' do
58
+ index = stub :index
59
+ redis.stub! :index => index
60
+
61
+ index.should_receive(:collection).once.with :some_sym
62
+
63
+ redis.ids :some_sym
64
+ end
65
+ it 'returns the value' do
66
+ index = stub :index
67
+ redis.stub! :index => index
68
+
69
+ index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
70
+
71
+ redis.ids(:any).should == [1,2,3]
72
+ end
73
+ end
74
+ end
@@ -132,6 +132,27 @@ describe Internals::Query::Tokens do
132
132
  end
133
133
  end
134
134
 
135
+ describe 'possible_combinations_in' do
136
+ before(:each) do
137
+ @token1 = stub :token1
138
+ @token2 = stub :token2
139
+ @token3 = stub :token3
140
+
141
+ @tokens = described_class.new [@token1, @token2, @token3]
142
+ end
143
+ it 'should work correctly' do
144
+ @token1.should_receive(:possible_combinations_in).once.with(:some_index).and_return [:combination11, :combination12]
145
+ @token2.should_receive(:possible_combinations_in).once.with(:some_index).and_return [:combination21]
146
+ @token3.should_receive(:possible_combinations_in).once.with(:some_index).and_return [:combination31, :combination32, :combination33]
147
+
148
+ @tokens.possible_combinations_in(:some_index).should == [
149
+ [:combination11, :combination12],
150
+ [:combination21],
151
+ [:combination31, :combination32, :combination33]
152
+ ]
153
+ end
154
+ end
155
+
135
156
  describe 'to_s' do
136
157
  before(:each) do
137
158
  @tokens = described_class.new [
@@ -9,12 +9,12 @@ describe Sources::Wrappers::Location do
9
9
  end
10
10
  context "without grid option" do
11
11
  it "fails" do
12
- lambda { Sources::Wrappers::Location.new(:something) }.should raise_error
12
+ lambda { described_class.new(:something) }.should raise_error
13
13
  end
14
14
  end
15
15
  context "with grid option" do
16
16
  before(:each) do
17
- @wrapper = Sources::Wrappers::Location.new @category, grid:10
17
+ @wrapper = described_class.new @category, grid:10
18
18
  end
19
19
  it "uses a default of 1 on the precision" do
20
20
  @wrapper.precision.should == 1
@@ -39,7 +39,7 @@ describe Sources::Wrappers::Location do
39
39
  end
40
40
  context "with grid and precision option" do
41
41
  before(:each) do
42
- @wrapper = Sources::Wrappers::Location.new @category, grid:4, precision:2
42
+ @wrapper = described_class.new @category, grid:4, precision:2
43
43
  end
44
44
  it "uses the given precision" do
45
45
  @wrapper.precision.should == 2
@@ -60,7 +60,7 @@ describe Sources::Wrappers::Location do
60
60
  end
61
61
  context "without backend" do
62
62
  it "fails" do
63
- lambda { Sources::Wrappers::Location.new }.should raise_error(ArgumentError)
63
+ lambda { described_class.new }.should raise_error(ArgumentError)
64
64
  end
65
65
  end
66
66
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.4.3
5
+ version: 1.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 +01:00
13
+ date: 2011-03-03 00:00:00 +01:00
14
14
  default_executable: picky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: "0"
25
25
  type: :development
26
26
  version_requirements: *id001
27
- description: Fast Ruby small-text search engine with comfortable single field interface.
27
+ description: Fast Ruby semantic text search engine with comfortable single field interface.
28
28
  email: florian.hanke+picky@gmail.com
29
29
  executables:
30
30
  - picky
@@ -195,6 +195,8 @@ files:
195
195
  - spec/lib/internals/index/file/marshal_spec.rb
196
196
  - spec/lib/internals/index/file/text_spec.rb
197
197
  - spec/lib/internals/index/files_spec.rb
198
+ - spec/lib/internals/index/redis/string_hash_spec.rb
199
+ - spec/lib/internals/index/redis_spec.rb
198
200
  - spec/lib/internals/indexed/bundle/memory_spec.rb
199
201
  - spec/lib/internals/indexed/categories_spec.rb
200
202
  - spec/lib/internals/indexed/category_spec.rb
@@ -310,6 +312,8 @@ test_files:
310
312
  - spec/lib/internals/index/file/marshal_spec.rb
311
313
  - spec/lib/internals/index/file/text_spec.rb
312
314
  - spec/lib/internals/index/files_spec.rb
315
+ - spec/lib/internals/index/redis/string_hash_spec.rb
316
+ - spec/lib/internals/index/redis_spec.rb
313
317
  - spec/lib/internals/indexed/bundle/memory_spec.rb
314
318
  - spec/lib/internals/indexed/categories_spec.rb
315
319
  - spec/lib/internals/indexed/category_spec.rb