picky 2.4.3 → 2.5.0

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.
@@ -46,12 +46,7 @@ module Internals
46
46
  #
47
47
  def << category
48
48
  categories << category
49
- # Note: [category] is an optimization, since I need an array
50
- # of categories.
51
- # It's faster to just package it in an array on loading
52
- # Picky than doing it over and over with each query.
53
- #
54
- category_hash[category.name] = [category]
49
+ category_hash[category.name] = category
55
50
  end
56
51
 
57
52
  # Return all possible combinations for the given token.
@@ -129,10 +124,13 @@ module Internals
129
124
  # an existing category.
130
125
  #
131
126
  # Note: Returns nil if the user did not define one
132
- # or if he/she has defined a non-existing one.
127
+ # or [] if he/she has defined a non-existing one.
133
128
  #
134
129
  def user_defined_categories token
135
- category_hash[token.user_defined_category_name]
130
+ names = token.user_defined_category_names
131
+ names && names.map do |name|
132
+ category_hash[name]
133
+ end.compact
136
134
  end
137
135
 
138
136
  end
@@ -42,10 +42,10 @@ module Internals
42
42
  self
43
43
  end
44
44
 
45
- # This returns a predefined category name if the user has given one.
45
+ # This returns an array of predefined category names if the user has given any.
46
46
  #
47
- def user_defined_category_name
48
- @qualifier
47
+ def user_defined_category_names
48
+ @qualifiers
49
49
  end
50
50
 
51
51
  # Extracts a qualifier for this token and pre-assigns an allocation.
@@ -53,8 +53,9 @@ module Internals
53
53
  # Note: Removes the qualifier if it is not allowed.
54
54
  #
55
55
  def qualify
56
- @qualifier, @text = split @text
57
- @qualifier = Query::Qualifiers.instance.normalize @qualifier
56
+ @qualifiers, @text = split @text
57
+ @qualifiers && @qualifiers.collect! { |qualifier| Query::Qualifiers.instance.normalize qualifier }.compact!
58
+ @qualifiers
58
59
  end
59
60
  def extract_original
60
61
  @original = @text.dup
@@ -151,27 +152,6 @@ module Internals
151
152
  bundle.similar(@text).dup || []
152
153
  end
153
154
 
154
- # Generates a solr term from this token.
155
- #
156
- # E.g. "name:heroes~0.75"
157
- #
158
- @@solr_fuzzy_mapping = {
159
- 1 => :'',
160
- 2 => :'',
161
- 3 => :'',
162
- 4 => :'~0.74',
163
- 5 => :'~0.78',
164
- 6 => :'~0.81',
165
- 7 => :'~0.83',
166
- 8 => :'~0.85',
167
- 9 => :'~0.87',
168
- 10 => :'~0.89'
169
- }
170
- @@solr_fuzzy_mapping.default = :'~0.9'
171
- def to_solr
172
- blank? ? '' : (to_s + @@solr_fuzzy_mapping[@text.size].to_s)
173
- end
174
-
175
155
  #
176
156
  #
177
157
  def to_result
@@ -194,8 +174,10 @@ module Internals
194
174
  #
195
175
  # e.g. name:meier
196
176
  #
177
+ @@split_qualifier_text = ':'
178
+ @@split_qualifiers = ','
197
179
  def to_s
198
- [@qualifier, @text].compact.join ':'
180
+ [@qualifiers && @qualifiers.join(@@split_qualifiers), @text].compact.join @@split_qualifier_text
199
181
  end
200
182
 
201
183
  private
@@ -205,11 +187,11 @@ module Internals
205
187
  # Returns [qualifier, text].
206
188
  #
207
189
  def split unqualified_text
208
- qualifier, text = (unqualified_text || '').split(':', 2)
190
+ qualifiers, text = (unqualified_text || '').split(@@split_qualifier_text, 2)
209
191
  if text.blank?
210
- [nil, (qualifier || '')]
192
+ [nil, (qualifiers || '')]
211
193
  else
212
- [qualifier, text]
194
+ [qualifiers.split(@@split_qualifiers), text]
213
195
  end
214
196
  end
215
197
 
@@ -107,7 +107,7 @@ describe Internals::Indexed::Categories do
107
107
  context 'without preselected categories' do
108
108
  context 'user defined exists' do
109
109
  before(:each) do
110
- @token = stub :token, :user_defined_category_name => :category2
110
+ @token = stub :token, :user_defined_category_names => [:category2]
111
111
  end
112
112
  context 'combination exists' do
113
113
  before(:each) do
@@ -139,7 +139,7 @@ describe Internals::Indexed::Categories do
139
139
  describe 'possible_categories' do
140
140
  context 'user defined exists' do
141
141
  before(:each) do
142
- @token = stub :token, :user_defined_category_name => :category2
142
+ @token = stub :token, :user_defined_category_names => [:category2]
143
143
  end
144
144
  it 'should return the right categories' do
145
145
  @categories.possible_categories(@token).should == [@category2]
@@ -147,7 +147,7 @@ describe Internals::Indexed::Categories do
147
147
  end
148
148
  context 'user defined does not exist' do
149
149
  before(:each) do
150
- @token = stub :token, :user_defined_category_name => nil
150
+ @token = stub :token, :user_defined_category_names => nil
151
151
  end
152
152
  it 'should return all categories' do
153
153
  @categories.possible_categories(@token).should == [@category1, @category2, @category3]
@@ -158,7 +158,7 @@ describe Internals::Indexed::Categories do
158
158
  describe 'user_defined_categories' do
159
159
  context 'category exists' do
160
160
  before(:each) do
161
- @token = stub :token, :user_defined_category_name => :category2
161
+ @token = stub :token, :user_defined_category_names => [:category2]
162
162
  end
163
163
  it 'should return the right categories' do
164
164
  @categories.user_defined_categories(@token).should == [@category2]
@@ -166,10 +166,10 @@ describe Internals::Indexed::Categories do
166
166
  end
167
167
  context 'category does not exist' do
168
168
  before(:each) do
169
- @token = stub :token, :user_defined_category_name => :gnoergel
169
+ @token = stub :token, :user_defined_category_names => [:gnoergel]
170
170
  end
171
171
  it 'should return nil' do
172
- @categories.user_defined_categories(@token).should == nil
172
+ @categories.user_defined_categories(@token).should == []
173
173
  end
174
174
  end
175
175
  end
@@ -122,33 +122,33 @@ describe Internals::Query::Token do
122
122
  end
123
123
  end
124
124
 
125
- describe 'to_solr' do
126
- def self.it_should_solr text, expected_result
127
- it "should solrify into #{expected_result} from #{text}" do
128
- described_class.processed(text).to_solr.should == expected_result
129
- end
130
- end
131
- it_should_solr 's', 's'
132
- it_should_solr 'se', 'se'
133
- it_should_solr 'sea', 'sea'
134
- it_should_solr 'sear', 'sear~0.74'
135
- it_should_solr 'searc', 'searc~0.78'
136
- it_should_solr 'search', 'search~0.81'
137
- it_should_solr 'searche', 'searche~0.83'
138
- it_should_solr 'searchen', 'searchen~0.85'
139
- it_should_solr 'searcheng', 'searcheng~0.87'
140
- it_should_solr 'searchengi', 'searchengi~0.89'
141
- it_should_solr 'searchengin', 'searchengin~0.9'
142
- it_should_solr 'searchengine', 'searchengine~0.9'
143
-
144
- it_should_solr 'spec:tex', 'specific:tex'
145
- it_should_solr 'with:text', 'text~0.74'
146
- it_should_solr 'name:', 'name~0.74'
147
- it_should_solr '', ''
148
- it_should_solr 'sp:tex', 'specific:tex'
149
- it_should_solr 'sp:tex~', 'specific:tex'
150
- it_should_solr 'sp:tex"', 'specific:tex'
151
- end
125
+ # describe 'to_solr' do
126
+ # def self.it_should_solr text, expected_result
127
+ # it "should solrify into #{expected_result} from #{text}" do
128
+ # described_class.processed(text).to_solr.should == expected_result
129
+ # end
130
+ # end
131
+ # it_should_solr 's', 's'
132
+ # it_should_solr 'se', 'se'
133
+ # it_should_solr 'sea', 'sea'
134
+ # it_should_solr 'sear', 'sear~0.74'
135
+ # it_should_solr 'searc', 'searc~0.78'
136
+ # it_should_solr 'search', 'search~0.81'
137
+ # it_should_solr 'searche', 'searche~0.83'
138
+ # it_should_solr 'searchen', 'searchen~0.85'
139
+ # it_should_solr 'searcheng', 'searcheng~0.87'
140
+ # it_should_solr 'searchengi', 'searchengi~0.89'
141
+ # it_should_solr 'searchengin', 'searchengin~0.9'
142
+ # it_should_solr 'searchengine', 'searchengine~0.9'
143
+ #
144
+ # it_should_solr 'spec:tex', 'specific:tex'
145
+ # it_should_solr 'with:text', 'text~0.74'
146
+ # it_should_solr 'name:', 'name~0.74'
147
+ # it_should_solr '', ''
148
+ # it_should_solr 'sp:tex', 'specific:tex'
149
+ # it_should_solr 'sp:tex~', 'specific:tex'
150
+ # it_should_solr 'sp:tex"', 'specific:tex'
151
+ # end
152
152
 
153
153
  describe 'qualify' do
154
154
  def self.it_should_qualify text, expected_result
@@ -156,13 +156,13 @@ describe Internals::Query::Token do
156
156
  described_class.new(text).qualify.should == expected_result
157
157
  end
158
158
  end
159
- it_should_qualify 'spec:qualifier', :specific
160
- it_should_qualify 'with:qualifier', nil
159
+ it_should_qualify 'spec:qualifier', [:specific]
160
+ it_should_qualify 'with:qualifier', []
161
161
  it_should_qualify 'without qualifier', nil
162
162
  it_should_qualify 'name:', nil
163
- it_should_qualify ':broken qualifier', nil
163
+ it_should_qualify ':broken qualifier', [] # Unsure about that. Probably should recognize it as text.
164
164
  it_should_qualify '', nil
165
- it_should_qualify 'sp:text', :specific
165
+ it_should_qualify 'sp:text', [:specific]
166
166
  end
167
167
 
168
168
  describe 'processed' do
@@ -270,11 +270,13 @@ describe Internals::Query::Token do
270
270
  end
271
271
  it_should_split '""', [nil, '""']
272
272
  it_should_split 'name:', [nil, 'name']
273
- it_should_split 'name:hanke', ['name', 'hanke']
274
- it_should_split 'g:gaga', ['g', 'gaga']
275
- it_should_split ':nothing', ['', 'nothing']
273
+ it_should_split 'name:hanke', [['name'], 'hanke']
274
+ it_should_split 'g:gaga', [['g'], 'gaga']
275
+ it_should_split ':nothing', [[], 'nothing']
276
276
  it_should_split 'hello', [nil, 'hello']
277
- it_should_split 'a:b:c', ['a', 'b:c']
277
+ it_should_split 'a:b:c', [['a'], 'b:c']
278
+ it_should_split 'a,b:c', [['a','b'], 'c']
279
+ it_should_split 'a,b,c:d', [['a','b','c'], 'd']
278
280
  end
279
281
 
280
282
  describe "original" do
@@ -321,7 +323,23 @@ describe Internals::Query::Token do
321
323
  @token = described_class.processed('sp:qualifier')
322
324
  end
323
325
  it 'should return the qualifier' do
324
- @token.user_defined_category_name.should == :specific
326
+ @token.user_defined_category_names.should == [:specific]
327
+ end
328
+ end
329
+ context 'with incorrect qualifier' do
330
+ before(:each) do
331
+ @token = described_class.processed('specific:qualifier')
332
+ end
333
+ it 'should return the qualifier' do
334
+ @token.user_defined_category_names.should == []
335
+ end
336
+ end
337
+ context 'with multiple qualifiers' do
338
+ before(:each) do
339
+ @token = described_class.processed('sp,spec:qualifier')
340
+ end
341
+ it 'should return the qualifier' do
342
+ @token.user_defined_category_names.should == [:specific, :specific]
325
343
  end
326
344
  end
327
345
  context 'without qualifier' do
@@ -329,7 +347,7 @@ describe Internals::Query::Token do
329
347
  @token = described_class.processed('noqualifier')
330
348
  end
331
349
  it 'should return nil' do
332
- @token.user_defined_category_name.should == nil
350
+ @token.user_defined_category_names.should == nil
333
351
  end
334
352
  end
335
353
  end
@@ -340,14 +358,14 @@ describe Internals::Query::Token do
340
358
  described_class.new('any').send(:split, text).should == expected_result
341
359
  end
342
360
  end
343
- it_should_split ':', [nil, '']
344
- it_should_split 'vorname:qualifier', ['vorname', 'qualifier']
345
- it_should_split 'with:qualifier', ['with', 'qualifier']
346
- it_should_split 'without qualifier', [nil, 'without qualifier']
347
- it_should_split 'name:', [nil, 'name']
348
- it_should_split ':broken qualifier', ['', 'broken qualifier']
349
- it_should_split '', [nil, '']
350
- it_should_split 'fn:text', ['fn', 'text']
361
+ it_should_split ':', [nil, '']
362
+ it_should_split 'vorname:qualifier', [['vorname'], 'qualifier']
363
+ it_should_split 'with:qualifier', [['with'], 'qualifier']
364
+ it_should_split 'without qualifier', [nil, 'without qualifier']
365
+ it_should_split 'name:', [nil, 'name']
366
+ it_should_split ':broken qualifier', [[], 'broken qualifier']
367
+ it_should_split '', [nil, '']
368
+ it_should_split 'fn:text', [['fn'], 'text']
351
369
  end
352
370
 
353
371
  describe 'partial=' do
@@ -35,23 +35,6 @@ describe Internals::Query::Tokens do
35
35
  described_class.processed ['this~', 'is', 'a', 'sp:solr', 'query"']
36
36
  end
37
37
  end
38
-
39
- describe 'to_solr_query' do
40
- context 'many tokens' do
41
- before(:each) do
42
- @tokens = described_class.new [
43
- Internals::Query::Token.processed('this~'),
44
- Internals::Query::Token.processed('is'),
45
- Internals::Query::Token.processed('a'),
46
- Internals::Query::Token.processed('sp:solr'),
47
- Internals::Query::Token.processed('query"')
48
- ]
49
- end
50
- it 'should output a correct solr query' do
51
- @tokens.to_solr_query.should == 'this~0.74 is a specific:solr~0.74 query~0.78'
52
- end
53
- end
54
- end
55
38
 
56
39
  describe 'reject' do
57
40
  before(:each) do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.4.3
5
+ version: 2.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-07-01 00:00:00 +10:00
13
+ date: 2011-07-02 00:00:00 +10:00
14
14
  default_executable: picky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 2.4.3
35
+ version: 2.5.0
36
36
  type: :development
37
37
  version_requirements: *id002
38
38
  description: Fast Ruby semantic text search engine with comfortable single field interface.