picky 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/{lib → aux}/picky/cli.rb +50 -38
  2. data/bin/picky +1 -1
  3. data/lib/picky/application.rb +5 -2
  4. data/lib/picky/index/base.rb +88 -25
  5. data/lib/picky/index/memory.rb +8 -8
  6. data/lib/picky/index/redis.rb +8 -8
  7. data/lib/picky/index_bundle.rb +2 -2
  8. data/lib/picky/indexing/indexes.rb +6 -6
  9. data/lib/picky/internals/calculations/location.rb +54 -42
  10. data/lib/picky/internals/index/backend.rb +21 -21
  11. data/lib/picky/internals/index/file/text.rb +11 -11
  12. data/lib/picky/internals/index/files.rb +6 -6
  13. data/lib/picky/internals/index/redis.rb +14 -14
  14. data/lib/picky/internals/indexed/bundle/base.rb +2 -2
  15. data/lib/picky/internals/indexed/bundle/redis.rb +3 -3
  16. data/lib/picky/internals/indexed/category.rb +8 -9
  17. data/lib/picky/internals/indexed/wrappers/bundle/calculation.rb +25 -23
  18. data/lib/picky/internals/indexed/wrappers/bundle/location.rb +36 -34
  19. data/lib/picky/internals/indexed/wrappers/bundle/wrapper.rb +35 -33
  20. data/lib/picky/internals/indexed/wrappers/category/location.rb +27 -0
  21. data/lib/picky/internals/indexers/base.rb +28 -0
  22. data/lib/picky/internals/indexers/parallel.rb +64 -0
  23. data/lib/picky/internals/indexers/serial.rb +20 -29
  24. data/lib/picky/internals/indexing/bundle/base.rb +2 -2
  25. data/lib/picky/internals/indexing/bundle/super_base.rb +3 -3
  26. data/lib/picky/internals/indexing/category.rb +30 -27
  27. data/lib/picky/internals/indexing/index.rb +82 -27
  28. data/lib/picky/internals/indexing/wrappers/category/location.rb +27 -0
  29. data/lib/picky/internals/query/indexes.rb +1 -1
  30. data/lib/picky/internals/query/qualifiers.rb +7 -6
  31. data/lib/picky/internals/query/weights.rb +6 -0
  32. data/lib/picky/internals/shared/category.rb +52 -0
  33. data/lib/picky/internals/tokenizers/base.rb +1 -1
  34. data/lib/picky/internals/tokenizers/location.rb +54 -0
  35. data/lib/picky/loader.rb +16 -3
  36. data/lib/picky/no_source_specified_exception.rb +3 -0
  37. data/lib/picky/search.rb +44 -5
  38. data/lib/picky/sources/base.rb +2 -2
  39. data/lib/picky/sources/couch.rb +1 -1
  40. data/lib/picky/sources/csv.rb +1 -1
  41. data/lib/picky/sources/db.rb +9 -9
  42. data/lib/picky/sources/delicious.rb +1 -1
  43. data/lib/picky/sources/wrappers/base.rb +12 -13
  44. data/lib/picky/sources/wrappers/location.rb +24 -54
  45. data/lib/tasks/search.rake +4 -5
  46. data/lib/tasks/todo.rake +1 -1
  47. data/spec/{lib → aux/picky}/cli_spec.rb +13 -8
  48. data/spec/lib/application_spec.rb +21 -16
  49. data/spec/lib/index/base_spec.rb +74 -27
  50. data/spec/lib/index/redis_spec.rb +1 -1
  51. data/spec/lib/index_bundle_spec.rb +1 -1
  52. data/spec/lib/indexing/indexes_spec.rb +5 -5
  53. data/spec/lib/internals/calculations/location_spec.rb +14 -3
  54. data/spec/lib/internals/index/files_spec.rb +2 -3
  55. data/spec/lib/internals/index/redis_spec.rb +122 -49
  56. data/spec/lib/internals/indexed/bundle/memory_spec.rb +4 -6
  57. data/spec/lib/internals/indexed/bundle/redis_spec.rb +2 -3
  58. data/spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb +3 -3
  59. data/spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb +3 -3
  60. data/spec/lib/internals/indexers/parallel_spec.rb +36 -0
  61. data/spec/lib/internals/indexers/serial_spec.rb +6 -14
  62. data/spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb +2 -3
  63. data/spec/lib/internals/indexing/bundle/memory_spec.rb +5 -6
  64. data/spec/lib/internals/indexing/bundle/redis_spec.rb +5 -6
  65. data/spec/lib/internals/indexing/category_spec.rb +21 -6
  66. data/spec/lib/internals/indexing/index_spec.rb +43 -7
  67. data/spec/lib/query/indexes_spec.rb +1 -1
  68. data/spec/lib/search_spec.rb +51 -2
  69. data/spec/lib/sources/couch_spec.rb +6 -6
  70. data/spec/lib/sources/csv_spec.rb +4 -4
  71. data/spec/lib/sources/db_spec.rb +13 -14
  72. data/spec/lib/sources/delicious_spec.rb +3 -3
  73. data/spec/lib/sources/wrappers/base_spec.rb +9 -10
  74. data/spec/lib/sources/wrappers/location_spec.rb +11 -23
  75. metadata +14 -15
  76. data/lib/picky/auxiliary/terminal.rb +0 -219
  77. data/lib/picky/internals/configuration/index.rb +0 -67
  78. data/lib/picky/internals/indexers/no_source_specified_error.rb +0 -7
  79. data/lib/picky/internals/indexing/categories.rb +0 -46
  80. data/spec/lib/auxiliary/terminal_spec.rb +0 -150
  81. data/spec/lib/internals/configuration/index_spec.rb +0 -80
  82. data/spec/lib/internals/indexing/categories_spec.rb +0 -49
@@ -1,67 +0,0 @@
1
- module Configuration # :nodoc:all
2
-
3
- # Holds the configuration for a
4
- # index/category combination.
5
- #
6
- class Index
7
-
8
- attr_reader :index, :category
9
-
10
- def initialize index, category
11
- @index = index
12
- @category = category
13
- end
14
-
15
- def index_name
16
- @index_name ||= index.name
17
- end
18
- def category_name
19
- @category_name ||= category.name
20
- end
21
-
22
- #
23
- #
24
- def index_path bundle_name, name
25
- "#{index_directory}/#{category_name}_#{bundle_name}_#{name}"
26
- end
27
-
28
- # Was: search_index_file_name
29
- #
30
- def prepared_index_path
31
- @prepared_index_path ||= "#{index_directory}/prepared_#{category_name}_index"
32
- end
33
- def prepared_index_file &block
34
- @prepared_index_file ||= Internals::Index::File::Text.new prepared_index_path
35
- @prepared_index_file.open_for_indexing &block
36
- end
37
-
38
- # Identifier for internal use.
39
- #
40
- def identifier
41
- @identifier ||= "#{index_name}:#{category_name}"
42
- end
43
-
44
- def to_s
45
- "#{index_name} #{category_name}"
46
- end
47
-
48
- def self.index_root
49
- @index_root ||= "#{PICKY_ROOT}/index"
50
- end
51
- def index_root
52
- self.class.index_root
53
- end
54
- # Was: cache_directory
55
- #
56
- def index_directory
57
- @index_directory ||= "#{index_root}/#{PICKY_ENVIRONMENT}/#{index_name}"
58
- end
59
- # Was: prepare_cache_directory
60
- #
61
- def prepare_index_directory
62
- FileUtils.mkdir_p index_directory
63
- end
64
-
65
- end
66
-
67
- end
@@ -1,7 +0,0 @@
1
- module Indexers # :nodoc:all
2
-
3
- # Raised if no source is available on a category.
4
- #
5
- class NoSourceSpecifiedException < StandardError; end
6
-
7
- end
@@ -1,46 +0,0 @@
1
- module Internals
2
-
3
- module Indexing
4
-
5
- class Categories
6
-
7
- attr_reader :categories
8
-
9
- each_delegate :index,
10
- :cache,
11
- :generate_caches,
12
- :backup_caches,
13
- :restore_caches,
14
- :check_caches,
15
- :clear_caches,
16
- :create_directory_structure,
17
- :to => :categories
18
-
19
- def initialize
20
- @categories = []
21
- end
22
-
23
- def to_s
24
- categories.indented_to_s
25
- end
26
-
27
- def << category
28
- categories << category
29
- end
30
-
31
- def find category_name
32
- category_name = category_name.to_sym
33
-
34
- categories.each do |category|
35
- next unless category.name == category_name
36
- return category
37
- end
38
-
39
- raise %Q{Index category "#{category_name}" not found. Possible categories: "#{categories.map(&:name).join('", "')}".}
40
- end
41
-
42
- end
43
-
44
- end
45
-
46
- end
@@ -1,150 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- # We need to load the Statistics file explicitly as the Statistics
6
- # are not loaded with the Loader (not needed in the server, only for script runs).
7
- #
8
- require File.expand_path '../../../../lib/picky/auxiliary/terminal', __FILE__
9
-
10
- describe Terminal do
11
-
12
- let(:terminal) { described_class.new('/some/url') }
13
-
14
- describe 'backspace' do
15
- it 'works correctly' do
16
- terminal.should_receive(:chop_text).once.ordered.with()
17
- terminal.should_receive(:print).once.ordered.with "\e[1D \e[1D"
18
- terminal.should_receive(:flush).once.ordered.with()
19
-
20
- terminal.backspace
21
- end
22
- end
23
-
24
- describe 'write_results' do
25
- it 'works correctly' do
26
- terminal.should_receive(:move_to).once.ordered.with 0
27
- terminal.should_receive(:write).once.ordered.with " 0"
28
- terminal.should_receive(:move_to).once.ordered.with 10
29
-
30
- terminal.write_results nil
31
- end
32
- it 'works correctly' do
33
- terminal.should_receive(:move_to).once.ordered.with 0
34
- terminal.should_receive(:write).once.ordered.with "123456789"
35
- terminal.should_receive(:move_to).once.ordered.with 10
36
-
37
- terminal.write_results stub(:results, :total => 123456789)
38
- end
39
- end
40
-
41
- describe 'search' do
42
- before(:each) do
43
- @client = stub :client
44
- terminal.stub! :client => @client
45
-
46
- terminal.add_text 'hello'
47
- end
48
- it 'searches full correctly' do
49
- @client.should_receive(:search).once.with 'hello', :ids => 20
50
-
51
- terminal.search true
52
- end
53
- it 'searches full correctly' do
54
- terminal = described_class.new('/some/url', 33)
55
- terminal.stub! :client => @client
56
-
57
- @client.should_receive(:search).once.with '', :ids => 33
58
-
59
- terminal.search true
60
- end
61
- it 'searches live correctly' do
62
- @client.should_receive(:search).once.with 'hello', :ids => 0
63
-
64
- terminal.search
65
- end
66
- it 'searches live correctly' do
67
- @client.should_receive(:search).once.with 'hello', :ids => 0
68
-
69
- terminal.search false
70
- end
71
- end
72
-
73
- describe 'clear_ids' do
74
- it 'moves to the ids, then clears all' do
75
- terminal.should_receive(:move_to_ids).once.with()
76
- terminal.should_receive(:write).once.with " "*200
77
-
78
- terminal.clear_ids
79
- end
80
- end
81
-
82
- describe 'write_ids' do
83
- it 'writes the result\'s ids' do
84
- terminal.should_receive(:move_to_ids).once.with()
85
- terminal.should_receive(:write).once.with "=> []"
86
-
87
- terminal.write_ids stub(:results, :total => nil)
88
- end
89
- it 'writes the result\'s ids' do
90
- terminal.should_receive(:move_to_ids).once.with()
91
- terminal.should_receive(:write).once.with "=> [1, 2, 3]"
92
-
93
- terminal.write_ids stub(:results, :total => 3, :ids => [1, 2, 3])
94
- end
95
- end
96
-
97
- describe 'move_to_ids' do
98
- it 'moves to a specific place' do
99
- terminal.should_receive(:move_to).once.with 12
100
-
101
- terminal.move_to_ids
102
- end
103
- it 'moves to a specific place' do
104
- terminal.add_text 'test'
105
-
106
- terminal.should_receive(:move_to).once.with 16
107
-
108
- terminal.move_to_ids
109
- end
110
- end
111
-
112
- describe 'left' do
113
- it 'moves by amount' do
114
- terminal.should_receive(:print).once.ordered.with "\e[13D"
115
- terminal.should_receive(:flush).once.ordered
116
-
117
- terminal.left 13
118
- end
119
- it 'default is 1' do
120
- terminal.should_receive(:print).once.ordered.with "\e[1D"
121
- terminal.should_receive(:flush).once.ordered
122
-
123
- terminal.left
124
- end
125
- end
126
-
127
- describe 'right' do
128
- it 'moves by amount' do
129
- terminal.should_receive(:print).once.ordered.with "\e[13C"
130
- terminal.should_receive(:flush).once.ordered
131
-
132
- terminal.right 13
133
- end
134
- it 'default is 1' do
135
- terminal.should_receive(:print).once.ordered.with "\e[1C"
136
- terminal.should_receive(:flush).once.ordered
137
-
138
- terminal.right
139
- end
140
- end
141
-
142
- describe 'flush' do
143
- it 'flushes STDOUT' do
144
- STDOUT.should_receive(:flush).once.with()
145
-
146
- terminal.flush
147
- end
148
- end
149
-
150
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Configuration::Index' do
4
-
5
- before(:each) do
6
- @index = stub :index, :name => :some_index
7
- @category = stub :category, :name => :some_category
8
- @config = Configuration::Index.new @index, @category
9
- end
10
-
11
- describe "index_name" do
12
- it "returns the right thing" do
13
- @config.index_name.should == :some_index
14
- end
15
- end
16
- describe "category_name" do
17
- it "returns the right thing" do
18
- @config.category_name.should == :some_category
19
- end
20
- end
21
-
22
- describe "index_path" do
23
- it "caches" do
24
- @config.index_path(:some_bundle, :some_name).should_not equal(@config.index_path(:some_bundle, :some_name))
25
- end
26
- it "returns the right thing" do
27
- @config.index_path(:some_bundle, :some_name).should == 'spec/test_directory/index/test/some_index/some_category_some_bundle_some_name'
28
- end
29
- end
30
-
31
- # describe "file_name" do
32
- # it "caches" do
33
- # @config.file_name.should equal(@config.file_name)
34
- # end
35
- # it "returns the right thing" do
36
- # @config.file_name.should == 'some_index_some_category'
37
- # end
38
- # end
39
-
40
- describe "identifier" do
41
- it "caches" do
42
- @config.identifier.should equal(@config.identifier)
43
- end
44
- it "returns the right thing" do
45
- @config.identifier.should == 'some_index:some_category'
46
- end
47
- end
48
- describe "index_root" do
49
- it "caches" do
50
- @config.index_root.should equal(@config.index_root)
51
- end
52
- it "returns the right thing" do
53
- @config.index_root.should == 'spec/test_directory/index'
54
- end
55
- end
56
- describe "index_directory" do
57
- it "caches" do
58
- @config.index_directory.should equal(@config.index_directory)
59
- end
60
- it "returns the right thing" do
61
- @config.index_directory.should == 'spec/test_directory/index/test/some_index'
62
- end
63
- end
64
- describe "prepared_index_path" do
65
- it "caches" do
66
- @config.prepared_index_path.should equal(@config.prepared_index_path)
67
- end
68
- it "returns the right thing" do
69
- @config.prepared_index_path.should == 'spec/test_directory/index/test/some_index/prepared_some_category_index'
70
- end
71
- end
72
- describe "prepare_index_directory" do
73
- it "calls the right thing" do
74
- FileUtils.should_receive(:mkdir_p).once.with 'spec/test_directory/index/test/some_index'
75
-
76
- @config.prepare_index_directory
77
- end
78
- end
79
-
80
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Internals::Indexing::Categories do
4
-
5
- let(:categories) { described_class.new }
6
-
7
- describe 'to_s' do
8
- context 'no categories' do
9
- it 'outputs the right thing' do
10
- categories.to_s.should == ""
11
- end
12
- end
13
- context 'with categories' do
14
- before(:each) do
15
- index = stub :index, :name => :some_name
16
- categories << Internals::Indexing::Category.new(:some_name, index, :source => stub(:source))
17
- end
18
- it 'outputs the right thing' do
19
- categories.to_s.should == " Category(some_name from some_name):\n Exact:\n Memory\n Partial:\n Memory\n"
20
- end
21
- end
22
- end
23
-
24
- describe 'find' do
25
- context 'no categories' do
26
- it 'raises on none existent category' do
27
- expect do
28
- categories.find :some_non_existent_name
29
- end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "".})
30
- end
31
- end
32
- context 'with categories' do
33
- before(:each) do
34
- index = stub :index, :name => :some_name
35
- @category = Internals::Indexing::Category.new(:some_name, index, :source => stub(:source))
36
- categories << @category
37
- end
38
- it 'returns it if found' do
39
- categories.find(:some_name).should == @category
40
- end
41
- it 'raises on none existent category' do
42
- expect do
43
- categories.find :some_non_existent_name
44
- end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_name".})
45
- end
46
- end
47
- end
48
-
49
- end