picky 1.4.1 → 1.4.2

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.
Files changed (229) hide show
  1. data/lib/picky/{alias_instances.rb → aliases.rb} +1 -3
  2. data/lib/picky/application.rb +18 -19
  3. data/lib/picky/cores.rb +1 -1
  4. data/lib/picky/generators/aliases.rb +3 -0
  5. data/lib/picky/index/base.rb +179 -0
  6. data/lib/picky/index/memory.rb +28 -0
  7. data/lib/picky/index/redis.rb +28 -0
  8. data/lib/picky/{indexes_api.rb → index_bundle.rb} +16 -16
  9. data/lib/picky/indexed/indexes.rb +11 -7
  10. data/lib/picky/indexing/indexes.rb +14 -8
  11. data/lib/picky/internals/adapters/rack/base.rb +27 -0
  12. data/lib/picky/internals/adapters/rack/live_parameters.rb +37 -0
  13. data/lib/picky/internals/adapters/rack/query.rb +63 -0
  14. data/lib/picky/internals/adapters/rack.rb +34 -0
  15. data/lib/picky/{calculations → internals/calculations}/location.rb +0 -0
  16. data/lib/picky/{cli.rb → internals/cli.rb} +0 -0
  17. data/lib/picky/{configuration → internals/configuration}/index.rb +8 -2
  18. data/lib/picky/{ext → internals/ext}/maybe_compile.rb +0 -0
  19. data/lib/picky/{ext → internals/ext}/ruby19/extconf.rb +0 -0
  20. data/lib/picky/{ext → internals/ext}/ruby19/performant.c +0 -0
  21. data/lib/picky/{extensions → internals/extensions}/array.rb +0 -0
  22. data/lib/picky/{extensions → internals/extensions}/hash.rb +0 -0
  23. data/lib/picky/{extensions → internals/extensions}/module.rb +0 -0
  24. data/lib/picky/{extensions → internals/extensions}/object.rb +0 -0
  25. data/lib/picky/{extensions → internals/extensions}/symbol.rb +0 -0
  26. data/lib/picky/internals/frontend_adapters/rack.rb +154 -0
  27. data/lib/picky/internals/generators/base.rb +19 -0
  28. data/lib/picky/internals/generators/partial/default.rb +7 -0
  29. data/lib/picky/internals/generators/partial/none.rb +35 -0
  30. data/lib/picky/internals/generators/partial/strategy.rb +29 -0
  31. data/lib/picky/internals/generators/partial/substring.rb +122 -0
  32. data/lib/picky/internals/generators/partial_generator.rb +19 -0
  33. data/lib/picky/internals/generators/similarity/default.rb +9 -0
  34. data/lib/picky/internals/generators/similarity/double_levenshtone.rb +81 -0
  35. data/lib/picky/internals/generators/similarity/none.rb +35 -0
  36. data/lib/picky/internals/generators/similarity/strategy.rb +11 -0
  37. data/lib/picky/internals/generators/similarity_generator.rb +19 -0
  38. data/lib/picky/internals/generators/strategy.rb +18 -0
  39. data/lib/picky/internals/generators/weights/default.rb +9 -0
  40. data/lib/picky/internals/generators/weights/logarithmic.rb +43 -0
  41. data/lib/picky/internals/generators/weights/strategy.rb +11 -0
  42. data/lib/picky/internals/generators/weights_generator.rb +19 -0
  43. data/lib/picky/{helpers → internals/helpers}/measuring.rb +0 -0
  44. data/lib/picky/internals/index/backend.rb +113 -0
  45. data/lib/picky/internals/index/file/basic.rb +101 -0
  46. data/lib/picky/internals/index/file/json.rb +38 -0
  47. data/lib/picky/internals/index/file/marshal.rb +38 -0
  48. data/lib/picky/internals/index/file/text.rb +60 -0
  49. data/lib/picky/internals/index/files.rb +24 -0
  50. data/lib/picky/internals/index/redis/basic.rb +77 -0
  51. data/lib/picky/internals/index/redis/list_hash.rb +46 -0
  52. data/lib/picky/internals/index/redis/string_hash.rb +35 -0
  53. data/lib/picky/internals/index/redis.rb +44 -0
  54. data/lib/picky/internals/indexed/bundle/base.rb +72 -0
  55. data/lib/picky/internals/indexed/bundle/memory.rb +69 -0
  56. data/lib/picky/internals/indexed/bundle/redis.rb +70 -0
  57. data/lib/picky/internals/indexed/categories.rb +135 -0
  58. data/lib/picky/internals/indexed/category.rb +90 -0
  59. data/lib/picky/internals/indexed/index.rb +57 -0
  60. data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/calculation.rb +0 -0
  61. data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/location.rb +4 -2
  62. data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/wrapper.rb +1 -1
  63. data/lib/picky/internals/indexed/wrappers/exact_first.rb +65 -0
  64. data/lib/picky/{indexers → internals/indexers}/no_source_specified_error.rb +0 -0
  65. data/lib/picky/{indexers → internals/indexers}/serial.rb +2 -2
  66. data/lib/picky/{indexers → internals/indexers}/solr.rb +0 -0
  67. data/lib/picky/internals/indexing/bundle/base.rb +219 -0
  68. data/lib/picky/internals/indexing/bundle/memory.rb +25 -0
  69. data/lib/picky/internals/indexing/bundle/redis.rb +28 -0
  70. data/lib/picky/internals/indexing/bundle/super_base.rb +65 -0
  71. data/lib/picky/internals/indexing/categories.rb +42 -0
  72. data/lib/picky/internals/indexing/category.rb +120 -0
  73. data/lib/picky/internals/indexing/index.rb +67 -0
  74. data/lib/picky/{performant.rb → internals/performant.rb} +0 -0
  75. data/lib/picky/internals/query/allocation.rb +88 -0
  76. data/lib/picky/internals/query/allocations.rb +137 -0
  77. data/lib/picky/internals/query/combination.rb +80 -0
  78. data/lib/picky/internals/query/combinations/base.rb +84 -0
  79. data/lib/picky/internals/query/combinations/memory.rb +58 -0
  80. data/lib/picky/internals/query/combinations/redis.rb +59 -0
  81. data/lib/picky/internals/query/indexes.rb +180 -0
  82. data/lib/picky/internals/query/qualifiers.rb +81 -0
  83. data/lib/picky/internals/query/token.rb +215 -0
  84. data/lib/picky/internals/query/tokens.rb +89 -0
  85. data/lib/picky/{query → internals/query}/weights.rb +0 -0
  86. data/lib/picky/internals/results/base.rb +106 -0
  87. data/lib/picky/internals/results/full.rb +17 -0
  88. data/lib/picky/internals/results/live.rb +17 -0
  89. data/lib/picky/{solr → internals/solr}/schema_generator.rb +0 -0
  90. data/lib/picky/internals/tokenizers/base.rb +166 -0
  91. data/lib/picky/internals/tokenizers/index.rb +63 -0
  92. data/lib/picky/internals/tokenizers/query.rb +79 -0
  93. data/lib/picky/loader.rb +148 -112
  94. data/lib/picky/query/base.rb +57 -26
  95. data/lib/picky/query/full.rb +1 -1
  96. data/lib/picky/query/live.rb +1 -1
  97. data/lib/picky/sources/db.rb +27 -6
  98. data/lib/tasks/index.rake +3 -3
  99. data/lib/tasks/try.rake +2 -2
  100. data/spec/lib/aliases_spec.rb +9 -0
  101. data/spec/lib/application_spec.rb +3 -3
  102. data/spec/lib/generators/aliases_spec.rb +1 -0
  103. data/spec/lib/{index_api_spec.rb → index/base_spec.rb} +7 -7
  104. data/spec/lib/index_bundle_spec.rb +71 -0
  105. data/spec/lib/indexed/indexes_spec.rb +61 -0
  106. data/spec/lib/indexing/indexes_spec.rb +94 -24
  107. data/spec/lib/{adapters → internals/adapters}/rack/base_spec.rb +2 -2
  108. data/spec/lib/{adapters → internals/adapters}/rack/live_parameters_spec.rb +2 -2
  109. data/spec/lib/{adapters → internals/adapters}/rack/query_spec.rb +2 -2
  110. data/spec/lib/{calculations → internals/calculations}/location_spec.rb +0 -0
  111. data/spec/lib/{cli_spec.rb → internals/cli_spec.rb} +4 -1
  112. data/spec/lib/{configuration → internals/configuration}/index_spec.rb +1 -1
  113. data/spec/lib/{cores_spec.rb → internals/cores_spec.rb} +0 -0
  114. data/spec/lib/{extensions → internals/extensions}/array_spec.rb +0 -0
  115. data/spec/lib/{extensions → internals/extensions}/hash_spec.rb +0 -0
  116. data/spec/lib/{extensions → internals/extensions}/module_spec.rb +0 -0
  117. data/spec/lib/{extensions → internals/extensions}/object_spec.rb +0 -0
  118. data/spec/lib/{extensions → internals/extensions}/symbol_spec.rb +0 -0
  119. data/spec/lib/{frontend_adapters → internals/frontend_adapters}/rack_spec.rb +11 -11
  120. data/spec/lib/{cacher → internals/generators}/cacher_strategy_spec.rb +2 -2
  121. data/spec/lib/internals/generators/partial/default_spec.rb +17 -0
  122. data/spec/lib/internals/generators/partial/none_spec.rb +17 -0
  123. data/spec/lib/{cacher → internals/generators}/partial/substring_spec.rb +26 -27
  124. data/spec/lib/{cacher → internals/generators}/partial_generator_spec.rb +5 -5
  125. data/spec/lib/{cacher → internals/generators}/similarity/double_levenshtone_spec.rb +4 -4
  126. data/spec/lib/{cacher → internals/generators}/similarity/none_spec.rb +2 -2
  127. data/spec/lib/{cacher → internals/generators}/similarity_generator_spec.rb +4 -4
  128. data/spec/lib/{cacher → internals/generators}/weights/logarithmic_spec.rb +2 -2
  129. data/spec/lib/internals/generators/weights_generator_spec.rb +21 -0
  130. data/spec/lib/{helpers → internals/helpers}/measuring_spec.rb +0 -0
  131. data/spec/lib/{index → internals/index}/file/basic_spec.rb +2 -2
  132. data/spec/lib/{index → internals/index}/file/json_spec.rb +2 -2
  133. data/spec/lib/{index → internals/index}/file/marshal_spec.rb +2 -2
  134. data/spec/lib/{index → internals/index}/file/text_spec.rb +2 -2
  135. data/spec/lib/{index → internals/index}/files_spec.rb +2 -2
  136. data/spec/lib/{indexed/bundle_spec.rb → internals/indexed/bundle/memory_spec.rb} +4 -5
  137. data/spec/lib/{indexed → internals/indexed}/categories_spec.rb +13 -13
  138. data/spec/lib/{indexed → internals/indexed}/category_spec.rb +59 -32
  139. data/spec/lib/{indexed → internals/indexed}/index_spec.rb +5 -5
  140. data/spec/lib/{indexed → internals/indexed}/wrappers/bundle/calculation_spec.rb +0 -0
  141. data/spec/lib/{indexed → internals/indexed}/wrappers/bundle/wrapper_spec.rb +0 -0
  142. data/spec/lib/{indexed → internals/indexed}/wrappers/exact_first_spec.rb +5 -5
  143. data/spec/lib/{indexers → internals/indexers}/serial_spec.rb +0 -0
  144. data/spec/lib/{indexing/bundle_partial_generation_speed_spec.rb → internals/indexing/bundle/memory_partial_generation_speed_spec.rb} +3 -3
  145. data/spec/lib/{indexing/bundle_spec.rb → internals/indexing/bundle/memory_spec.rb} +3 -3
  146. data/spec/lib/{index/bundle_spec.rb → internals/indexing/bundle/super_base_spec.rb} +9 -3
  147. data/spec/lib/{indexing → internals/indexing}/category_spec.rb +3 -3
  148. data/spec/lib/{indexing → internals/indexing}/index_spec.rb +3 -3
  149. data/spec/lib/internals/indexing/indexes_spec.rb +36 -0
  150. data/spec/lib/{interfaces → internals/interfaces}/live_parameters_spec.rb +0 -0
  151. data/spec/lib/internals/results/base_spec.rb +105 -0
  152. data/spec/lib/internals/results/full_spec.rb +78 -0
  153. data/spec/lib/internals/results/live_spec.rb +88 -0
  154. data/spec/lib/{solr → internals/solr}/schema_generator_spec.rb +0 -0
  155. data/spec/lib/{tokenizers → internals/tokenizers}/base_spec.rb +3 -3
  156. data/spec/lib/{tokenizers → internals/tokenizers}/index_spec.rb +9 -9
  157. data/spec/lib/{tokenizers → internals/tokenizers}/query_spec.rb +11 -11
  158. data/spec/lib/query/allocation_spec.rb +12 -12
  159. data/spec/lib/query/allocations_spec.rb +19 -19
  160. data/spec/lib/query/base_spec.rb +28 -4
  161. data/spec/lib/query/combination_spec.rb +8 -9
  162. data/spec/lib/query/combinations/base_spec.rb +116 -0
  163. data/spec/lib/query/{combinations_spec.rb → combinations/memory_spec.rb} +14 -14
  164. data/spec/lib/query/combinations/redis_spec.rb +132 -0
  165. data/spec/lib/query/full_spec.rb +2 -2
  166. data/spec/lib/query/indexes_spec.rb +81 -0
  167. data/spec/lib/query/live_spec.rb +3 -3
  168. data/spec/lib/query/qualifiers_spec.rb +6 -6
  169. data/spec/lib/query/token_spec.rb +38 -38
  170. data/spec/lib/query/tokens_spec.rb +35 -35
  171. data/spec/lib/sources/db_spec.rb +23 -18
  172. metadata +212 -181
  173. data/lib/picky/adapters/rack/base.rb +0 -23
  174. data/lib/picky/adapters/rack/live_parameters.rb +0 -33
  175. data/lib/picky/adapters/rack/query.rb +0 -59
  176. data/lib/picky/adapters/rack.rb +0 -28
  177. data/lib/picky/cacher/convenience.rb +0 -3
  178. data/lib/picky/cacher/generator.rb +0 -15
  179. data/lib/picky/cacher/partial/default.rb +0 -5
  180. data/lib/picky/cacher/partial/none.rb +0 -31
  181. data/lib/picky/cacher/partial/strategy.rb +0 -21
  182. data/lib/picky/cacher/partial/substring.rb +0 -118
  183. data/lib/picky/cacher/partial_generator.rb +0 -15
  184. data/lib/picky/cacher/similarity/default.rb +0 -7
  185. data/lib/picky/cacher/similarity/double_levenshtone.rb +0 -77
  186. data/lib/picky/cacher/similarity/none.rb +0 -31
  187. data/lib/picky/cacher/similarity/strategy.rb +0 -9
  188. data/lib/picky/cacher/similarity_generator.rb +0 -15
  189. data/lib/picky/cacher/strategy.rb +0 -12
  190. data/lib/picky/cacher/weights/default.rb +0 -7
  191. data/lib/picky/cacher/weights/logarithmic.rb +0 -39
  192. data/lib/picky/cacher/weights/strategy.rb +0 -9
  193. data/lib/picky/cacher/weights_generator.rb +0 -15
  194. data/lib/picky/frontend_adapters/rack.rb +0 -150
  195. data/lib/picky/index/bundle.rb +0 -54
  196. data/lib/picky/index/file/basic.rb +0 -97
  197. data/lib/picky/index/file/json.rb +0 -34
  198. data/lib/picky/index/file/marshal.rb +0 -34
  199. data/lib/picky/index/file/text.rb +0 -56
  200. data/lib/picky/index/files.rb +0 -118
  201. data/lib/picky/index_api.rb +0 -175
  202. data/lib/picky/indexed/bundle.rb +0 -54
  203. data/lib/picky/indexed/categories.rb +0 -131
  204. data/lib/picky/indexed/category.rb +0 -85
  205. data/lib/picky/indexed/index.rb +0 -39
  206. data/lib/picky/indexed/wrappers/exact_first.rb +0 -61
  207. data/lib/picky/indexing/bundle.rb +0 -213
  208. data/lib/picky/indexing/categories.rb +0 -38
  209. data/lib/picky/indexing/category.rb +0 -117
  210. data/lib/picky/indexing/index.rb +0 -55
  211. data/lib/picky/query/allocation.rb +0 -82
  212. data/lib/picky/query/allocations.rb +0 -130
  213. data/lib/picky/query/combination.rb +0 -74
  214. data/lib/picky/query/combinations.rb +0 -105
  215. data/lib/picky/query/qualifiers.rb +0 -77
  216. data/lib/picky/query/token.rb +0 -202
  217. data/lib/picky/query/tokens.rb +0 -86
  218. data/lib/picky/query/weigher.rb +0 -165
  219. data/lib/picky/results/base.rb +0 -102
  220. data/lib/picky/results/full.rb +0 -13
  221. data/lib/picky/results/live.rb +0 -13
  222. data/lib/picky/tokenizers/base.rb +0 -161
  223. data/lib/picky/tokenizers/index.rb +0 -58
  224. data/lib/picky/tokenizers/query.rb +0 -74
  225. data/spec/lib/cacher/partial/default_spec.rb +0 -15
  226. data/spec/lib/cacher/partial/none_spec.rb +0 -17
  227. data/spec/lib/cacher/weights_generator_spec.rb +0 -21
  228. data/spec/lib/results/base_spec.rb +0 -257
  229. data/spec/lib/results/live_spec.rb +0 -15
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexed::Wrappers::ExactFirst do
3
+ describe Internals::Indexed::Wrappers::ExactFirst do
4
4
 
5
5
  before(:each) do
6
6
  @exact = stub :exact
7
7
  @partial = stub :partial
8
8
  @category = stub :category, :exact => @exact, :partial => @partial
9
9
 
10
- @wrapper = Indexed::Wrappers::ExactFirst.new @category
10
+ @wrapper = described_class.new @category
11
11
  end
12
12
 
13
13
  describe "self.wrap" do
@@ -23,17 +23,17 @@ describe Indexed::Wrappers::ExactFirst do
23
23
  # type.categories.should be_kind_of(Index::Wrappers::ExactFirst)
24
24
  # end
25
25
  it "returns the type" do
26
- type = Indexed::Index.new :type_name
26
+ type = Internals::Indexed::Index.new :type_name
27
27
  type.define_category :some_category
28
28
 
29
- Indexed::Wrappers::ExactFirst.wrap(type).should == type
29
+ described_class.wrap(type).should == type
30
30
  end
31
31
  end
32
32
  context "category" do
33
33
  it "wraps each category" do
34
34
  category = stub :category, :exact => :exact, :partial => :partial
35
35
 
36
- Indexed::Wrappers::ExactFirst.wrap(category).should be_kind_of(Indexed::Wrappers::ExactFirst)
36
+ described_class.wrap(category).should be_kind_of(described_class)
37
37
  end
38
38
  end
39
39
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexing::Bundle do
3
+ describe Internals::Indexing::Bundle::Memory do
4
4
 
5
5
  before(:each) do
6
6
  @category = stub :category, :name => :some_category
7
7
  @index = stub :index, :name => :some_index
8
8
  @configuration = Configuration::Index.new @index, @category
9
9
 
10
- @partial_strategy = Cacher::Partial::Substring.new :from => 1
11
- @exact = Indexing::Bundle.new :some_name, @configuration, nil, @partial_strategy, nil
10
+ @partial_strategy = Internals::Generators::Partial::Substring.new :from => 1
11
+ @exact = described_class.new :some_name, @configuration, nil, @partial_strategy, nil
12
12
  end
13
13
 
14
14
  def generate_random_keys amount
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexing::Bundle do
3
+ describe Internals::Indexing::Bundle::Memory do
4
4
 
5
5
  before(:each) do
6
6
  @internal_index = stub :index, :name => :some_index
@@ -10,12 +10,12 @@ describe Indexing::Bundle do
10
10
  @partial = stub :partial
11
11
  @weights = stub :weights
12
12
  @similarity = stub :similarity
13
- @index = Indexing::Bundle.new :some_name, @configuration, @similarity, @partial, @weights
13
+ @index = described_class.new :some_name, @configuration, @similarity, @partial, @weights
14
14
  end
15
15
 
16
16
  describe 'identifier' do
17
17
  it 'should return a specific identifier' do
18
- @index.identifier.should == 'some_index some_category (some_name)'
18
+ @index.identifier.should == 'some_index:some_category:some_name'
19
19
  end
20
20
  end
21
21
 
@@ -1,12 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Index::Bundle do
3
+ describe Internals::Indexing::Bundle::SuperBase do
4
4
 
5
5
  before(:each) do
6
6
  @configuration = stub :configuration, :identifier => 'some_identifier'
7
- Index::Files.stub! :new
7
+ Internals::Index::Files.stub! :new
8
8
  @similarity = Similarity::Phonetic.new 3
9
- @bundle = Index::Bundle.new :some_name, @configuration, @similarity
9
+ @bundle = described_class.new :some_name, @configuration, @similarity
10
+ end
11
+
12
+ describe 'identifier' do
13
+ it 'is correct' do
14
+ @bundle.identifier.should == 'some_identifier:some_name'
15
+ end
10
16
  end
11
17
 
12
18
  describe 'similar' do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexing::Category do
3
+ describe Internals::Indexing::Category do
4
4
 
5
5
  before(:each) do
6
6
  @index = stub :index, :name => :some_index
7
7
  @source = stub :some_given_source, :key_format => nil
8
- @category = Indexing::Category.new :some_category, @index, :source => @source
8
+ @category = described_class.new :some_category, @index, :source => @source
9
9
  end
10
10
  context "unit specs" do
11
11
  before(:each) do
@@ -107,7 +107,7 @@ describe Indexing::Category do
107
107
  describe "source" do
108
108
  context "without source" do
109
109
  it "raises" do
110
- lambda { Indexing::Category.new :some_name, @index }.should raise_error(Indexers::NoSourceSpecifiedException)
110
+ lambda { described_class.new :some_name, @index }.should raise_error(Indexers::NoSourceSpecifiedException)
111
111
  end
112
112
  end
113
113
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexing::Index do
3
+ describe Internals::Indexing::Index do
4
4
 
5
5
  context "with categories" do
6
6
  before(:each) do
@@ -8,7 +8,7 @@ describe Indexing::Index do
8
8
 
9
9
  @categories = stub :categories
10
10
 
11
- @index = Indexing::Index.new :some_name, @source
11
+ @index = described_class.new :some_name, @source
12
12
  @index.define_category :some_category_name1
13
13
  @index.define_category :some_category_name2
14
14
 
@@ -25,7 +25,7 @@ describe Indexing::Index do
25
25
 
26
26
  context "no categories" do
27
27
  it "works" do
28
- Indexing::Index.new :some_name, @source
28
+ described_class.new :some_name, @source
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Indexing::Indexes do
4
+
5
+ before(:each) do
6
+ @indexes = Indexing::Indexes.new
7
+ end
8
+
9
+ describe 'indexes' do
10
+ it 'exists' do
11
+ lambda { @indexes.indexes }.should_not raise_error
12
+ end
13
+ it 'is empty by default' do
14
+ @indexes.indexes.should be_empty
15
+ end
16
+ end
17
+
18
+ describe 'clear' do
19
+ it 'clears the indexes' do
20
+ @indexes.register :some_index
21
+
22
+ @indexes.clear
23
+
24
+ @indexes.indexes.should == []
25
+ end
26
+ end
27
+
28
+ describe 'register' do
29
+ it 'adds the given index to the indexes' do
30
+ @indexes.register :some_index
31
+
32
+ @indexes.indexes.should == [:some_index]
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Results::Base do
4
+
5
+ describe "from" do
6
+ before(:each) do
7
+ @results = stub :results
8
+ described_class.stub! :new => @results
9
+
10
+ @results.stub! :prepare!
11
+ end
12
+ it "should generate a result" do
13
+ described_class.from(0, @allocations).should == @results
14
+ end
15
+ end
16
+
17
+ describe "ids" do
18
+ before(:each) do
19
+ @allocations = stub :allocations
20
+ @results = described_class.new :unimportant, @allocations
21
+ end
22
+ it "delegates" do
23
+ @allocations.should_receive(:ids).once.with :anything
24
+
25
+ @results.ids :anything
26
+ end
27
+ end
28
+
29
+ describe "random_ids" do
30
+ before(:each) do
31
+ @allocations = stub :allocations
32
+ @results = described_class.new :unimportant, @allocations
33
+ end
34
+ it "delegates" do
35
+ @allocations.should_receive(:random_ids).once.with :anything
36
+
37
+ @results.random_ids :anything
38
+ end
39
+ end
40
+
41
+ describe 'to_log' do
42
+ before(:each) do
43
+ time = stub :time, :to_s => '0-08-16 10:07:33'
44
+ Time.stub! :now => time
45
+ end
46
+ context 'without results' do
47
+ before(:each) do
48
+ @results = described_class.new
49
+ end
50
+ it 'should output a default log' do
51
+ @results.to_log('some_query').should == '|0-08-16 10:07:33|0.000000|some_query | 0| 0| 0|'
52
+ end
53
+ end
54
+ context 'with results' do
55
+ before(:each) do
56
+ @allocations = stub :allocations,
57
+ :process! => nil, :size => 12
58
+
59
+ @results = described_class.new 1234, @allocations
60
+ @results.stub! :duration => 0.1234567890,
61
+ :total => 12345678
62
+ end
63
+ it 'should output a specific log' do
64
+ @results.to_log('some_query').should == '|0-08-16 10:07:33|0.123457|some_query |12345678|1234|12|'
65
+ end
66
+ end
67
+ end
68
+
69
+ describe 'to_json' do
70
+ before(:each) do
71
+ @results = described_class.new
72
+ end
73
+ it 'should do it correctly' do
74
+ @results.stub! :serialize => :serialized
75
+
76
+ @results.to_json.should == '"serialized"'
77
+ end
78
+ end
79
+
80
+ describe 'serialize' do
81
+ before(:each) do
82
+ @allocations = stub :allocations, :process! => nil, :to_result => :allocations, :total => :some_total
83
+
84
+ @results = described_class.new :some_offset, @allocations
85
+ @results.duration = :some_duration
86
+ end
87
+ it 'should do it correctly' do
88
+ @results.prepare!
89
+
90
+ @results.serialize.should == { :allocations => :allocations, :offset => :some_offset, :duration => :some_duration, :total => :some_total }
91
+ end
92
+ end
93
+
94
+ describe "accessors" do
95
+ before(:each) do
96
+ @results = described_class.new :anything
97
+ @some_stub = stub(:some)
98
+ end
99
+ it "should have accessors for duration" do
100
+ @results.duration = @some_stub
101
+ @results.duration.should == @some_stub
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Results::Full do
4
+
5
+ describe "class accessors" do
6
+ it "should have accessors for max_results" do
7
+ max_results = stub :max_results
8
+ old_results = described_class.max_results
9
+ described_class.max_results = max_results
10
+
11
+ described_class.max_results.should == max_results
12
+
13
+ described_class.max_results = old_results
14
+ end
15
+ end
16
+
17
+ describe 'initialize' do
18
+ context 'without allocations' do
19
+ it 'should not fail' do
20
+ lambda {
21
+ described_class.new
22
+ }.should_not raise_error
23
+ end
24
+ it 'should set the allocations to allocations that are empty' do
25
+ described_class.new.instance_variable_get(:@allocations).should be_empty
26
+ end
27
+ end
28
+ context 'with allocations' do
29
+ it 'should not fail' do
30
+ lambda {
31
+ described_class.new :some_allocations
32
+ }.should_not raise_error
33
+ end
34
+ it 'should set the allocations to an empty array' do
35
+ described_class.new(:unimportant, :some_allocations).instance_variable_get(:@allocations).should == :some_allocations
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'duration' do
41
+ before(:each) do
42
+ @results = described_class.new
43
+ end
44
+ it 'should return the set duration' do
45
+ @results.duration = :some_duration
46
+
47
+ @results.duration.should == :some_duration
48
+ end
49
+ it 'should return 0 as a default' do
50
+ @results.duration.should == 0
51
+ end
52
+ end
53
+
54
+ describe 'total' do
55
+ it 'should delegate to allocations.total' do
56
+ allocations = stub :allocations
57
+ results = described_class.new nil, allocations
58
+
59
+ allocations.should_receive(:total).once
60
+
61
+ results.total
62
+ end
63
+ end
64
+
65
+ describe 'prepare!' do
66
+ before(:each) do
67
+ @results = described_class.new
68
+ @allocations = stub :allocations
69
+ @results.stub! :allocations => @allocations
70
+ end
71
+ it 'should process' do
72
+ @allocations.should_receive(:process!).once.with(20, 0).ordered
73
+
74
+ @results.prepare!
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Internals::Results::Live do
4
+
5
+ it "is the right subclass" do
6
+ described_class.should < Internals::Results::Base
7
+ end
8
+
9
+ it "logs correctly" do
10
+ Time.stub! :now => Time.parse('2010-10-25 01:25:07')
11
+
12
+ described_class.new.to_log('some query').should == '.|2010-10-25 01:25:07|0.000000|some query | 0| 0| 0|'
13
+ end
14
+
15
+ describe "class accessors" do
16
+ it "should have accessors for max_results" do
17
+ max_results = stub :max_results
18
+ old_results = described_class.max_results
19
+ described_class.max_results = max_results
20
+
21
+ described_class.max_results.should == max_results
22
+
23
+ described_class.max_results = old_results
24
+ end
25
+ end
26
+
27
+ describe 'initialize' do
28
+ context 'without allocations' do
29
+ it 'should not fail' do
30
+ lambda {
31
+ described_class.new
32
+ }.should_not raise_error
33
+ end
34
+ it 'should set the allocations to allocations that are empty' do
35
+ described_class.new.instance_variable_get(:@allocations).should be_empty
36
+ end
37
+ end
38
+ context 'with allocations' do
39
+ it 'should not fail' do
40
+ lambda {
41
+ described_class.new :some_allocations
42
+ }.should_not raise_error
43
+ end
44
+ it 'should set the allocations to an empty array' do
45
+ described_class.new(:unimportant, :some_allocations).instance_variable_get(:@allocations).should == :some_allocations
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'duration' do
51
+ before(:each) do
52
+ @results = described_class.new
53
+ end
54
+ it 'should return the set duration' do
55
+ @results.duration = :some_duration
56
+
57
+ @results.duration.should == :some_duration
58
+ end
59
+ it 'should return 0 as a default' do
60
+ @results.duration.should == 0
61
+ end
62
+ end
63
+
64
+ describe 'total' do
65
+ it 'should delegate to allocations.total' do
66
+ allocations = stub :allocations
67
+ results = described_class.new nil, allocations
68
+
69
+ allocations.should_receive(:total).once
70
+
71
+ results.total
72
+ end
73
+ end
74
+
75
+ describe 'prepare!' do
76
+ before(:each) do
77
+ @results = described_class.new
78
+ @allocations = stub :allocations
79
+ @results.stub! :allocations => @allocations
80
+ end
81
+ it 'should generate truncate the ids fully' do
82
+ @allocations.should_receive(:process!).once.with(0, 0).ordered
83
+
84
+ @results.prepare!
85
+ end
86
+ end
87
+
88
+ end
@@ -2,10 +2,10 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Tokenizers::Base do
5
+ describe Internals::Tokenizers::Base do
6
6
 
7
7
  context 'with special instance' do
8
- let (:tokenizer) { Tokenizers::Base.new reject_token_if: lambda { |token| token.to_s.length < 2 || token == :hello } }
8
+ let (:tokenizer) { described_class.new reject_token_if: lambda { |token| token.to_s.length < 2 || token == :hello } }
9
9
  it 'rejects tokens with length < 2' do
10
10
  tokenizer.reject([:'', :a, :ab, :abc]).should == [:ab, :abc]
11
11
  end
@@ -15,7 +15,7 @@ describe Tokenizers::Base do
15
15
  end
16
16
 
17
17
  context 'with normal instance' do
18
- let(:tokenizer) { Tokenizers::Base.new }
18
+ let(:tokenizer) { described_class.new }
19
19
 
20
20
  describe 'reject_token_if' do
21
21
  it 'rejects empty tokens by default' do
@@ -2,30 +2,30 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Tokenizers::Index do
5
+ describe Internals::Tokenizers::Index do
6
6
 
7
- let(:tokenizer) { Tokenizers::Index.new }
7
+ let(:tokenizer) { described_class.new }
8
8
 
9
9
  describe "default*" do
10
10
  before(:all) do
11
- @old = Tokenizers::Index.default
11
+ @old = described_class.default
12
12
  end
13
13
  after(:all) do
14
- Tokenizers::Index.default = @old
14
+ described_class.default = @old
15
15
  end
16
16
  it "has a reader" do
17
- lambda { Tokenizers::Index.default }.should_not raise_error
17
+ lambda { described_class.default }.should_not raise_error
18
18
  end
19
19
  it "returns by default a new Index" do
20
- Tokenizers::Index.default.should be_kind_of(Tokenizers::Index)
20
+ described_class.default.should be_kind_of(described_class)
21
21
  end
22
22
  it "has a writer" do
23
- lambda { Tokenizers::Index.default = :bla }.should_not raise_error
23
+ lambda { described_class.default = :bla }.should_not raise_error
24
24
  end
25
25
  it "returns what has been written, if something has been written" do
26
- Tokenizers::Index.default = :some_default
26
+ described_class.default = :some_default
27
27
 
28
- Tokenizers::Index.default.should == :some_default
28
+ described_class.default.should == :some_default
29
29
  end
30
30
  end
31
31
 
@@ -1,30 +1,30 @@
1
1
  # coding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Tokenizers::Query do
4
+ describe Internals::Tokenizers::Query do
5
5
 
6
- let(:tokenizer) { Tokenizers::Query.new }
6
+ let(:tokenizer) { described_class.new }
7
7
 
8
8
  describe "default*" do
9
9
  before(:all) do
10
- @old = Tokenizers::Query.default
10
+ @old = described_class.default
11
11
  end
12
12
  after(:all) do
13
- Tokenizers::Query.default = @old
13
+ described_class.default = @old
14
14
  end
15
15
  it "has a reader" do
16
- lambda { Tokenizers::Query.default }.should_not raise_error
16
+ lambda { described_class.default }.should_not raise_error
17
17
  end
18
18
  it "returns by default a new Index" do
19
- Tokenizers::Query.default.should be_kind_of(Tokenizers::Query)
19
+ described_class.default.should be_kind_of(described_class)
20
20
  end
21
21
  it "has a writer" do
22
- lambda { Tokenizers::Query.default = :bla }.should_not raise_error
22
+ lambda { described_class.default = :bla }.should_not raise_error
23
23
  end
24
24
  it "returns what has been written, if something has been written" do
25
- Tokenizers::Query.default = :some_default
25
+ described_class.default = :some_default
26
26
 
27
- Tokenizers::Query.default.should == :some_default
27
+ described_class.default.should == :some_default
28
28
  end
29
29
  end
30
30
 
@@ -33,7 +33,7 @@ describe Tokenizers::Query do
33
33
  tokenizer.maximum_tokens.should == 5
34
34
  end
35
35
  it "should be settable" do
36
- Tokenizers::Query.new(maximum_tokens: 3).maximum_tokens.should == 3
36
+ described_class.new(maximum_tokens: 3).maximum_tokens.should == 3
37
37
  end
38
38
  end
39
39
 
@@ -125,7 +125,7 @@ describe Tokenizers::Query do
125
125
  describe "token_for" do
126
126
  it "should get a preprocessed token" do
127
127
  text = stub(:text)
128
- Query::Token.should_receive(:processed).with text
128
+ Internals::Query::Token.should_receive(:processed).with text
129
129
 
130
130
  tokenizer.token_for text
131
131
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Query::Allocation do
3
+ describe Internals::Query::Allocation do
4
4
 
5
5
  before(:each) do
6
6
  @combinations = stub :combinations
7
- @allocation = Query::Allocation.new @combinations, :some_result_identifier
7
+ @allocation = described_class.new @combinations, :some_result_identifier
8
8
  end
9
9
 
10
10
  describe "eql?" do
@@ -130,7 +130,7 @@ describe Query::Allocation do
130
130
  describe 'to_result' do
131
131
  context 'with few combinations' do
132
132
  before(:each) do
133
- @allocation = Query::Allocation.new stub(:combinations, :ids => [1,2,3], :to_result => [:some_result]), :some_result_identifier
133
+ @allocation = described_class.new stub(:combinations, :ids => [1,2,3], :to_result => [:some_result]), :some_result_identifier
134
134
  @allocation.instance_variable_set :@score, :some_score
135
135
  end
136
136
  context 'with ids' do
@@ -144,7 +144,7 @@ describe Query::Allocation do
144
144
  context 'with results' do
145
145
  before(:each) do
146
146
  combinations = stub :combinations, :ids => [1,2,3], :to_result => [:some_result1, :some_result2]
147
- @allocation = Query::Allocation.new combinations, :some_result_identifier
147
+ @allocation = described_class.new combinations, :some_result_identifier
148
148
  @allocation.instance_variable_set :@score, :some_score
149
149
  end
150
150
  context 'with ids' do
@@ -157,7 +157,7 @@ describe Query::Allocation do
157
157
  end
158
158
  context 'without results' do
159
159
  before(:each) do
160
- @allocation = Query::Allocation.new stub(:combinations, :ids => [], :to_result => []), :some_result_identifier
160
+ @allocation = described_class.new stub(:combinations, :ids => [], :to_result => []), :some_result_identifier
161
161
  @allocation.instance_variable_set :@score, :some_score
162
162
  end
163
163
  it 'should return nil' do
@@ -170,7 +170,7 @@ describe Query::Allocation do
170
170
 
171
171
  describe 'to_json' do
172
172
  before(:each) do
173
- @allocation = Query::Allocation.new stub(:combination, :ids => [1,2,3,4,5,6,7], :to_result => [:some_result1, :some_result2]), :some_result_identifier
173
+ @allocation = described_class.new stub(:combination, :ids => [1,2,3,4,5,6,7], :to_result => [:some_result1, :some_result2]), :some_result_identifier
174
174
  @allocation.instance_variable_set :@score, :some_score
175
175
  end
176
176
  it 'should output the correct json string' do
@@ -190,9 +190,9 @@ describe Query::Allocation do
190
190
 
191
191
  describe "<=>" do
192
192
  it "should sort higher first" do
193
- first = Query::Allocation.new [], :some_result_identifier
193
+ first = described_class.new [], :some_result_identifier
194
194
  first.instance_variable_set :@score, 20
195
- second = Query::Allocation.new [], :some_result_identifier
195
+ second = described_class.new [], :some_result_identifier
196
196
  second.instance_variable_set :@score, 10
197
197
 
198
198
  first.<=>(second).should == -1
@@ -201,11 +201,11 @@ describe Query::Allocation do
201
201
 
202
202
  describe "sort!" do
203
203
  it "should sort correctly" do
204
- first = Query::Allocation.new :whatever, :some_result_identifier
204
+ first = described_class.new :whatever, :some_result_identifier
205
205
  first.instance_variable_set :@score, 20
206
- second = Query::Allocation.new :whatever, :some_result_identifier
206
+ second = described_class.new :whatever, :some_result_identifier
207
207
  second.instance_variable_set :@score, 10
208
- third = Query::Allocation.new :whatever, :some_result_identifier
208
+ third = described_class.new :whatever, :some_result_identifier
209
209
  third.instance_variable_set :@score, 5
210
210
 
211
211
  allocations = [second, third, first]
@@ -222,7 +222,7 @@ describe Query::Allocation do
222
222
  @allocation.stub! :calculate_ids => @ids
223
223
  end
224
224
  it 'should calculate_ids' do
225
- @allocation.should_receive(:calculate_ids).once.with.and_return @ids
225
+ @allocation.should_receive(:calculate_ids).once.with(@amount, @offset).and_return @ids
226
226
 
227
227
  @allocation.process! @amount, @offset
228
228
  end