picky 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/picky/bundle.rb CHANGED
@@ -92,7 +92,7 @@ module Picky
92
92
  #
93
93
  def initialize_backends
94
94
  @inverted = @backend_inverted.initial
95
- @weights = @weight_strategy.saved? ? @backend_weights.initial : @weight_strategy
95
+ @weights = @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved? ? @weight_strategy : @backend_weights.initial
96
96
  @similarity = @backend_similarity.initial
97
97
  @configuration = @backend_configuration.initial
98
98
  @realtime = @backend_realtime.initial
@@ -102,11 +102,11 @@ module Picky
102
102
  # internal backend instance.
103
103
  #
104
104
  def empty
105
- @inverted = @backend_inverted.empty
106
- @weights = @weight_strategy.saved? ? @backend_weights.empty : @weight_strategy
107
- @similarity = @backend_similarity.empty
105
+ @inverted = @backend_inverted.empty
106
+ @weights = @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved? ? @weight_strategy : @backend_weights.empty
107
+ @similarity = @backend_similarity.empty
108
108
  @configuration = @backend_configuration.empty
109
- @realtime = @backend_realtime.empty
109
+ @realtime = @backend_realtime.empty
110
110
  end
111
111
 
112
112
  # Delete all index files.
@@ -115,10 +115,10 @@ module Picky
115
115
  @backend_inverted.delete if @backend_inverted.respond_to? :delete
116
116
  # THINK about this. Perhaps the strategies should implement the backend methods?
117
117
  #
118
- @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weight_strategy.saved?
118
+ @backend_weights.delete if @backend_weights.respond_to?(:delete) && @weight_strategy.respond_to?(:saved?) && @weight_strategy.saved?
119
119
  @backend_similarity.delete if @backend_similarity.respond_to? :delete
120
120
  @backend_configuration.delete if @backend_configuration.respond_to? :delete
121
- @backend_realtime.delete if @backend_realtime.respond_to? :delete
121
+ @backend_realtime.delete if @backend_realtime.respond_to? :delete
122
122
  end
123
123
 
124
124
  # Get a list of similar texts.
@@ -79,12 +79,12 @@ module Picky
79
79
  # Loads the weights index.
80
80
  #
81
81
  def load_weights
82
- self.weights = @backend_weights.load if @weight_strategy.saved?
82
+ self.weights = @backend_weights.load unless @weight_strategy.respond_to?(:saved?) && !@weight_strategy.saved?
83
83
  end
84
84
  # Loads the similarity index.
85
85
  #
86
86
  def load_similarity
87
- self.similarity = @backend_similarity.load if @similarity_strategy.saved?
87
+ self.similarity = @backend_similarity.load unless @similarity_strategy.respond_to?(:saved?) && !@similarity_strategy.saved?
88
88
  end
89
89
  # Loads the configuration.
90
90
  #
@@ -34,8 +34,8 @@ module Picky
34
34
  @backend_inverted.dump @inverted
35
35
  # THINK about this. Perhaps the strategies should implement the backend methods? Or only the internal index ones?
36
36
  #
37
- @backend_weights.dump @weights if @weight_strategy.saved?
38
- @backend_similarity.dump @similarity if @similarity_strategy.saved?
37
+ @backend_weights.dump @weights if @weight_strategy.respond_to?(:saved?) && @weight_strategy.saved?
38
+ @backend_similarity.dump @similarity if @similarity_strategy.respond_to?(:saved?) && @similarity_strategy.saved?
39
39
  @backend_configuration.dump @configuration
40
40
  @backend_realtime.dump @realtime
41
41
  end
data/lib/picky/search.rb CHANGED
@@ -19,7 +19,8 @@ module Picky
19
19
 
20
20
  include Helpers::Measuring
21
21
 
22
- attr_reader :indexes
22
+ attr_reader :indexes,
23
+ :ignore_unassigned
23
24
  attr_accessor :tokenizer,
24
25
  :boosts
25
26
 
@@ -44,7 +45,6 @@ module Picky
44
45
 
45
46
  @tokenizer ||= Tokenizer.searching # THINK Not dynamic. Ok?
46
47
  @boosts ||= Query::Boosts.new
47
- @ignore_unassigned = false if @ignore_unassigned.nil?
48
48
 
49
49
  self
50
50
  end
@@ -156,14 +156,14 @@ module Picky
156
156
  #
157
157
  # Example:
158
158
  # search = Search.new(books_index, dvd_index, mp3_index) do
159
- # ignore_unassigned_tokens true
159
+ # ignore_unassigned_tokens
160
160
  # end
161
161
  #
162
- # With this set to true, if in "Peter Flunder", "Flunder"
162
+ # With this set (to true), if in "Peter Flunder", "Flunder"
163
163
  # couldn't be assigned to any category, it will simply be
164
164
  # ignored. This is done for each categorization.
165
165
  #
166
- def ignore_unassigned_tokens value
166
+ def ignore_unassigned_tokens value = true
167
167
  @ignore_unassigned = value
168
168
  end
169
169
 
@@ -111,6 +111,39 @@ describe Picky::Search do
111
111
  end
112
112
  end
113
113
 
114
+ describe 'ignore_unassigned_tokens' do
115
+ let(:search) { described_class.new @index }
116
+ context 'by default' do
117
+ it 'is falsy' do
118
+ search.ignore_unassigned.should be_false
119
+ end
120
+ end
121
+ context 'set to nothing' do
122
+ before(:each) do
123
+ search.ignore_unassigned_tokens
124
+ end
125
+ it 'is truey' do
126
+ search.ignore_unassigned.should be_true
127
+ end
128
+ end
129
+ context 'set to true' do
130
+ before(:each) do
131
+ search.ignore_unassigned_tokens true
132
+ end
133
+ it 'is truey' do
134
+ search.ignore_unassigned.should be_true
135
+ end
136
+ end
137
+ context 'set to false' do
138
+ before(:each) do
139
+ search.ignore_unassigned_tokens false
140
+ end
141
+ it 'is falsy' do
142
+ search.ignore_unassigned.should be_false
143
+ end
144
+ end
145
+ end
146
+
114
147
  describe 'initializer' do
115
148
  context 'with tokenizer' do
116
149
  before(:each) 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: 4.0.0
4
+ version: 4.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70136859666820 !ruby/object:Gem::Requirement
16
+ requirement: &70196698946200 !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: *70136859666820
24
+ version_requirements: *70196698946200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70136859665980 !ruby/object:Gem::Requirement
27
+ requirement: &70196698945640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 4.0.0
32
+ version: 4.0.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70136859665980
35
+ version_requirements: *70196698945640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: text
38
- requirement: &70136859663880 !ruby/object:Gem::Requirement
38
+ requirement: &70196698961460 !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: *70136859663880
46
+ version_requirements: *70196698961460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &70136859663340 !ruby/object:Gem::Requirement
49
+ requirement: &70196698960800 !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: *70136859663340
57
+ version_requirements: *70196698960800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70136859662720 !ruby/object:Gem::Requirement
60
+ requirement: &70196698959920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70136859662720
68
+ version_requirements: *70196698959920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: procrastinate
71
- requirement: &70136859661300 !ruby/object:Gem::Requirement
71
+ requirement: &70196698958960 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.4'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70136859661300
79
+ version_requirements: *70196698958960
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rack_fast_escape
82
- requirement: &70136859660460 !ruby/object:Gem::Requirement
82
+ requirement: &70196698957940 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70136859660460
90
+ version_requirements: *70196698957940
91
91
  description: Fast Ruby semantic text search engine with comfortable single field interface.
92
92
  email: florian.hanke+picky@gmail.com
93
93
  executables: