picky 4.6.3 → 4.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/performant.c +4 -4
- data/lib/picky/analyzer.rb +6 -3
- data/lib/picky/backends/backend.rb +40 -0
- data/lib/picky/backends/file/json.rb +4 -0
- data/lib/picky/backends/file.rb +1 -25
- data/lib/picky/backends/memory/json.rb +4 -0
- data/lib/picky/backends/memory.rb +1 -29
- data/lib/picky/backends/redis/directly_manipulable.rb +15 -7
- data/lib/picky/backends/redis.rb +91 -92
- data/lib/picky/backends/sqlite/basic.rb +6 -0
- data/lib/picky/bundle.rb +12 -10
- data/lib/picky/categories_indexing.rb +0 -13
- data/lib/picky/category.rb +24 -21
- data/lib/picky/category_indexing.rb +8 -22
- data/lib/picky/constants.rb +0 -1
- data/lib/picky/generators/aliases.rb +2 -0
- data/lib/picky/generators/partial.rb +27 -0
- data/lib/picky/generators/similarity.rb +27 -0
- data/lib/picky/generators/weights.rb +32 -0
- data/lib/picky/helpers/identification.rb +18 -0
- data/lib/picky/helpers/indexing.rb +16 -0
- data/lib/picky/index.rb +6 -0
- data/lib/picky/index_indexing.rb +9 -21
- data/lib/picky/indexes_indexing.rb +5 -14
- data/lib/picky/loader.rb +204 -199
- data/lib/picky/query/indexes.rb +12 -1
- data/lib/picky/search.rb +1 -0
- data/lib/picky/source.rb +23 -0
- data/lib/picky/tokenizer.rb +35 -13
- data/spec/functional/facets_spec.rb +1 -1
- data/spec/functional/remap_qualifiers_spec.rb +43 -0
- data/spec/functional/tokenizer_spec.rb +1 -1
- data/spec/lib/api/search/boost_spec.rb +1 -1
- data/spec/lib/category_spec.rb +1 -4
- data/spec/lib/generators/partial_spec.rb +58 -0
- data/spec/lib/generators/similarity_spec.rb +59 -0
- data/spec/lib/generators/weights_spec.rb +68 -0
- data/spec/lib/index_indexing_spec.rb +2 -4
- data/spec/lib/index_spec.rb +6 -0
- data/spec/lib/pool_spec.rb +39 -35
- data/spec/lib/sinatra_spec.rb +2 -2
- data/spec/lib/source_spec.rb +63 -0
- data/spec/lib/tokenizer_spec.rb +64 -2
- metadata +20 -20
- data/lib/picky/api/category/partial.rb +0 -26
- data/lib/picky/api/category/similarity.rb +0 -26
- data/lib/picky/api/category/weight.rb +0 -28
- data/lib/picky/api/source.rb +0 -35
- data/lib/picky/api/tokenizer.rb +0 -37
- data/lib/picky/deployment.rb +0 -211
- data/spec/lib/api/category/partial_spec.rb +0 -49
- data/spec/lib/api/category/similarity_spec.rb +0 -50
- data/spec/lib/api/category/weight_spec.rb +0 -55
- data/spec/lib/api/source_spec.rb +0 -68
- data/spec/lib/api/tokenizer_spec.rb +0 -42
data/lib/picky/loader.rb
CHANGED
@@ -28,8 +28,10 @@ module Picky
|
|
28
28
|
|
29
29
|
# Load a file relative to this.
|
30
30
|
#
|
31
|
-
def load_relative
|
32
|
-
|
31
|
+
def load_relative *filenames_without_rb
|
32
|
+
filenames_without_rb.each do |filename_without_rb|
|
33
|
+
Kernel.load File.join(File.dirname(__FILE__), "#{filename_without_rb}.rb")
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
# Load a user file.
|
@@ -46,231 +48,234 @@ module Picky
|
|
46
48
|
exclaim "\nBy default, Picky needs/loads the PICKY_ROOT/app.rb file as the app.\n\n"
|
47
49
|
raise e
|
48
50
|
end
|
49
|
-
|
50
|
-
# Loads the
|
51
|
-
# (Not for the user)
|
51
|
+
|
52
|
+
# Loads the compiled C code.
|
52
53
|
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# when installing the gem.
|
58
|
-
#
|
54
|
+
# Note: Picky already tries to compile
|
55
|
+
# when installing the gem.
|
56
|
+
#
|
57
|
+
def load_c_code
|
59
58
|
require_relative '../maybe_compile'
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# Calculations.
|
81
|
-
#
|
82
|
-
load_relative 'calculations/location'
|
83
|
-
|
84
|
-
# Index generation strategies.
|
85
|
-
#
|
86
|
-
load_relative 'indexers/base'
|
87
|
-
load_relative 'indexers/serial'
|
88
|
-
load_relative 'indexers/parallel'
|
89
|
-
|
90
|
-
# Generators.
|
91
|
-
#
|
59
|
+
end
|
60
|
+
def load_extensions
|
61
|
+
load_relative 'extensions/object',
|
62
|
+
'extensions/array',
|
63
|
+
'extensions/symbol',
|
64
|
+
'extensions/string',
|
65
|
+
'extensions/module',
|
66
|
+
'extensions/class',
|
67
|
+
'extensions/hash'
|
68
|
+
end
|
69
|
+
def load_helpers
|
70
|
+
load_relative 'helpers/measuring',
|
71
|
+
'helpers/indexing',
|
72
|
+
'helpers/identification'
|
73
|
+
end
|
74
|
+
def load_index_generation_strategies
|
75
|
+
load_relative 'indexers/base',
|
76
|
+
'indexers/serial',
|
77
|
+
'indexers/parallel'
|
78
|
+
|
92
79
|
load_relative 'generators/strategy'
|
93
|
-
|
80
|
+
|
94
81
|
# Partial index generation strategies.
|
95
82
|
#
|
96
|
-
load_relative 'generators/partial/strategy'
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
load_relative 'generators/partial/strategy',
|
84
|
+
'generators/partial/none',
|
85
|
+
'generators/partial/substring',
|
86
|
+
'generators/partial/postfix',
|
87
|
+
'generators/partial/infix',
|
88
|
+
'generators/partial/default'
|
89
|
+
|
103
90
|
# Weight index generation strategies.
|
104
91
|
#
|
105
|
-
load_relative 'generators/weights/strategy'
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
92
|
+
load_relative 'generators/weights/strategy',
|
93
|
+
'generators/weights/stub',
|
94
|
+
'generators/weights/dynamic',
|
95
|
+
'generators/weights/constant',
|
96
|
+
'generators/weights/logarithmic',
|
97
|
+
'generators/weights/default'
|
98
|
+
|
112
99
|
# Similarity index generation strategies.
|
113
100
|
#
|
114
|
-
load_relative 'generators/similarity/strategy'
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
101
|
+
load_relative 'generators/similarity/strategy',
|
102
|
+
'generators/similarity/none',
|
103
|
+
'generators/similarity/phonetic',
|
104
|
+
'generators/similarity/metaphone',
|
105
|
+
'generators/similarity/double_metaphone',
|
106
|
+
'generators/similarity/soundex',
|
107
|
+
'generators/similarity/default'
|
108
|
+
end
|
109
|
+
|
110
|
+
# Loads the index store handling.
|
111
|
+
#
|
112
|
+
def load_index_stores
|
113
|
+
load_relative 'backends/helpers/file',
|
114
|
+
'backends/backend'
|
126
115
|
|
127
116
|
load_relative 'backends/prepared/text'
|
128
117
|
|
129
|
-
load_relative 'backends/memory'
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
load_relative 'backends/file'
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
load_relative 'backends/redis'
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
load_relative 'backends/sqlite'
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
load_relative '
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
118
|
+
load_relative 'backends/memory',
|
119
|
+
'backends/memory/basic',
|
120
|
+
'backends/memory/marshal',
|
121
|
+
'backends/memory/json'
|
122
|
+
|
123
|
+
load_relative 'backends/file',
|
124
|
+
'backends/file/basic',
|
125
|
+
'backends/file/json'
|
126
|
+
|
127
|
+
load_relative 'backends/redis',
|
128
|
+
'backends/redis/directly_manipulable',
|
129
|
+
'backends/redis/basic',
|
130
|
+
'backends/redis/list',
|
131
|
+
'backends/redis/string',
|
132
|
+
'backends/redis/float'
|
133
|
+
|
134
|
+
load_relative 'backends/sqlite',
|
135
|
+
'backends/sqlite/directly_manipulable',
|
136
|
+
'backends/sqlite/basic',
|
137
|
+
'backends/sqlite/array',
|
138
|
+
'backends/sqlite/value',
|
139
|
+
'backends/sqlite/string_key_array',
|
140
|
+
'backends/sqlite/integer_key_array'
|
141
|
+
end
|
142
|
+
|
143
|
+
# Indexing and Indexed things.
|
144
|
+
#
|
145
|
+
def load_indexes
|
146
|
+
load_relative 'bundle',
|
147
|
+
'bundle_indexing',
|
148
|
+
'bundle_indexed',
|
149
|
+
'bundle_realtime'
|
150
|
+
end
|
151
|
+
|
152
|
+
# Index wrappers.
|
153
|
+
#
|
154
|
+
def load_wrappers
|
162
155
|
load_relative 'category/location'
|
163
156
|
|
164
|
-
load_relative 'wrappers/bundle/delegators'
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
#
|
177
|
-
load_relative 'query/combination'
|
178
|
-
load_relative 'query/combinations'
|
157
|
+
load_relative 'wrappers/bundle/delegators',
|
158
|
+
'wrappers/bundle/wrapper',
|
159
|
+
'wrappers/bundle/calculation',
|
160
|
+
'wrappers/bundle/location',
|
161
|
+
'wrappers/bundle/exact_partial'
|
162
|
+
end
|
163
|
+
|
164
|
+
# Query combinations, qualifiers, weigher.
|
165
|
+
#
|
166
|
+
def load_query
|
167
|
+
load_relative 'query/combination',
|
168
|
+
'query/combinations'
|
179
169
|
|
180
|
-
load_relative 'query/allocation'
|
181
|
-
|
170
|
+
load_relative 'query/allocation',
|
171
|
+
'query/allocations'
|
182
172
|
|
183
173
|
load_relative 'query/qualifier_category_mapper'
|
184
174
|
|
185
175
|
load_relative 'query/boosts'
|
186
176
|
|
187
|
-
load_relative 'query/indexes'
|
188
|
-
|
177
|
+
load_relative 'query/indexes',
|
178
|
+
'query/indexes_check'
|
179
|
+
end
|
180
|
+
|
181
|
+
# Loads the internal parts of the framework.
|
182
|
+
# (Not for the user)
|
183
|
+
#
|
184
|
+
def load_framework_internals
|
185
|
+
load_c_code
|
186
|
+
load_extensions
|
187
|
+
load_helpers
|
188
|
+
load_relative 'pool'
|
189
|
+
load_relative 'calculations/location' # Calculations
|
190
|
+
load_index_generation_strategies
|
191
|
+
load_index_stores
|
192
|
+
load_indexes
|
193
|
+
load_wrappers
|
194
|
+
load_relative 'query/token' # Token related.
|
195
|
+
load_relative 'query/tokens'
|
196
|
+
load_query
|
197
|
+
end
|
198
|
+
|
199
|
+
# All things API related.
|
200
|
+
#
|
201
|
+
def load_api
|
202
|
+
load_relative 'api/tokenizer/character_substituter',
|
203
|
+
'api/search/boost'
|
204
|
+
end
|
205
|
+
|
206
|
+
def load_logging
|
207
|
+
load_relative 'loggers/silent',
|
208
|
+
'loggers/concise',
|
209
|
+
'loggers/verbose',
|
210
|
+
'loggers/default'
|
211
|
+
end
|
212
|
+
|
213
|
+
def load_generators
|
214
|
+
load_relative 'generators/weights'
|
215
|
+
load_relative 'generators/partial'
|
216
|
+
load_relative 'generators/similarity'
|
217
|
+
load_relative 'generators/aliases'
|
218
|
+
end
|
219
|
+
|
220
|
+
def load_inner_api
|
221
|
+
load_relative 'category',
|
222
|
+
'category_indexed',
|
223
|
+
'category_indexing',
|
224
|
+
'category_realtime',
|
225
|
+
'category_convenience'
|
226
|
+
|
227
|
+
load_relative 'categories',
|
228
|
+
'categories_indexed',
|
229
|
+
'categories_indexing',
|
230
|
+
'categories_realtime',
|
231
|
+
'categories_convenience'
|
232
|
+
|
233
|
+
load_relative 'indexes',
|
234
|
+
'indexes_indexed',
|
235
|
+
'indexes_indexing',
|
236
|
+
'indexes_convenience'
|
237
|
+
|
238
|
+
load_relative 'index',
|
239
|
+
'index_indexed',
|
240
|
+
'index_indexing',
|
241
|
+
'index_realtime',
|
242
|
+
'index_facets',
|
243
|
+
'index_convenience'
|
244
|
+
end
|
245
|
+
|
246
|
+
def load_results
|
247
|
+
load_relative 'results',
|
248
|
+
'results/exact_first'
|
189
249
|
end
|
250
|
+
|
251
|
+
def load_search
|
252
|
+
load_relative 'search',
|
253
|
+
'search_facets'
|
254
|
+
end
|
255
|
+
|
256
|
+
def load_interfaces
|
257
|
+
load_relative 'interfaces/live_parameters/master_child',
|
258
|
+
'interfaces/live_parameters/unicorn'
|
259
|
+
end
|
260
|
+
|
190
261
|
# Loads the user interface parts.
|
191
262
|
#
|
263
|
+
# TODO Move tokenizer etc.?
|
264
|
+
#
|
192
265
|
def load_user_interface
|
193
|
-
|
194
|
-
|
195
|
-
load_relative '
|
196
|
-
load_relative 'api/tokenizer/character_substituter'
|
197
|
-
load_relative 'api/source'
|
198
|
-
load_relative 'api/category/weight'
|
199
|
-
load_relative 'api/category/partial'
|
200
|
-
load_relative 'api/category/similarity'
|
201
|
-
load_relative 'api/search/boost'
|
202
|
-
|
203
|
-
# Loggers.
|
204
|
-
#
|
205
|
-
load_relative 'loggers/silent'
|
206
|
-
load_relative 'loggers/concise'
|
207
|
-
load_relative 'loggers/verbose'
|
208
|
-
load_relative 'loggers/default'
|
209
|
-
|
210
|
-
# Tokenizer.
|
211
|
-
#
|
266
|
+
load_api
|
267
|
+
load_logging
|
268
|
+
load_relative 'source'
|
212
269
|
load_relative 'tokenizer'
|
213
|
-
|
214
|
-
# Load harakiri.
|
215
|
-
#
|
216
270
|
load_relative 'rack/harakiri'
|
217
|
-
|
218
|
-
# Character Substituters
|
219
|
-
#
|
220
271
|
load_relative 'character_substituters/west_european'
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
# API.
|
227
|
-
#
|
228
|
-
load_relative 'category'
|
229
|
-
load_relative 'category_indexed'
|
230
|
-
load_relative 'category_indexing'
|
231
|
-
load_relative 'category_realtime'
|
232
|
-
load_relative 'category_convenience'
|
233
|
-
|
234
|
-
load_relative 'categories'
|
235
|
-
load_relative 'categories_indexed'
|
236
|
-
load_relative 'categories_indexing'
|
237
|
-
load_relative 'categories_realtime'
|
238
|
-
load_relative 'categories_convenience'
|
239
|
-
|
240
|
-
load_relative 'indexes'
|
241
|
-
load_relative 'indexes_indexed'
|
242
|
-
load_relative 'indexes_indexing'
|
243
|
-
load_relative 'indexes_convenience'
|
244
|
-
|
245
|
-
load_relative 'index'
|
246
|
-
load_relative 'index_indexed'
|
247
|
-
load_relative 'index_indexing'
|
248
|
-
load_relative 'index_realtime'
|
249
|
-
load_relative 'index_facets'
|
250
|
-
load_relative 'index_convenience'
|
251
|
-
|
252
|
-
# Results.
|
253
|
-
#
|
254
|
-
load_relative 'results'
|
255
|
-
load_relative 'results/exact_first'
|
256
|
-
|
257
|
-
# Search.
|
258
|
-
#
|
259
|
-
load_relative 'search'
|
260
|
-
load_relative 'search_facets'
|
261
|
-
|
262
|
-
# Interfaces
|
263
|
-
#
|
264
|
-
load_relative 'interfaces/live_parameters/master_child'
|
265
|
-
load_relative 'interfaces/live_parameters/unicorn'
|
266
|
-
|
267
|
-
# Load tools. Load specifically?
|
268
|
-
#
|
272
|
+
load_generators
|
273
|
+
load_inner_api
|
274
|
+
load_results
|
275
|
+
load_search
|
276
|
+
load_interfaces
|
269
277
|
load_relative 'scheduler'
|
270
|
-
|
271
|
-
# Load migration notices.
|
272
|
-
#
|
273
|
-
load_relative 'migrations/from_30_to_31'
|
278
|
+
load_relative 'migrations/from_30_to_31' # TODO Remove.
|
274
279
|
end
|
275
280
|
|
276
281
|
# Loads the framework.
|
data/lib/picky/query/indexes.rb
CHANGED
@@ -30,7 +30,18 @@ module Picky
|
|
30
30
|
|
31
31
|
@indexes = indexes
|
32
32
|
|
33
|
-
|
33
|
+
remap_qualifiers
|
34
|
+
end
|
35
|
+
|
36
|
+
# Updates the qualifier ("qualifier:searchterm") mapping.
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# You dynamically add a new category to an index.
|
40
|
+
# To add the qualifiers to a search, you call this
|
41
|
+
# method.
|
42
|
+
#
|
43
|
+
def remap_qualifiers
|
44
|
+
@mapper = QualifierCategoryMapper.new @indexes # TODO Move into search?
|
34
45
|
end
|
35
46
|
|
36
47
|
# Ignore the categories with these qualifiers.
|
data/lib/picky/search.rb
CHANGED
data/lib/picky/source.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
module Source
|
4
|
+
extend Helpers::Identification
|
5
|
+
|
6
|
+
# Either a thing responding to #each or a block is fine.
|
7
|
+
#
|
8
|
+
def self.from thing, nil_ok, index_name = nil
|
9
|
+
if thing.respond_to?(:each) || thing.respond_to?(:call)
|
10
|
+
thing
|
11
|
+
else
|
12
|
+
return if nil_ok
|
13
|
+
|
14
|
+
raise ArgumentError.new(<<-ERROR)
|
15
|
+
The source #{identifier_for(index_name)}should respond to either the method #each or
|
16
|
+
it can be a lambda/block, returning such a source.
|
17
|
+
ERROR
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/picky/tokenizer.rb
CHANGED
@@ -6,23 +6,41 @@ module Picky
|
|
6
6
|
#
|
7
7
|
class Tokenizer
|
8
8
|
|
9
|
-
extend
|
10
|
-
|
9
|
+
extend Picky::Helpers::Identification
|
11
10
|
include API::Tokenizer::CharacterSubstituter
|
12
11
|
|
13
12
|
def self.default_indexing_with options = {}
|
14
|
-
@indexing =
|
13
|
+
@indexing = from options
|
15
14
|
end
|
16
15
|
def self.indexing
|
17
16
|
@indexing ||= new
|
18
17
|
end
|
19
18
|
|
20
19
|
def self.default_searching_with options = {}
|
21
|
-
@searching =
|
20
|
+
@searching = from options
|
22
21
|
end
|
23
22
|
def self.searching
|
24
23
|
@searching ||= new
|
25
24
|
end
|
25
|
+
|
26
|
+
def self.from thing, index_name = nil, category_name = nil
|
27
|
+
return unless thing
|
28
|
+
|
29
|
+
if thing.respond_to? :tokenize
|
30
|
+
thing
|
31
|
+
else
|
32
|
+
if thing.respond_to? :[]
|
33
|
+
Picky::Tokenizer.new thing
|
34
|
+
else
|
35
|
+
raise <<-ERROR
|
36
|
+
indexing options #{identifier_for(index_name, category_name)}should be either
|
37
|
+
* a Hash
|
38
|
+
or
|
39
|
+
* an object that responds to #tokenize(text) => [[token1, token2, ...], [original1, original2, ...]]
|
40
|
+
ERROR
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
26
44
|
|
27
45
|
def to_s
|
28
46
|
reject_condition_location = @reject_condition.to_s[/:(\d+) \(lambda\)/, 1]
|
@@ -120,7 +138,7 @@ Case sensitive? #{@case_sensitive ? "Yes." : "-"}
|
|
120
138
|
|
121
139
|
# Reject tokens after tokenizing based on the given criteria.
|
122
140
|
#
|
123
|
-
def rejects_token_if
|
141
|
+
def rejects_token_if condition
|
124
142
|
@reject_condition = condition
|
125
143
|
end
|
126
144
|
def reject tokens
|
@@ -161,14 +179,18 @@ Case sensitive? #{@case_sensitive ? "Yes." : "-"}
|
|
161
179
|
alias substituter? substituter
|
162
180
|
|
163
181
|
def initialize options = {}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
182
|
+
options = default_options.merge options
|
183
|
+
options.each do |method_name, value|
|
184
|
+
send method_name, value unless value.nil?
|
185
|
+
end
|
186
|
+
rescue NoMethodError => e
|
187
|
+
raise %Q{The option "#{e.name}" is not a valid option for a Picky tokenizer.\nPlease see https://github.com/floere/picky/wiki/Indexing-configuration for valid options.}
|
188
|
+
end
|
189
|
+
def default_options
|
190
|
+
{
|
191
|
+
splits_text_on: /\s/,
|
192
|
+
rejects_token_if: :blank?.to_proc
|
193
|
+
}
|
172
194
|
end
|
173
195
|
|
174
196
|
# Returns a number of tokens, generated from the given text,
|
@@ -139,7 +139,7 @@ describe 'facets' do
|
|
139
139
|
it 'is fast enough' do
|
140
140
|
performance_of {
|
141
141
|
10.times { finder.facets(:age_category, filter: 'surname:meier name:peter') }
|
142
|
-
}.should < 0.
|
142
|
+
}.should < 0.003
|
143
143
|
end
|
144
144
|
it 'has one filtered facet' do
|
145
145
|
# TODO Fix problems with alternative qualifiers (like :age).
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'qualifier remapping' do
|
6
|
+
|
7
|
+
it 'can have new qualifiers' do
|
8
|
+
index = Picky::Index.new :qualifier_remapping do
|
9
|
+
category :a
|
10
|
+
end
|
11
|
+
|
12
|
+
QualifierRemappingThing = Struct.new(:id, :a, :b)
|
13
|
+
|
14
|
+
index.add QualifierRemappingThing.new(1, "a", "b")
|
15
|
+
|
16
|
+
try = Picky::Search.new index
|
17
|
+
|
18
|
+
# Picky finds nothing.
|
19
|
+
#
|
20
|
+
try.search('b').ids.should == []
|
21
|
+
|
22
|
+
# Add a new category and a thing.
|
23
|
+
#
|
24
|
+
index.category :b
|
25
|
+
index.add QualifierRemappingThing.new(2, "c", "b")
|
26
|
+
|
27
|
+
# It finds it.
|
28
|
+
#
|
29
|
+
try.search('b').ids.should == [2]
|
30
|
+
|
31
|
+
# But not with qualifier!
|
32
|
+
#
|
33
|
+
try.search('b:b').ids.should == []
|
34
|
+
|
35
|
+
# So remap the qualifiers.
|
36
|
+
#
|
37
|
+
try.remap_qualifiers
|
38
|
+
|
39
|
+
# Now it works!
|
40
|
+
#
|
41
|
+
try.search('b:b').ids.should == [2]
|
42
|
+
end
|
43
|
+
end
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe Picky::Tokenizer do
|
6
6
|
describe 'examples' do
|
7
7
|
it 'works correctly' do
|
8
|
-
tokenizer = described_class.new(
|
8
|
+
tokenizer = described_class.new(normalizes_words: [[/\&/, 'and']])
|
9
9
|
|
10
10
|
# Is this really correct? Shouldn't we split after normalizing?
|
11
11
|
#
|
data/spec/lib/category_spec.rb
CHANGED
@@ -29,9 +29,6 @@ describe Picky::Category do
|
|
29
29
|
it 'is correct' do
|
30
30
|
category.prepared_index_path.should == 'spec/test_directory/index/test/some_index/some_category'
|
31
31
|
end
|
32
|
-
it 'is correct' do
|
33
|
-
category.index_directory.should == 'spec/test_directory/index/test/some_index'
|
34
|
-
end
|
35
32
|
end
|
36
33
|
|
37
34
|
context 'tokenizer' do
|
@@ -62,7 +59,7 @@ describe Picky::Category do
|
|
62
59
|
indexing options for some_index:some_category should be either
|
63
60
|
* a Hash
|
64
61
|
or
|
65
|
-
* an object that responds to #tokenize(text) => [[token1, ...], [original1, ...]]
|
62
|
+
* an object that responds to #tokenize(text) => [[token1, token2, ...], [original1, original2, ...]]
|
66
63
|
ERROR
|
67
64
|
end
|
68
65
|
end
|