picky 2.7.0 → 3.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/lib/picky/adapters/rack/base.rb +20 -16
  2. data/lib/picky/adapters/rack/live_parameters.rb +28 -24
  3. data/lib/picky/adapters/rack/search.rb +67 -0
  4. data/lib/picky/adapters/rack.rb +27 -23
  5. data/lib/picky/application.rb +246 -236
  6. data/lib/picky/backend/base.rb +115 -119
  7. data/lib/picky/backend/file/basic.rb +102 -98
  8. data/lib/picky/backend/file/json.rb +27 -23
  9. data/lib/picky/backend/file/marshal.rb +32 -28
  10. data/lib/picky/backend/file/text.rb +45 -41
  11. data/lib/picky/backend/files.rb +19 -15
  12. data/lib/picky/backend/redis/basic.rb +76 -72
  13. data/lib/picky/backend/redis/list_hash.rb +40 -36
  14. data/lib/picky/backend/redis/string_hash.rb +30 -26
  15. data/lib/picky/backend/redis.rb +32 -28
  16. data/lib/picky/bundle.rb +82 -57
  17. data/lib/{bundling.rb → picky/bundling.rb} +0 -0
  18. data/lib/picky/calculations/location.rb +51 -47
  19. data/lib/picky/categories.rb +60 -56
  20. data/lib/picky/categories_indexed.rb +73 -82
  21. data/lib/picky/categories_indexing.rb +12 -8
  22. data/lib/picky/category.rb +109 -120
  23. data/lib/picky/category_indexed.rb +39 -41
  24. data/lib/picky/category_indexing.rb +123 -125
  25. data/lib/picky/character_substituters/west_european.rb +32 -26
  26. data/lib/{constants.rb → picky/constants.rb} +0 -0
  27. data/lib/picky/cores.rb +96 -92
  28. data/lib/{deployment.rb → picky/deployment.rb} +0 -0
  29. data/lib/picky/frontend_adapters/rack.rb +133 -118
  30. data/lib/picky/generators/aliases.rb +5 -3
  31. data/lib/picky/generators/base.rb +11 -7
  32. data/lib/picky/generators/partial/default.rb +7 -3
  33. data/lib/picky/generators/partial/none.rb +24 -20
  34. data/lib/picky/generators/partial/strategy.rb +20 -16
  35. data/lib/picky/generators/partial/substring.rb +94 -90
  36. data/lib/picky/generators/partial_generator.rb +11 -7
  37. data/lib/picky/generators/similarity/default.rb +9 -5
  38. data/lib/picky/generators/similarity/double_metaphone.rb +20 -16
  39. data/lib/picky/generators/similarity/metaphone.rb +20 -16
  40. data/lib/picky/generators/similarity/none.rb +23 -19
  41. data/lib/picky/generators/similarity/phonetic.rb +49 -45
  42. data/lib/picky/generators/similarity/soundex.rb +20 -16
  43. data/lib/picky/generators/similarity/strategy.rb +10 -6
  44. data/lib/picky/generators/similarity_generator.rb +11 -7
  45. data/lib/picky/generators/strategy.rb +14 -10
  46. data/lib/picky/generators/weights/default.rb +9 -5
  47. data/lib/picky/generators/weights/logarithmic.rb +30 -26
  48. data/lib/picky/generators/weights/strategy.rb +10 -6
  49. data/lib/picky/generators/weights_generator.rb +11 -7
  50. data/lib/picky/helpers/measuring.rb +20 -16
  51. data/lib/picky/indexed/bundle/base.rb +39 -37
  52. data/lib/picky/indexed/bundle/memory.rb +68 -64
  53. data/lib/picky/indexed/bundle/redis.rb +73 -69
  54. data/lib/picky/indexed/wrappers/bundle/calculation.rb +26 -22
  55. data/lib/picky/indexed/wrappers/bundle/location.rb +30 -26
  56. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +36 -32
  57. data/lib/picky/indexed/wrappers/category/location.rb +17 -13
  58. data/lib/picky/indexed/wrappers/exact_first.rb +46 -42
  59. data/lib/picky/indexers/base.rb +26 -22
  60. data/lib/picky/indexers/parallel.rb +62 -58
  61. data/lib/picky/indexers/serial.rb +41 -37
  62. data/lib/picky/indexes/index.rb +400 -0
  63. data/lib/picky/indexes/index_indexed.rb +24 -0
  64. data/lib/picky/indexes/index_indexing.rb +138 -0
  65. data/lib/picky/indexes/memory.rb +20 -0
  66. data/lib/picky/indexes/redis.rb +20 -0
  67. data/lib/picky/indexes.rb +68 -61
  68. data/lib/picky/indexes_indexed.rb +16 -12
  69. data/lib/picky/indexes_indexing.rb +41 -37
  70. data/lib/picky/indexing/bundle/base.rb +216 -205
  71. data/lib/picky/indexing/bundle/memory.rb +16 -11
  72. data/lib/picky/indexing/bundle/redis.rb +14 -12
  73. data/lib/picky/indexing/wrappers/category/location.rb +17 -13
  74. data/lib/picky/interfaces/live_parameters.rb +159 -154
  75. data/lib/picky/loader.rb +267 -304
  76. data/lib/picky/loggers/search.rb +20 -13
  77. data/lib/picky/no_source_specified_exception.rb +7 -3
  78. data/lib/picky/performant.rb +6 -2
  79. data/lib/picky/query/allocation.rb +71 -67
  80. data/lib/picky/query/allocations.rb +99 -94
  81. data/lib/picky/query/combination.rb +70 -66
  82. data/lib/picky/query/combinations/base.rb +56 -52
  83. data/lib/picky/query/combinations/memory.rb +36 -32
  84. data/lib/picky/query/combinations/redis.rb +66 -62
  85. data/lib/picky/query/indexes.rb +175 -160
  86. data/lib/picky/query/qualifier_category_mapper.rb +43 -0
  87. data/lib/picky/query/token.rb +165 -172
  88. data/lib/picky/query/tokens.rb +86 -82
  89. data/lib/picky/query/weights.rb +44 -48
  90. data/lib/picky/query.rb +5 -1
  91. data/lib/picky/rack/harakiri.rb +51 -47
  92. data/lib/picky/results.rb +81 -77
  93. data/lib/picky/search.rb +169 -158
  94. data/lib/picky/sinatra.rb +34 -0
  95. data/lib/picky/sources/base.rb +73 -70
  96. data/lib/picky/sources/couch.rb +61 -57
  97. data/lib/picky/sources/csv.rb +68 -64
  98. data/lib/picky/sources/db.rb +139 -135
  99. data/lib/picky/sources/delicious.rb +52 -48
  100. data/lib/picky/sources/mongo.rb +68 -63
  101. data/lib/picky/sources/wrappers/base.rb +20 -16
  102. data/lib/picky/sources/wrappers/location.rb +37 -33
  103. data/lib/picky/statistics.rb +46 -43
  104. data/lib/picky/tasks.rb +3 -0
  105. data/lib/picky/tokenizers/base.rb +192 -187
  106. data/lib/picky/tokenizers/index.rb +25 -21
  107. data/lib/picky/tokenizers/location.rb +33 -29
  108. data/lib/picky/tokenizers/query.rb +49 -43
  109. data/lib/picky.rb +21 -13
  110. data/lib/tasks/application.rake +1 -1
  111. data/lib/tasks/index.rake +3 -3
  112. data/lib/tasks/routes.rake +1 -1
  113. data/lib/tasks/server.rake +1 -1
  114. data/spec/lib/adapters/rack/base_spec.rb +1 -1
  115. data/spec/lib/adapters/rack/live_parameters_spec.rb +1 -1
  116. data/spec/lib/adapters/rack/query_spec.rb +1 -1
  117. data/spec/lib/application_spec.rb +39 -32
  118. data/spec/lib/backend/file/basic_spec.rb +2 -2
  119. data/spec/lib/backend/file/json_spec.rb +2 -2
  120. data/spec/lib/backend/file/marshal_spec.rb +2 -2
  121. data/spec/lib/backend/file/text_spec.rb +1 -1
  122. data/spec/lib/backend/files_spec.rb +14 -24
  123. data/spec/lib/backend/redis/basic_spec.rb +2 -2
  124. data/spec/lib/backend/redis/list_hash_spec.rb +3 -3
  125. data/spec/lib/backend/redis/string_hash_spec.rb +3 -3
  126. data/spec/lib/backend/redis_spec.rb +20 -13
  127. data/spec/lib/calculations/location_spec.rb +1 -1
  128. data/spec/lib/categories_indexed_spec.rb +16 -34
  129. data/spec/lib/category_indexed_spec.rb +9 -27
  130. data/spec/lib/category_indexing_spec.rb +2 -3
  131. data/spec/lib/category_spec.rb +10 -10
  132. data/spec/lib/character_substituters/west_european_spec.rb +6 -5
  133. data/spec/lib/cores_spec.rb +17 -17
  134. data/spec/lib/extensions/symbol_spec.rb +15 -1
  135. data/spec/lib/frontend_adapters/rack_spec.rb +20 -20
  136. data/spec/lib/generators/aliases_spec.rb +3 -3
  137. data/spec/lib/generators/cacher_strategy_spec.rb +1 -1
  138. data/spec/lib/generators/partial/default_spec.rb +3 -3
  139. data/spec/lib/generators/partial/none_spec.rb +2 -2
  140. data/spec/lib/generators/partial/substring_spec.rb +1 -1
  141. data/spec/lib/generators/partial_generator_spec.rb +3 -3
  142. data/spec/lib/generators/similarity/double_metaphone_spec.rb +1 -1
  143. data/spec/lib/generators/similarity/metaphone_spec.rb +1 -1
  144. data/spec/lib/generators/similarity/none_spec.rb +1 -1
  145. data/spec/lib/generators/similarity/phonetic_spec.rb +1 -1
  146. data/spec/lib/generators/similarity/soundex_spec.rb +1 -1
  147. data/spec/lib/generators/similarity_generator_spec.rb +2 -2
  148. data/spec/lib/generators/weights/logarithmic_spec.rb +1 -1
  149. data/spec/lib/generators/weights_generator_spec.rb +1 -1
  150. data/spec/lib/helpers/measuring_spec.rb +2 -2
  151. data/spec/lib/indexed/bundle/memory_spec.rb +6 -6
  152. data/spec/lib/indexed/bundle/redis_spec.rb +4 -4
  153. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +2 -3
  154. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +2 -2
  155. data/spec/lib/indexed/wrappers/exact_first_spec.rb +5 -5
  156. data/spec/lib/indexers/base_spec.rb +1 -1
  157. data/spec/lib/indexers/parallel_spec.rb +1 -1
  158. data/spec/lib/indexers/serial_spec.rb +1 -1
  159. data/spec/lib/{index/base_indexed_spec.rb → indexes/index_indexed_spec.rb} +3 -3
  160. data/spec/lib/{index/base_indexing_spec.rb → indexes/index_indexing_spec.rb} +19 -2
  161. data/spec/lib/{index/base_spec.rb → indexes/index_spec.rb} +6 -25
  162. data/spec/lib/{index → indexes}/redis_spec.rb +1 -1
  163. data/spec/lib/indexes_class_spec.rb +2 -2
  164. data/spec/lib/indexes_indexed_spec.rb +1 -1
  165. data/spec/lib/indexes_indexing_spec.rb +1 -1
  166. data/spec/lib/indexes_spec.rb +1 -1
  167. data/spec/lib/indexing/bundle/base_spec.rb +7 -5
  168. data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +4 -4
  169. data/spec/lib/indexing/bundle/memory_spec.rb +15 -15
  170. data/spec/lib/indexing/bundle/redis_spec.rb +9 -9
  171. data/spec/lib/interfaces/live_parameters_spec.rb +5 -5
  172. data/spec/lib/loader_spec.rb +17 -19
  173. data/spec/lib/loggers/search_spec.rb +2 -2
  174. data/spec/lib/query/allocation_spec.rb +1 -1
  175. data/spec/lib/query/allocations_spec.rb +1 -1
  176. data/spec/lib/query/combination_spec.rb +4 -4
  177. data/spec/lib/query/combinations/base_spec.rb +1 -1
  178. data/spec/lib/query/combinations/memory_spec.rb +1 -1
  179. data/spec/lib/query/combinations/redis_spec.rb +1 -1
  180. data/spec/lib/query/indexes_spec.rb +7 -2
  181. data/spec/lib/query/qualifier_category_mapper_spec.rb +34 -0
  182. data/spec/lib/query/token_spec.rb +32 -53
  183. data/spec/lib/query/tokens_spec.rb +30 -35
  184. data/spec/lib/query/weights_spec.rb +16 -16
  185. data/spec/lib/rack/harakiri_spec.rb +5 -5
  186. data/spec/lib/results_spec.rb +1 -1
  187. data/spec/lib/search_spec.rb +24 -22
  188. data/spec/lib/sinatra_spec.rb +36 -0
  189. data/spec/lib/sources/base_spec.rb +1 -1
  190. data/spec/lib/sources/couch_spec.rb +9 -9
  191. data/spec/lib/sources/csv_spec.rb +7 -7
  192. data/spec/lib/sources/db_spec.rb +2 -2
  193. data/spec/lib/sources/delicious_spec.rb +5 -5
  194. data/spec/lib/sources/mongo_spec.rb +7 -7
  195. data/spec/lib/sources/wrappers/base_spec.rb +2 -2
  196. data/spec/lib/sources/wrappers/location_spec.rb +1 -1
  197. data/spec/lib/statistics_spec.rb +1 -1
  198. data/spec/lib/tokenizers/base_spec.rb +2 -2
  199. data/spec/lib/tokenizers/index_spec.rb +1 -1
  200. data/spec/lib/tokenizers/query_spec.rb +1 -1
  201. metadata +30 -30
  202. data/lib/picky/adapters/rack/query.rb +0 -65
  203. data/lib/picky/index/base.rb +0 -409
  204. data/lib/picky/index/base_indexed.rb +0 -29
  205. data/lib/picky/index/base_indexing.rb +0 -127
  206. data/lib/picky/index/memory.rb +0 -16
  207. data/lib/picky/index/redis.rb +0 -16
  208. data/lib/picky/query/qualifiers.rb +0 -76
  209. data/lib/picky/query/solr.rb +0 -60
  210. data/lib/picky/signals.rb +0 -8
  211. data/lib/picky-tasks.rb +0 -6
  212. data/lib/tasks/spec.rake +0 -11
  213. data/spec/lib/query/qualifiers_spec.rb +0 -31
@@ -1,47 +1,51 @@
1
- module Tokenizers
1
+ module Picky
2
2
 
3
- class Location < Base
3
+ module Tokenizers
4
4
 
5
- attr_reader :calculation
5
+ class Location < Base
6
6
 
7
- def initialize options = {}
8
- super options
7
+ attr_reader :calculation
9
8
 
10
- grid = options[:grid]
11
- precision = options[:precision] || 1
9
+ def initialize options = {}
10
+ super options
12
11
 
13
- @calculation = Calculations::Location.new grid, precision
12
+ grid = options[:grid]
13
+ precision = options[:precision] || 1
14
14
 
15
- @minimum = 1.0 / 0
15
+ @calculation = Calculations::Location.new grid, precision
16
16
 
17
- @locations = []
18
- end
17
+ @minimum = 1.0 / 0
19
18
 
20
- #
21
- #
22
- def tokenize text
19
+ @locations = []
20
+ end
23
21
 
24
- # Gather min/max.
25
22
  #
26
- source.harvest category do |indexed_id, location|
27
- location = location.to_f
28
- minimum = location if location < minimum
29
- locations << [indexed_id, location]
30
- end
23
+ #
24
+ def tokenize text
25
+
26
+ # Gather min/max.
27
+ #
28
+ source.harvest category do |indexed_id, location|
29
+ location = location.to_f
30
+ minimum = location if location < minimum
31
+ locations << [indexed_id, location]
32
+ end
31
33
 
32
- calculation.minimum = minimum
34
+ calculation.minimum = minimum
33
35
 
34
- # Recalculate locations.
35
- #
36
- locations.each do |indexed_id, location|
37
- calculation.recalculated_range(location).each do |new_location|
38
- yield indexed_id, new_location.to_s
36
+ # Recalculate locations.
37
+ #
38
+ locations.each do |indexed_id, location|
39
+ calculation.recalculated_range(location).each do |new_location|
40
+ yield indexed_id, new_location.to_s
41
+ end
39
42
  end
43
+
44
+ # TODO Move to the right place.
45
+ #
46
+ category.indexing_exact[:location_minimum] = minimum
40
47
  end
41
48
 
42
- # TODO Move to the right place.
43
- #
44
- category.indexing_exact[:location_minimum] = minimum
45
49
  end
46
50
 
47
51
  end
@@ -1,53 +1,59 @@
1
1
  # encoding: utf-8
2
2
  #
3
- module Tokenizers
4
-
5
- # There are a few class methods that you can use to configure how a query works.
6
- #
7
- # removes_characters regexp
8
- # illegal_after_normalizing regexp
9
- # stopwords regexp
10
- # contracts_expressions regexp, to_string
11
- # splits_text_on regexp
12
- # normalizes_words [[/regexp1/, 'replacement1'], [/regexp2/, 'replacement2']]
13
- #
14
- class Query < Base
15
-
16
- def self.default= new_default
17
- @default = new_default
18
- end
19
- def self.default
20
- @default ||= new
21
- end
3
+ module Picky
22
4
 
23
- attr_reader :maximum_tokens
24
-
25
- def initialize options = {}
26
- super options
27
- @maximum_tokens = options[:maximum_tokens] || 5
28
- end
5
+ module Tokenizers
29
6
 
30
- # Let each token process itself.
31
- # Reject, limit, and partialize tokens.
7
+ # There are a few class methods that you can use to configure how a query works.
32
8
  #
33
- # In querying we work with real tokens (in indexing it's just symbols).
9
+ # removes_characters regexp
10
+ # illegal_after_normalizing regexp
11
+ # stopwords regexp
12
+ # contracts_expressions regexp, to_string
13
+ # splits_text_on regexp
14
+ # normalizes_words [[/regexp1/, 'replacement1'], [/regexp2/, 'replacement2']]
34
15
  #
35
- def process tokens
36
- tokens.reject # Reject any tokens that don't meet criteria.
37
- tokens.cap maximum_tokens # Cut off superfluous tokens.
38
- tokens.partialize_last # Set certain tokens as partial.
39
- tokens
40
- end
16
+ class Query < Base
17
+
18
+ attr_reader :qualifiers
19
+
20
+ def self.default= new_default
21
+ @default = new_default
22
+ end
23
+ def self.default
24
+ @default ||= new
25
+ end
26
+
27
+ attr_reader :maximum_tokens
28
+
29
+ def initialize options = {}
30
+ super options
31
+ @maximum_tokens = options[:maximum_tokens] || 5
32
+ end
33
+
34
+ # Let each token process itself.
35
+ # Reject, limit, and partialize tokens.
36
+ #
37
+ # In querying we work with real tokens (in indexing it's just symbols).
38
+ #
39
+ def process tokens
40
+ tokens.reject # Reject any tokens that don't meet criteria.
41
+ tokens.cap maximum_tokens # Cut off superfluous tokens.
42
+ tokens.partialize_last # Set certain tokens as partial.
43
+ tokens
44
+ end
45
+
46
+ # Converts words into real tokens.
47
+ #
48
+ def tokens_for words
49
+ Picky::Query::Tokens.processed words, downcase?
50
+ end
51
+ # Returns a tokens object.
52
+ #
53
+ def empty_tokens
54
+ Picky::Query::Tokens.new
55
+ end
41
56
 
42
- # Converts words into real tokens.
43
- #
44
- def tokens_for words
45
- ::Query::Tokens.processed words, downcase?
46
- end
47
- # Returns a tokens object.
48
- #
49
- def empty_tokens
50
- ::Query::Tokens.new
51
57
  end
52
58
 
53
59
  end
data/lib/picky.rb CHANGED
@@ -1,16 +1,24 @@
1
- # Require the constants.
2
- #
3
- require File.expand_path '../constants', __FILE__
1
+ module Picky
4
2
 
5
- # Library bundling.
6
- #
7
- require File.expand_path '../bundling', __FILE__
3
+ # Require the constants.
4
+ #
5
+ require ::File.expand_path '../picky/constants', __FILE__
8
6
 
9
- # Loader which handles framework and app loading.
10
- #
11
- require File.expand_path '../picky/loader', __FILE__
7
+ # Library bundling.
8
+ #
9
+ require ::File.expand_path '../picky/bundling', __FILE__
12
10
 
13
- # Load the framework
14
- #
15
- Loader.load_framework
16
- puts "Loaded picky with environment '#{PICKY_ENVIRONMENT}' in #{PICKY_ROOT} on Ruby #{RUBY_VERSION}."
11
+ # Loader which handles framework and app loading.
12
+ #
13
+ require ::File.expand_path '../picky/loader', __FILE__
14
+
15
+ # Load the framework
16
+ #
17
+ Loader.load_framework
18
+ puts "Loaded picky with environment '#{PICKY_ENVIRONMENT}' in #{PICKY_ROOT} on Ruby #{RUBY_VERSION}."
19
+
20
+ # Check if delegators need to be installed.
21
+ #
22
+ require ::File.expand_path '../picky/sinatra', __FILE__
23
+
24
+ end
@@ -3,5 +3,5 @@
3
3
  # Note: This is used by tasks to load the application (and the framework) as a dependency.
4
4
  #
5
5
  task :application => :framework do
6
- Loader.load_application
6
+ Picky::Loader.load_application
7
7
  end
data/lib/tasks/index.rake CHANGED
@@ -4,7 +4,7 @@ desc "Generate the index (index, category optional)."
4
4
  task :index, [:index, :category] => :application do |_, options|
5
5
  index, category = options.index, options.category
6
6
 
7
- specific = Indexes
7
+ specific = Picky::Indexes
8
8
  specific = specific[index] if index
9
9
  specific = specific[category] if category
10
10
  specific.index
@@ -16,11 +16,11 @@ namespace :index do
16
16
  #
17
17
  # desc "Takes a snapshot, indexes, and caches in random order."
18
18
  task :randomly => :application do
19
- Indexes.index true
19
+ Picky::Indexes.index true
20
20
  end
21
21
  # desc "Takes a snapshot, indexes, and caches in order given."
22
22
  task :ordered => :application do
23
- Indexes.index false
23
+ Picky::Indexes.index false
24
24
  end
25
25
 
26
26
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  desc "Shows the available URL paths."
4
4
  task :routes => :application do
5
- Application.apps.each do |app|
5
+ Picky::Application.apps.each do |app|
6
6
  puts app.to_routes
7
7
  end
8
8
  end
@@ -16,7 +16,7 @@ namespace :server do
16
16
  task :start => :framework do
17
17
  chdir_to_root
18
18
  daemonize = PICKY_ENVIRONMENT == 'production' ? '-D' : ''
19
- command = "export PICKY_ENV=#{PICKY_ENVIRONMENT}; unicorn -c unicorn.ru #{daemonize}".strip
19
+ command = "export PICKY_ENV=#{PICKY_ENVIRONMENT}; unicorn -c unicorn.rb #{daemonize}".strip
20
20
  puts "Running \`#{command}\`."
21
21
  exec command
22
22
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Adapters::Rack::Base do
5
+ describe Picky::Adapters::Rack::Base do
6
6
 
7
7
  before(:each) do
8
8
  @adapter = described_class.new
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Adapters::Rack::LiveParameters do
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 }
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Adapters::Rack::Query do
5
+ describe Picky::Adapters::Rack::Search do
6
6
 
7
7
  before(:each) do
8
8
  @query = stub :query
@@ -2,28 +2,32 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Application do
5
+ describe Picky::Application do
6
6
 
7
7
  describe "integration" do
8
8
  it "should run ok" do
9
9
  lambda {
10
- class MinimalTestApplication < Application
11
- books = Index::Memory.new :books, source: Sources::DB.new('SELECT id, title FROM books', :file => 'app/db.yml')
10
+ class MinimalTestApplication < described_class
11
+ books = Picky::Indexes::Memory.new :books,
12
+ source: Picky::Sources::DB.new(
13
+ 'SELECT id, title FROM books',
14
+ :file => 'app/db.yml'
15
+ )
12
16
  books.define_category :title
13
17
 
14
18
  rack_adapter.stub! :exclaim # Stopping it from exclaiming.
15
19
 
16
- route %r{^/books} => Search.new(books)
20
+ route %r{^/books} => Picky::Search.new(books)
17
21
  end
18
- Tokenizers::Index.default.tokenize 'some text'
19
- Tokenizers::Query.default.tokenize 'some text'
22
+ Picky::Tokenizers::Index.default.tokenize 'some text'
23
+ Picky::Tokenizers::Query.default.tokenize 'some text'
20
24
  }.should_not raise_error
21
25
  end
22
26
  it "should run ok" do
23
27
  lambda {
24
28
  # Here we just test if the API can be called ok.
25
29
  #
26
- class TestApplication < Application
30
+ class TestApplication < described_class
27
31
  indexing removes_characters: /[^a-zA-Z0-9\s\/\-\"\&\.]/,
28
32
  stopwords: /\b(and|the|of|it|in|for)\b/,
29
33
  splits_text_on: /[\s\/\-\"\&\.]/,
@@ -36,31 +40,34 @@ describe Application do
36
40
  splits_text_on: /[\s\/\-\,\&]+/,
37
41
  normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
38
42
 
39
- substitutes_characters_with: CharacterSubstituters::WestEuropean.new,
43
+ substitutes_characters_with: Picky::CharacterSubstituters::WestEuropean.new,
40
44
  maximum_tokens: 5
41
45
 
42
- books_index = Index::Memory.new :books,
43
- source: Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
46
+ books_index = Picky::Indexes::Memory.new :books,
47
+ source: Picky::Sources::DB.new(
48
+ 'SELECT id, title, author, isbn13 as isbn FROM books',
49
+ :file => 'app/db.yml'
50
+ )
44
51
  books_index.define_category :title,
45
- similarity: Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed.
52
+ similarity: Picky::Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed.
46
53
  books_index.define_category :author,
47
- similarity: Similarity::Soundex.new(2)
54
+ similarity: Picky::Similarity::Soundex.new(2)
48
55
  books_index.define_category :isbn,
49
- partial: Partial::None.new # Partially searching on an ISBN makes not much sense.
56
+ partial: Picky::Partial::None.new # Partially searching on an ISBN makes not much sense.
50
57
 
51
- geo_index = Index::Memory.new :geo do
52
- source Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
58
+ geo_index = Picky::Indexes::Memory.new :geo do
59
+ source Picky::Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
53
60
  indexing removes_characters: /[^a-z]/
54
61
  category :location,
55
- similarity: Similarity::Metaphone.new(4)
62
+ similarity: Picky::Similarity::Metaphone.new(4)
56
63
  ranged_category :north1, 1, precision: 3, from: :north
57
64
  ranged_category :east1, 1, precision: 3, from: :east
58
65
  end
59
66
 
60
67
  rack_adapter.stub! :exclaim # Stopping it from exclaiming.
61
68
 
62
- route %r{^/books} => Search.new(books_index)
63
- route %r{^/buks} => Search.new(books_index) do
69
+ route %r{^/books} => Picky::Search.new(books_index)
70
+ route %r{^/buks} => Picky::Search.new(books_index) do
64
71
  searching removes_characters: /[buks]/
65
72
  end
66
73
  end
@@ -70,57 +77,57 @@ describe Application do
70
77
 
71
78
  describe 'finalize' do
72
79
  before(:each) do
73
- Application.stub! :check
80
+ described_class.stub! :check
74
81
  end
75
82
  it 'checks if all is ok' do
76
- Application.should_receive(:check).once.with
83
+ described_class.should_receive(:check).once.with
77
84
 
78
- Application.finalize
85
+ described_class.finalize
79
86
  end
80
87
  it 'tells the rack adapter to finalize' do
81
- Application.rack_adapter.should_receive(:finalize).once.with
88
+ described_class.rack_adapter.should_receive(:finalize).once.with
82
89
 
83
- Application.finalize
90
+ described_class.finalize
84
91
  end
85
92
  end
86
93
 
87
94
  describe 'check' do
88
95
  it 'does something' do
89
- Application.should_receive(:warn).once.with "\nWARNING: No routes defined for application configuration in Class.\n\n"
96
+ described_class.should_receive(:warn).once.with "\nWARNING: No routes defined for application configuration in Class.\n\n"
90
97
 
91
- Application.check
98
+ described_class.check
92
99
  end
93
100
  end
94
101
 
95
102
  describe 'delegation' do
96
103
  it "should delegate route" do
97
- Application.rack_adapter.should_receive(:route).once.with :path => :query
104
+ described_class.rack_adapter.should_receive(:route).once.with :path => :query
98
105
 
99
- Application.route :path => :query
106
+ described_class.route :path => :query
100
107
  end
101
108
  end
102
109
 
103
110
  describe 'rack_adapter' do
104
111
  it 'should be there' do
105
- lambda { Application.rack_adapter }.should_not raise_error
112
+ lambda { described_class.rack_adapter }.should_not raise_error
106
113
  end
107
114
  it "should return a new FrontendAdapters::Rack instance" do
108
- Application.rack_adapter.should be_kind_of(FrontendAdapters::Rack)
115
+ described_class.rack_adapter.should be_kind_of(Picky::FrontendAdapters::Rack)
109
116
  end
110
117
  it "should cache the instance" do
111
- Application.rack_adapter.should == Application.rack_adapter
118
+ described_class.rack_adapter.should == described_class.rack_adapter
112
119
  end
113
120
  end
114
121
 
115
122
  describe 'call' do
116
123
  before(:each) do
117
124
  @routes = stub :routes
118
- Application.stub! :rack_adapter => @routes
125
+ described_class.stub! :rack_adapter => @routes
119
126
  end
120
127
  it 'should delegate' do
121
128
  @routes.should_receive(:call).once.with :env
122
129
 
123
- Application.call :env
130
+ described_class.call :env
124
131
  end
125
132
  end
126
133
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::File::Basic do
3
+ describe Picky::Backend::File::Basic do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
@@ -18,7 +18,7 @@ describe Backend::File::Basic do
18
18
 
19
19
  describe 'to_s' do
20
20
  it 'returns the cache path with the default file extension' do
21
- file.to_s.should == 'Backend::File::Basic(some/cache/path/to/file.index)'
21
+ file.to_s.should == 'Picky::Backend::File::Basic(some/cache/path/to/file.index)'
22
22
  end
23
23
  end
24
24
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::File::JSON do
3
+ describe Picky::Backend::File::JSON do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
@@ -24,7 +24,7 @@ describe Backend::File::JSON do
24
24
 
25
25
  describe 'to_s' do
26
26
  it 'returns the cache path with the default file extension' do
27
- file.to_s.should == 'Backend::File::JSON(some/cache/path/to/file.json)'
27
+ file.to_s.should == 'Picky::Backend::File::JSON(some/cache/path/to/file.json)'
28
28
  end
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::File::Marshal do
3
+ describe Picky::Backend::File::Marshal do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
@@ -24,7 +24,7 @@ describe Backend::File::Marshal do
24
24
 
25
25
  describe 'to_s' do
26
26
  it 'returns the cache path with the default file extension' do
27
- file.to_s.should == 'Backend::File::Marshal(some/cache/path/to/file.dump)'
27
+ file.to_s.should == 'Picky::Backend::File::Marshal(some/cache/path/to/file.dump)'
28
28
  end
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::File::Text do
3
+ describe Picky::Backend::File::Text do
4
4
 
5
5
  before(:each) do
6
6
  @file = described_class.new "some_cache_path"
@@ -1,14 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::Files do
3
+ describe Picky::Backend::Files do
4
4
 
5
5
  before(:each) do
6
- index = Index::Memory.new :some_index, source: []
7
- category = Category.new :some_category, index
6
+ index = Picky::Indexes::Memory.new :some_index, source: []
7
+ category = Picky::Category.new :some_category, index
8
+ bundle = Picky::Indexing::Bundle::Base.new :some_bundle, category, nil, nil, nil
8
9
 
9
- @files = described_class.new :some_name, category
10
-
11
- @prepared = @files.prepared
10
+ @files = described_class.new bundle
12
11
 
13
12
  @index = @files.inverted
14
13
  @weights = @files.weights
@@ -16,14 +15,6 @@ describe Backend::Files do
16
15
  @configuration = @files.configuration
17
16
  end
18
17
 
19
- describe "retrieve" do
20
- it "delegates to the prepared" do
21
- @prepared.should_receive(:retrieve).once.with
22
-
23
- @files.retrieve
24
- end
25
- end
26
-
27
18
  describe "dump indexes" do
28
19
  before(:each) do
29
20
  @files.stub! :timed_exclaim
@@ -66,7 +57,7 @@ describe Backend::Files do
66
57
  it "uses the right file" do
67
58
  Yajl::Parser.stub! :parse
68
59
 
69
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_inverted.json', 'r'
60
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_bundle_inverted.json', 'r'
70
61
 
71
62
  @files.load_inverted
72
63
  end
@@ -75,7 +66,7 @@ describe Backend::Files do
75
66
  it "uses the right file" do
76
67
  Yajl::Parser.stub! :parse
77
68
 
78
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_weights.json', 'r'
69
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_bundle_weights.json', 'r'
79
70
 
80
71
  @files.load_weights
81
72
  end
@@ -84,7 +75,7 @@ describe Backend::Files do
84
75
  it "uses the right file" do
85
76
  Marshal.stub! :load
86
77
 
87
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_similarity.dump', 'r:binary'
78
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_bundle_similarity.dump', 'r:binary'
88
79
 
89
80
  @files.load_similarity
90
81
  end
@@ -93,7 +84,7 @@ describe Backend::Files do
93
84
  it "uses the right file" do
94
85
  Yajl::Parser.stub! :parse
95
86
 
96
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_configuration.json', 'r'
87
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_bundle_configuration.json', 'r'
97
88
 
98
89
  @files.load_configuration
99
90
  end
@@ -181,18 +172,17 @@ describe Backend::Files do
181
172
 
182
173
  describe 'initialization' do
183
174
  it 'should initialize the name correctly' do
184
- @files.bundle_name.should == :some_name
175
+ @files.bundle.name.should == :some_bundle
185
176
  end
186
177
  end
187
178
 
188
179
  describe 'to_s' do
189
180
  it 'returns the right value' do
190
- category = stub :category,
191
- :identifier => "category_identifier",
192
- :prepared_index_path => "prepared/index/path",
193
- :index_path => 'index/path'
181
+ bundle = stub :bundle,
182
+ :index_path => 'index/path',
183
+ :prepared_index_path => 'prepared/index/path'
194
184
 
195
- described_class.new("some_bundle", category).to_s.should == "Backend::Files(Backend::File::Text(prepared/index/path.txt), Backend::File::JSON(index/path.json), Backend::File::JSON(index/path.json), Backend::File::Marshal(index/path.dump), Backend::File::JSON(index/path.json))"
185
+ described_class.new(bundle).to_s.should == "Picky::Backend::Files(Picky::Backend::File::JSON(index/path.json), Picky::Backend::File::JSON(index/path.json), Picky::Backend::File::Marshal(index/path.dump), Picky::Backend::File::JSON(index/path.json))"
196
186
  end
197
187
  end
198
188
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::Redis::Basic do
3
+ describe Picky::Backend::Redis::Basic do
4
4
 
5
5
  let(:redis) { described_class.new "some_namespace" }
6
6
 
@@ -66,7 +66,7 @@ describe Backend::Redis::Basic do
66
66
 
67
67
  describe 'to_s' do
68
68
  it 'returns the cache path with the default file extension' do
69
- redis.to_s.should == 'Backend::Redis::Basic(some_namespace:*)'
69
+ redis.to_s.should == 'Picky::Backend::Redis::Basic(some_namespace:*)'
70
70
  end
71
71
  end
72
72
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Backend::Redis::ListHash do
3
+ describe Picky::Backend::Redis::ListHash do
4
4
 
5
5
  let(:index) { described_class.new :some_namespace }
6
6
 
@@ -8,7 +8,7 @@ describe Backend::Redis::ListHash do
8
8
  it 'raises an error' do
9
9
  expect {
10
10
  index.member :some_sym
11
- }.to raise_error("Can't retrieve single value :some_sym from a Redis ListHash. Use Index::Redis::StringHash.")
11
+ }.to raise_error("Can't retrieve single value :some_sym from a Redis ListHash. Use Indexes::Redis::StringHash.")
12
12
  end
13
13
  end
14
14
 
@@ -33,7 +33,7 @@ describe Backend::Redis::ListHash do
33
33
 
34
34
  describe 'to_s' do
35
35
  it 'returns the cache path with the default file extension' do
36
- index.to_s.should == 'Backend::Redis::ListHash(some_namespace:*)'
36
+ index.to_s.should == 'Picky::Backend::Redis::ListHash(some_namespace:*)'
37
37
  end
38
38
  end
39
39