picky 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,7 +49,7 @@ module Picky
49
49
  ::File.open(cache_path, 'r:utf-8') do |file|
50
50
  file.each_line do |line|
51
51
  id, token = line.split ?,, 2
52
- yield id, (token.chomp! || token).to_sym
52
+ yield id, (token.chomp! || token).to_sym # TODO to_sym
53
53
  end
54
54
  end
55
55
  end
@@ -21,28 +21,28 @@ module Picky
21
21
  # [:token] # => [id, id, id, id, id] (an array of ids)
22
22
  #
23
23
  def create_inverted bundle
24
- extract_lambda_or(inverted, client, bundle) ||
24
+ extract_lambda_or(inverted, bundle, client) ||
25
25
  List.new(client, "#{bundle.identifier}:inverted")
26
26
  end
27
27
  # Returns an object that on #initial, #load returns an object that responds to:
28
28
  # [:token] # => 1.23 (a weight)
29
29
  #
30
30
  def create_weights bundle
31
- extract_lambda_or(weights, client, bundle) ||
31
+ extract_lambda_or(weights, bundle, client) ||
32
32
  Float.new(client, "#{bundle.identifier}:weights")
33
33
  end
34
34
  # Returns an object that on #initial, #load returns an object that responds to:
35
35
  # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
36
36
  #
37
37
  def create_similarity bundle
38
- extract_lambda_or(similarity, client, bundle) ||
38
+ extract_lambda_or(similarity, bundle, client) ||
39
39
  List.new(client, "#{bundle.identifier}:similarity")
40
40
  end
41
41
  # Returns an object that on #initial, #load returns an object that responds to:
42
42
  # [:key] # => value (a value for this config key)
43
43
  #
44
44
  def create_configuration bundle
45
- extract_lambda_or(configuration, client, bundle) ||
45
+ extract_lambda_or(configuration, bundle, client) ||
46
46
  String.new(client, "#{bundle.identifier}:configuration")
47
47
  end
48
48
 
@@ -112,13 +112,6 @@ module Picky
112
112
  end
113
113
  end
114
114
 
115
- # Generates a new index (writes its index) using the
116
- # partial caching strategy of this bundle.
117
- #
118
- def generate_partial
119
- generator = Generators::PartialGenerator.new self.inverted
120
- self.inverted = generator.generate self.partial_strategy
121
- end
122
115
  # Generate a partial index from the given exact inverted index.
123
116
  #
124
117
  def generate_partial_from exact_inverted_index
@@ -127,19 +120,24 @@ module Picky
127
120
  self.generate_partial
128
121
  self
129
122
  end
123
+
124
+ # Generates a new index (writes its index) using the
125
+ # partial caching strategy of this bundle.
126
+ #
127
+ def generate_partial
128
+ self.inverted = partial_strategy.generate_from self.inverted
129
+ end
130
130
  # Generates a new weights index (writes its index) using the
131
131
  # given weight caching strategy.
132
132
  #
133
133
  def generate_weights
134
- generator = Generators::WeightsGenerator.new self.inverted
135
- self.weights = generator.generate self.weights_strategy
134
+ self.weights = weights_strategy.generate_from self.inverted
136
135
  end
137
136
  # Generates a new similarity index (writes its index) using the
138
137
  # given similarity caching strategy.
139
138
  #
140
139
  def generate_similarity
141
- generator = Generators::SimilarityGenerator.new self.inverted
142
- self.similarity = generator.generate self.similarity_strategy
140
+ self.similarity = similarity_strategy.generate_from self.inverted
143
141
  end
144
142
 
145
143
  # Saves the indexes in a dump file.
@@ -32,7 +32,7 @@ module Picky
32
32
  def add_tokenized id, tokens
33
33
  tokens.each do |text|
34
34
  next unless text
35
- text = text.to_sym
35
+ text = text.to_sym # TODO to_sym
36
36
  exact.add id, text
37
37
  partial.add_partialized id, text
38
38
  end
@@ -7,6 +7,8 @@ module Picky
7
7
  # By default, all caches are saved in a
8
8
  # storage (like a file).
9
9
  #
10
+ # TODO Move to the backends?
11
+ #
10
12
  def saved?
11
13
  true
12
14
  end
data/lib/picky/loader.rb CHANGED
@@ -103,13 +103,6 @@ module Picky
103
103
  load_relative 'generators/similarity/soundex'
104
104
  load_relative 'generators/similarity/default'
105
105
 
106
- # Index generators.
107
- #
108
- load_relative 'generators/base'
109
- load_relative 'generators/partial_generator'
110
- load_relative 'generators/weights_generator'
111
- load_relative 'generators/similarity_generator'
112
-
113
106
  # Index store handling.
114
107
  #
115
108
  load_relative 'backends/helpers/file'
@@ -4,48 +4,52 @@ module Picky
4
4
 
5
5
  module Wrappers
6
6
 
7
- # This index combines an exact and partial index.
8
- # It serves to order the results such that exact hits are found first.
9
- #
10
- class ExactFirst < Bundle
11
-
12
- delegate :similar,
13
- :identifier,
14
- :name,
15
- :to => :@exact
16
- delegate :index,
17
- :category,
18
- :weight,
19
- :generate_partial_from,
20
- :generate_caches_from_memory,
21
- :generate_derived,
22
- :dump,
23
- :load,
24
- :to => :@partial
25
-
26
- def initialize category
27
- @exact = category.exact
28
- @partial = category.partial
29
- end
7
+ module Category
8
+
9
+ # This index combines an exact and partial index.
10
+ # It serves to order the results such that exact hits are found first.
11
+ #
12
+ class ExactFirst
13
+
14
+ delegate :similar,
15
+ :identifier,
16
+ :name,
17
+ :to => :@exact
18
+ delegate :index,
19
+ :category,
20
+ :weight,
21
+ :generate_partial_from,
22
+ :generate_caches_from_memory,
23
+ :generate_derived,
24
+ :dump,
25
+ :load,
26
+ :to => :@partial
27
+
28
+ def initialize category
29
+ @exact = category.exact
30
+ @partial = category.partial
31
+ end
30
32
 
31
- def self.wrap index_or_category
32
- if index_or_category.respond_to? :categories
33
- wrap_each_of index_or_category.categories
34
- index_or_category
35
- else
36
- new index_or_category
33
+ def self.wrap index_or_category
34
+ if index_or_category.respond_to? :categories
35
+ wrap_each_of index_or_category.categories
36
+ index_or_category
37
+ else
38
+ new index_or_category
39
+ end
40
+ end
41
+ def self.wrap_each_of categories
42
+ categories.categories.collect! { |category| new(category) }
37
43
  end
38
- end
39
- def self.wrap_each_of categories
40
- categories.categories.collect! { |category| new(category) }
41
- end
42
44
 
43
- def ids text
44
- @exact.ids(text) + @partial.ids(text)
45
- end
45
+ def ids text
46
+ @exact.ids(text) + @partial.ids(text)
47
+ end
48
+
49
+ def weight text
50
+ [@exact.weight(text) || 0, @partial.weight(text) || 0].max
51
+ end
46
52
 
47
- def weight text
48
- [@exact.weight(text) || 0, @partial.weight(text) || 0].max
49
53
  end
50
54
 
51
55
  end
@@ -3,10 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Picky::Adapters::Rack::LiveParameters do
6
-
6
+
7
7
  let(:live_parameters) { stub :live_parameters }
8
8
  let(:adapter) { described_class.new live_parameters }
9
-
9
+
10
10
  describe 'to_app' do
11
11
  it 'works' do
12
12
  lambda { adapter.to_app }.should_not raise_error
@@ -16,11 +16,11 @@ describe Picky::Adapters::Rack::LiveParameters do
16
16
  end
17
17
  it 'returned lambda should call parameters on the live parameters' do
18
18
  env = { 'rack.input' => 'some input' }
19
-
20
- live_parameters.should_receive(:parameters).once.with({})
21
-
19
+
20
+ live_parameters.should_receive(:parameters).once.with({}).and_return Hash.new
21
+
22
22
  adapter.to_app.call env
23
23
  end
24
24
  end
25
-
25
+
26
26
  end
@@ -11,7 +11,7 @@ describe Picky::Backends::Redis do
11
11
 
12
12
  @backend.stub! :timed_exclaim
13
13
  end
14
-
14
+
15
15
  describe 'create_...' do
16
16
  [
17
17
  [:inverted, Picky::Backends::Redis::Float],
@@ -27,17 +27,17 @@ describe Picky::Backends::Redis do
27
27
  end
28
28
  end
29
29
  end
30
-
30
+
31
31
  context 'with lambda options' do
32
32
  before(:each) do
33
- @backend = described_class.new inverted: ->(client, bundle){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:inverted)) },
34
- weights: ->(client, bundle){ Picky::Backends::Redis::String.new(client, bundle.identifier(:weights)) },
35
- similarity: ->(client, bundle){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:similarity)) },
36
- configuration: ->(client, bundle){ Picky::Backends::Redis::List.new(client, bundle.identifier(:configuration)) }
33
+ @backend = described_class.new inverted: ->(bundle, client){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:inverted)) },
34
+ weights: ->(bundle, client){ Picky::Backends::Redis::String.new(client, bundle.identifier(:weights)) },
35
+ similarity: ->(bundle, client){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:similarity)) },
36
+ configuration: ->(bundle, client){ Picky::Backends::Redis::List.new(client, bundle.identifier(:configuration)) }
37
37
 
38
38
  @backend.stub! :timed_exclaim
39
39
  end
40
-
40
+
41
41
  describe 'create_...' do
42
42
  [
43
43
  [:inverted, Picky::Backends::Redis::Float],
@@ -60,7 +60,7 @@ describe Picky::Backends::Redis do
60
60
 
61
61
  @backend.stub! :timed_exclaim
62
62
  end
63
-
63
+
64
64
  describe 'create_...' do
65
65
  [
66
66
  [:inverted, Picky::Backends::Redis::List],
@@ -89,42 +89,42 @@ describe Picky::Backends::Redis do
89
89
  # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
90
90
  # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
91
91
  # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
92
- #
92
+ #
93
93
  # @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
94
94
  # end
95
95
  # it "should intersect symbol_keys correctly" do
96
96
  # @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
97
97
  # @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
98
98
  # @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
99
- #
99
+ #
100
100
  # @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
101
101
  # end
102
102
  # it "should intersect correctly when intermediate intersect result is empty" do
103
103
  # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
104
104
  # @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
105
105
  # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
106
- #
106
+ #
107
107
  # @backend.ids(@combinations, :any, :thing).should == []
108
108
  # end
109
109
  # it "should be fast" do
110
110
  # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
111
111
  # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
112
112
  # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
113
- #
113
+ #
114
114
  # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
115
115
  # end
116
116
  # it "should be fast" do
117
117
  # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
118
118
  # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
119
119
  # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
120
- #
120
+ #
121
121
  # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
122
122
  # end
123
123
  # it "should be fast" do
124
124
  # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
125
125
  # @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
126
126
  # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
127
- #
127
+ #
128
128
  # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
129
129
  # end
130
130
  # end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Wrappers::ExactFirst do
3
+ describe Picky::Wrappers::Category::ExactFirst do
4
4
 
5
5
  before(:each) do
6
6
  @exact = stub :exact
@@ -16,10 +16,10 @@ describe Picky::Wrappers::ExactFirst do
16
16
  index = Picky::Index.new :some_index
17
17
  index.define_category :some_category
18
18
 
19
- Picky::Wrappers::ExactFirst.wrap index
19
+ described_class.wrap index
20
20
 
21
21
  index.categories.categories.each do |category|
22
- category.should be_kind_of(Picky::Wrappers::ExactFirst)
22
+ category.should be_kind_of(described_class)
23
23
  end
24
24
  end
25
25
  it "returns the index" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-30 00:00:00.000000000 Z
12
+ date: 2011-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70141614921940 !ruby/object:Gem::Requirement
16
+ requirement: &70176846773480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70141614921940
24
+ version_requirements: *70176846773480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70141614921380 !ruby/object:Gem::Requirement
27
+ requirement: &70176846773000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
31
31
  - !ruby/object:Gem::Version
32
- version: 3.3.1
32
+ version: 3.3.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70141614921380
35
+ version_requirements: *70176846773000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack
38
- requirement: &70141614920980 !ruby/object:Gem::Requirement
38
+ requirement: &70176846772620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70141614920980
46
+ version_requirements: *70176846772620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack_fast_escape
49
- requirement: &70141614920560 !ruby/object:Gem::Requirement
49
+ requirement: &70176846772200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70141614920560
57
+ version_requirements: *70176846772200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: text
60
- requirement: &70141614920140 !ruby/object:Gem::Requirement
60
+ requirement: &70176846771780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70141614920140
68
+ version_requirements: *70176846771780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
- requirement: &70141614919700 !ruby/object:Gem::Requirement
71
+ requirement: &70176846771360 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70141614919700
79
+ version_requirements: *70176846771360
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &70141614918940 !ruby/object:Gem::Requirement
82
+ requirement: &70176846770860 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70141614918940
90
+ version_requirements: *70176846770860
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &70141614916860 !ruby/object:Gem::Requirement
93
+ requirement: &70176846770360 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '3.0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70141614916860
101
+ version_requirements: *70176846770360
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: unicorn
104
- requirement: &70141614916340 !ruby/object:Gem::Requirement
104
+ requirement: &70176846769980 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70141614916340
112
+ version_requirements: *70176846769980
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sinatra
115
- requirement: &70141614908600 !ruby/object:Gem::Requirement
115
+ requirement: &70176846769520 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70141614908600
123
+ version_requirements: *70176846769520
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: redis
126
- requirement: &70141614908020 !ruby/object:Gem::Requirement
126
+ requirement: &70176846769100 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70141614908020
134
+ version_requirements: *70176846769100
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mysql
137
- requirement: &70141614907420 !ruby/object:Gem::Requirement
137
+ requirement: &70176846768680 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *70141614907420
145
+ version_requirements: *70176846768680
146
146
  description: Fast Ruby semantic text search engine with comfortable single field interface.
147
147
  email: florian.hanke+picky@gmail.com
148
148
  executables:
@@ -208,7 +208,6 @@ files:
208
208
  - lib/picky/generators/partial/postfix.rb
209
209
  - lib/picky/generators/partial/strategy.rb
210
210
  - lib/picky/generators/partial/substring.rb
211
- - lib/picky/generators/partial_generator.rb
212
211
  - lib/picky/generators/similarity/default.rb
213
212
  - lib/picky/generators/similarity/double_metaphone.rb
214
213
  - lib/picky/generators/similarity/metaphone.rb
@@ -216,12 +215,10 @@ files:
216
215
  - lib/picky/generators/similarity/phonetic.rb
217
216
  - lib/picky/generators/similarity/soundex.rb
218
217
  - lib/picky/generators/similarity/strategy.rb
219
- - lib/picky/generators/similarity_generator.rb
220
218
  - lib/picky/generators/strategy.rb
221
219
  - lib/picky/generators/weights/default.rb
222
220
  - lib/picky/generators/weights/logarithmic.rb
223
221
  - lib/picky/generators/weights/strategy.rb
224
- - lib/picky/generators/weights_generator.rb
225
222
  - lib/picky/helpers/measuring.rb
226
223
  - lib/picky/index.rb
227
224
  - lib/picky/index_indexed.rb
@@ -325,15 +322,12 @@ files:
325
322
  - spec/lib/generators/partial/none_spec.rb
326
323
  - spec/lib/generators/partial/postfix_spec.rb
327
324
  - spec/lib/generators/partial/substring_spec.rb
328
- - spec/lib/generators/partial_generator_spec.rb
329
325
  - spec/lib/generators/similarity/double_metaphone_spec.rb
330
326
  - spec/lib/generators/similarity/metaphone_spec.rb
331
327
  - spec/lib/generators/similarity/none_spec.rb
332
328
  - spec/lib/generators/similarity/phonetic_spec.rb
333
329
  - spec/lib/generators/similarity/soundex_spec.rb
334
- - spec/lib/generators/similarity_generator_spec.rb
335
330
  - spec/lib/generators/weights/logarithmic_spec.rb
336
- - spec/lib/generators/weights_generator_spec.rb
337
331
  - spec/lib/helpers/measuring_spec.rb
338
332
  - spec/lib/index_indexed_spec.rb
339
333
  - spec/lib/index_indexing_spec.rb
@@ -404,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
398
  version: '0'
405
399
  requirements: []
406
400
  rubyforge_project: http://rubyforge.org/projects/picky
407
- rubygems_version: 1.8.11
401
+ rubygems_version: 1.8.10
408
402
  signing_key:
409
403
  specification_version: 3
410
404
  summary: ! 'Picky: Semantic Search Engine. Clever Interface. Good Tools.'
@@ -451,15 +445,12 @@ test_files:
451
445
  - spec/lib/generators/partial/none_spec.rb
452
446
  - spec/lib/generators/partial/postfix_spec.rb
453
447
  - spec/lib/generators/partial/substring_spec.rb
454
- - spec/lib/generators/partial_generator_spec.rb
455
448
  - spec/lib/generators/similarity/double_metaphone_spec.rb
456
449
  - spec/lib/generators/similarity/metaphone_spec.rb
457
450
  - spec/lib/generators/similarity/none_spec.rb
458
451
  - spec/lib/generators/similarity/phonetic_spec.rb
459
452
  - spec/lib/generators/similarity/soundex_spec.rb
460
- - spec/lib/generators/similarity_generator_spec.rb
461
453
  - spec/lib/generators/weights/logarithmic_spec.rb
462
- - spec/lib/generators/weights_generator_spec.rb
463
454
  - spec/lib/helpers/measuring_spec.rb
464
455
  - spec/lib/index_indexed_spec.rb
465
456
  - spec/lib/index_indexing_spec.rb
@@ -1,19 +0,0 @@
1
- module Picky
2
-
3
- module Generators
4
-
5
- # The partial generator uses a subtoken(downto:1) generator as default.
6
- #
7
- class PartialGenerator < Base
8
-
9
- # Generate a partial index based on the given inverted index.
10
- #
11
- def generate strategy = Partial::Substring.new(from: 1)
12
- strategy.generate_from self.inverted
13
- end
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,19 +0,0 @@
1
- module Picky
2
-
3
- module Generators
4
-
5
- # Uses no similarity as default.
6
- #
7
- class SimilarityGenerator < Base
8
-
9
- # Generate a similarity index based on the given inverted index.
10
- #
11
- def generate strategy = Similarity::None.new
12
- strategy.generate_from self.inverted
13
- end
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,19 +0,0 @@
1
- module Picky
2
-
3
- module Generators
4
-
5
- # Uses a logarithmic algorithm as default.
6
- #
7
- class WeightsGenerator < Base
8
-
9
- # Generate a weights index based on the given inverted index.
10
- #
11
- def generate strategy = Weights::Logarithmic.new
12
- strategy.generate_from self.inverted
13
- end
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Picky::Generators::PartialGenerator do
4
-
5
- context 'integration' do
6
- it 'should generate the correct values with a given strategy' do
7
- generator = described_class.new :meier => [1], :maier => [2]
8
-
9
- generator.generate(Picky::Generators::Partial::Substring.new).should == {
10
- :meier => [1],
11
- :meie => [1],
12
- :mei => [1],
13
- :me => [1],
14
- :m => [1, 2],
15
- :maier => [2],
16
- :maie => [2],
17
- :mai => [2],
18
- :ma => [2]
19
- }
20
- end
21
- it 'should generate the correct values with a given specific strategy' do
22
- generator = described_class.new :meier => [1], :maier => [2]
23
-
24
- generator.generate(Picky::Generators::Partial::Substring.new(:from => 3)).should == {
25
- :meier => [1],
26
- :meie => [1],
27
- :mei => [1],
28
- :maier => [2],
29
- :maie => [2],
30
- :mai => [2]
31
- }
32
- end
33
- end
34
-
35
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Picky::Generators::SimilarityGenerator do
4
-
5
- context 'integration' do
6
- it 'should generate the correct values' do
7
- generator = described_class.new :anything_really
8
-
9
- generator.generate.should == {}
10
- end
11
- it 'should generate the correct values with a given strategy' do
12
- generator = described_class.new :meier => nil,
13
- :maier => nil,
14
- :mayer => nil,
15
- :meyer => nil,
16
- :peter => nil
17
-
18
- generator.generate(Picky::Generators::Similarity::DoubleMetaphone.new).should == { :MR => [:meier, :maier, :mayer, :meyer], :PTR => [:peter] }
19
- end
20
- end
21
-
22
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Picky::Generators::WeightsGenerator do
4
-
5
- context 'integration' do
6
- it 'should generate the correct values' do
7
- generator = described_class.new :a => Array.new(0),
8
- :b => Array.new(1),
9
- :c => Array.new(10),
10
- :d => Array.new(100),
11
- :e => Array.new(1000)
12
-
13
- result = generator.generate
14
-
15
- result[:c].should be_within(0.011).of(2.3)
16
- result[:d].should be_within(0.011).of(4.6)
17
- result[:e].should be_within(0.011).of(6.9)
18
- end
19
- end
20
-
21
- end