picky 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{lib → aux}/picky/cli.rb +50 -38
- data/bin/picky +1 -1
- data/lib/picky/application.rb +5 -2
- data/lib/picky/index/base.rb +88 -25
- data/lib/picky/index/memory.rb +8 -8
- data/lib/picky/index/redis.rb +8 -8
- data/lib/picky/index_bundle.rb +2 -2
- data/lib/picky/indexing/indexes.rb +6 -6
- data/lib/picky/internals/calculations/location.rb +54 -42
- data/lib/picky/internals/index/backend.rb +21 -21
- data/lib/picky/internals/index/file/text.rb +11 -11
- data/lib/picky/internals/index/files.rb +6 -6
- data/lib/picky/internals/index/redis.rb +14 -14
- data/lib/picky/internals/indexed/bundle/base.rb +2 -2
- data/lib/picky/internals/indexed/bundle/redis.rb +3 -3
- data/lib/picky/internals/indexed/category.rb +8 -9
- data/lib/picky/internals/indexed/wrappers/bundle/calculation.rb +25 -23
- data/lib/picky/internals/indexed/wrappers/bundle/location.rb +36 -34
- data/lib/picky/internals/indexed/wrappers/bundle/wrapper.rb +35 -33
- data/lib/picky/internals/indexed/wrappers/category/location.rb +27 -0
- data/lib/picky/internals/indexers/base.rb +28 -0
- data/lib/picky/internals/indexers/parallel.rb +64 -0
- data/lib/picky/internals/indexers/serial.rb +20 -29
- data/lib/picky/internals/indexing/bundle/base.rb +2 -2
- data/lib/picky/internals/indexing/bundle/super_base.rb +3 -3
- data/lib/picky/internals/indexing/category.rb +30 -27
- data/lib/picky/internals/indexing/index.rb +82 -27
- data/lib/picky/internals/indexing/wrappers/category/location.rb +27 -0
- data/lib/picky/internals/query/indexes.rb +1 -1
- data/lib/picky/internals/query/qualifiers.rb +7 -6
- data/lib/picky/internals/query/weights.rb +6 -0
- data/lib/picky/internals/shared/category.rb +52 -0
- data/lib/picky/internals/tokenizers/base.rb +1 -1
- data/lib/picky/internals/tokenizers/location.rb +54 -0
- data/lib/picky/loader.rb +16 -3
- data/lib/picky/no_source_specified_exception.rb +3 -0
- data/lib/picky/search.rb +44 -5
- data/lib/picky/sources/base.rb +2 -2
- data/lib/picky/sources/couch.rb +1 -1
- data/lib/picky/sources/csv.rb +1 -1
- data/lib/picky/sources/db.rb +9 -9
- data/lib/picky/sources/delicious.rb +1 -1
- data/lib/picky/sources/wrappers/base.rb +12 -13
- data/lib/picky/sources/wrappers/location.rb +24 -54
- data/lib/tasks/search.rake +4 -5
- data/lib/tasks/todo.rake +1 -1
- data/spec/{lib → aux/picky}/cli_spec.rb +13 -8
- data/spec/lib/application_spec.rb +21 -16
- data/spec/lib/index/base_spec.rb +74 -27
- data/spec/lib/index/redis_spec.rb +1 -1
- data/spec/lib/index_bundle_spec.rb +1 -1
- data/spec/lib/indexing/indexes_spec.rb +5 -5
- data/spec/lib/internals/calculations/location_spec.rb +14 -3
- data/spec/lib/internals/index/files_spec.rb +2 -3
- data/spec/lib/internals/index/redis_spec.rb +122 -49
- data/spec/lib/internals/indexed/bundle/memory_spec.rb +4 -6
- data/spec/lib/internals/indexed/bundle/redis_spec.rb +2 -3
- data/spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb +3 -3
- data/spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb +3 -3
- data/spec/lib/internals/indexers/parallel_spec.rb +36 -0
- data/spec/lib/internals/indexers/serial_spec.rb +6 -14
- data/spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb +2 -3
- data/spec/lib/internals/indexing/bundle/memory_spec.rb +5 -6
- data/spec/lib/internals/indexing/bundle/redis_spec.rb +5 -6
- data/spec/lib/internals/indexing/category_spec.rb +21 -6
- data/spec/lib/internals/indexing/index_spec.rb +43 -7
- data/spec/lib/query/indexes_spec.rb +1 -1
- data/spec/lib/search_spec.rb +51 -2
- data/spec/lib/sources/couch_spec.rb +6 -6
- data/spec/lib/sources/csv_spec.rb +4 -4
- data/spec/lib/sources/db_spec.rb +13 -14
- data/spec/lib/sources/delicious_spec.rb +3 -3
- data/spec/lib/sources/wrappers/base_spec.rb +9 -10
- data/spec/lib/sources/wrappers/location_spec.rb +11 -23
- metadata +14 -15
- data/lib/picky/auxiliary/terminal.rb +0 -219
- data/lib/picky/internals/configuration/index.rb +0 -67
- data/lib/picky/internals/indexers/no_source_specified_error.rb +0 -7
- data/lib/picky/internals/indexing/categories.rb +0 -46
- data/spec/lib/auxiliary/terminal_spec.rb +0 -150
- data/spec/lib/internals/configuration/index_spec.rb +0 -80
- data/spec/lib/internals/indexing/categories_spec.rb +0 -49
@@ -34,8 +34,8 @@ describe Sources::Couch do
|
|
34
34
|
|
35
35
|
describe "harvest" do
|
36
36
|
it "yields the right data" do
|
37
|
-
|
38
|
-
@source.harvest
|
37
|
+
category = stub :b, :from => :b
|
38
|
+
@source.harvest category do |id, token|
|
39
39
|
id.should eql('550e8400-e29b-41d4-a716-446655440000')
|
40
40
|
token.should eql('b data')
|
41
41
|
end.should have(1).item
|
@@ -60,8 +60,8 @@ describe Sources::Couch do
|
|
60
60
|
|
61
61
|
describe "harvest" do
|
62
62
|
it "yields the right data" do
|
63
|
-
|
64
|
-
@source.harvest
|
63
|
+
category = stub :b, :from => :b
|
64
|
+
@source.harvest category do |id, token|
|
65
65
|
id.should eql('123')
|
66
66
|
token.should eql('b data')
|
67
67
|
end.should have(1).item
|
@@ -94,8 +94,8 @@ describe Sources::Couch do
|
|
94
94
|
|
95
95
|
describe "harvest" do
|
96
96
|
it "yields the right data" do
|
97
|
-
|
98
|
-
@source.harvest
|
97
|
+
category = stub :b, :from => :b
|
98
|
+
@source.harvest category do |id, token|
|
99
99
|
id.should eql('7f')
|
100
100
|
token.should eql('b data')
|
101
101
|
end.should have(1).item
|
@@ -50,8 +50,8 @@ describe Sources::CSV do
|
|
50
50
|
end
|
51
51
|
describe "harvest" do
|
52
52
|
it "should yield the right data" do
|
53
|
-
|
54
|
-
@source.harvest
|
53
|
+
category = stub :b, :from => :b
|
54
|
+
@source.harvest category do |id, token|
|
55
55
|
[id, token].should == [' 7', 'b data']
|
56
56
|
end
|
57
57
|
end
|
@@ -70,8 +70,8 @@ describe Sources::CSV do
|
|
70
70
|
end
|
71
71
|
describe "harvest" do
|
72
72
|
it "should yield the right data" do
|
73
|
-
|
74
|
-
@source.harvest
|
73
|
+
category = stub :b, :from => :b
|
74
|
+
@source.harvest category do |id, token|
|
75
75
|
[id, token].should == [' 7', 'b data']
|
76
76
|
end
|
77
77
|
end
|
data/spec/lib/sources/db_spec.rb
CHANGED
@@ -24,8 +24,8 @@ describe Sources::DB do
|
|
24
24
|
|
25
25
|
describe "get_data" do
|
26
26
|
before(:each) do
|
27
|
-
@
|
28
|
-
@category = stub :category, :from => :some_category
|
27
|
+
@index = stub :index, :name => :some_index_name
|
28
|
+
@category = stub :category, :from => :some_category, :index => @index
|
29
29
|
end
|
30
30
|
context 'mysql' do
|
31
31
|
before(:each) do
|
@@ -36,20 +36,20 @@ describe Sources::DB do
|
|
36
36
|
|
37
37
|
@connection.should_receive(:execute).
|
38
38
|
once.
|
39
|
-
with('SELECT id, some_category FROM
|
39
|
+
with('SELECT id, some_category FROM picky_some_index_name_index st WHERE st.__picky_id > some_offset LIMIT 25000').
|
40
40
|
and_return []
|
41
41
|
|
42
|
-
@source.get_data @
|
42
|
+
@source.get_data @category, :some_offset
|
43
43
|
end
|
44
44
|
end
|
45
45
|
context 'with data' do
|
46
46
|
it 'yields to the caller' do
|
47
47
|
@connection.should_receive(:execute).
|
48
48
|
any_number_of_times.
|
49
|
-
with('SELECT id, some_category FROM
|
49
|
+
with('SELECT id, some_category FROM picky_some_index_name_index st WHERE st.__picky_id > some_offset LIMIT 25000').
|
50
50
|
and_return [[1, 'text']]
|
51
51
|
|
52
|
-
@source.get_data @
|
52
|
+
@source.get_data @category, :some_offset do |id, text|
|
53
53
|
id.should == 1
|
54
54
|
text.should == 'text'
|
55
55
|
end
|
@@ -100,8 +100,8 @@ describe Sources::DB do
|
|
100
100
|
|
101
101
|
describe 'harvest' do
|
102
102
|
before(:each) do
|
103
|
-
@
|
104
|
-
@category = stub :category, :name => :some_category
|
103
|
+
@index = stub :index, :name => :some_index
|
104
|
+
@category = stub :category, :name => :some_category, :index => @index
|
105
105
|
|
106
106
|
@source.should_receive(:get_data).any_number_of_times.and_return [[:some_id, 'some_text']].cycle
|
107
107
|
@source.stub! :count => 17
|
@@ -109,7 +109,7 @@ describe Sources::DB do
|
|
109
109
|
it 'calls connect_backend' do
|
110
110
|
@source.should_receive(:connect_backend).once.with()
|
111
111
|
|
112
|
-
@source.harvest @
|
112
|
+
@source.harvest @category do |id, text|
|
113
113
|
p [id, text]
|
114
114
|
end
|
115
115
|
end
|
@@ -118,19 +118,18 @@ describe Sources::DB do
|
|
118
118
|
describe "harvest_statement_with_offset" do
|
119
119
|
before(:each) do
|
120
120
|
@category = stub :category, :from => :some_category
|
121
|
-
@type = stub :type, :name => :some_type
|
122
121
|
end
|
123
122
|
it "should get a harvest statement and the chunksize to put the statement together" do
|
124
|
-
@source.should_receive(:harvest_statement).once.with(@
|
125
|
-
@source.harvest_statement_with_offset(@
|
123
|
+
@source.should_receive(:harvest_statement).once.with(@category).and_return 'some_example_statement'
|
124
|
+
@source.harvest_statement_with_offset(@category, :some_offset)
|
126
125
|
end
|
127
126
|
it "should add an AND if it already contains a WHERE statement" do
|
128
127
|
@source.should_receive(:harvest_statement).and_return 'WHERE'
|
129
|
-
@source.harvest_statement_with_offset(@
|
128
|
+
@source.harvest_statement_with_offset(@category, :some_offset).should == "WHERE AND st.__picky_id > some_offset LIMIT 25000"
|
130
129
|
end
|
131
130
|
it "should add a WHERE if it doesn't already contain one" do
|
132
131
|
@source.should_receive(:harvest_statement).and_return 'some_statement'
|
133
|
-
@source.harvest_statement_with_offset(@
|
132
|
+
@source.harvest_statement_with_offset(@category, :some_offset).should == "some_statement WHERE st.__picky_id > some_offset LIMIT 25000"
|
134
133
|
end
|
135
134
|
end
|
136
135
|
|
@@ -51,19 +51,19 @@ describe Sources::Delicious do
|
|
51
51
|
end
|
52
52
|
it "should yield the right data" do
|
53
53
|
category = stub :b, :from => :tags
|
54
|
-
@source.harvest
|
54
|
+
@source.harvest category do |id, token|
|
55
55
|
[id, token].should == [1, "barefoot running shoe"]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
it "should yield the right data" do
|
59
59
|
category = stub :b, :from => :title
|
60
|
-
@source.harvest
|
60
|
+
@source.harvest category do |id, token|
|
61
61
|
[id, token].should == [1, "VIBRAM - FiveFingers"]
|
62
62
|
end
|
63
63
|
end
|
64
64
|
it "should yield the right data" do
|
65
65
|
category = stub :b, :from => :url
|
66
|
-
@source.harvest
|
66
|
+
@source.harvest category do |id, token|
|
67
67
|
[id, token].should == [1, "http://www.vibramfivefingers.it/"]
|
68
68
|
end
|
69
69
|
end
|
@@ -3,36 +3,35 @@ require 'spec_helper'
|
|
3
3
|
describe Sources::Wrappers::Base do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@
|
7
|
-
@category = stub :category, :source => @backend
|
6
|
+
@source = stub :source
|
8
7
|
end
|
9
8
|
|
10
9
|
context "with backend" do
|
11
10
|
it "doesn't fail" do
|
12
|
-
lambda {
|
11
|
+
lambda { described_class.new(@source) }.should_not raise_error
|
13
12
|
end
|
14
13
|
before(:each) do
|
15
|
-
@wrapper
|
14
|
+
@wrapper = described_class.new @source
|
16
15
|
end
|
17
16
|
it "delegates harvest" do
|
18
|
-
@
|
17
|
+
@source.should_receive(:harvest).once.with :some_category
|
19
18
|
|
20
|
-
@wrapper.harvest :
|
19
|
+
@wrapper.harvest :some_category
|
21
20
|
end
|
22
21
|
it "delegates take_snapshot" do
|
23
|
-
@
|
22
|
+
@source.should_receive(:take_snapshot).once.with :some_index
|
24
23
|
|
25
|
-
@wrapper.take_snapshot :
|
24
|
+
@wrapper.take_snapshot :some_index
|
26
25
|
end
|
27
26
|
it "delegates connect_backend" do
|
28
|
-
@
|
27
|
+
@source.should_receive(:connect_backend).once.with # nothing
|
29
28
|
|
30
29
|
@wrapper.connect_backend
|
31
30
|
end
|
32
31
|
end
|
33
32
|
context "without backend" do
|
34
33
|
it "fails" do
|
35
|
-
lambda {
|
34
|
+
lambda { described_class.new }.should raise_error(ArgumentError)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -4,8 +4,8 @@ describe Sources::Wrappers::Location do
|
|
4
4
|
|
5
5
|
context "with backend" do
|
6
6
|
before(:each) do
|
7
|
-
@
|
8
|
-
@category = stub :category
|
7
|
+
@source = stub :source
|
8
|
+
@category = stub :category
|
9
9
|
end
|
10
10
|
context "without grid option" do
|
11
11
|
it "fails" do
|
@@ -14,47 +14,35 @@ describe Sources::Wrappers::Location do
|
|
14
14
|
end
|
15
15
|
context "with grid option" do
|
16
16
|
before(:each) do
|
17
|
-
@wrapper = described_class.new @
|
17
|
+
@wrapper = described_class.new @source, 10
|
18
18
|
end
|
19
19
|
it "uses a default of 1 on the precision" do
|
20
|
-
@wrapper.precision.should == 1
|
20
|
+
@wrapper.calculation.precision.should == 1
|
21
21
|
end
|
22
22
|
it "delegates harvest" do
|
23
23
|
@category.stub! :exact => {}
|
24
24
|
|
25
|
-
@
|
25
|
+
@source.should_receive(:harvest).once.with @category
|
26
26
|
|
27
|
-
@wrapper.harvest
|
27
|
+
@wrapper.harvest @category
|
28
28
|
end
|
29
29
|
it "delegates take_snapshot" do
|
30
|
-
@
|
30
|
+
@source.should_receive(:take_snapshot).once.with()
|
31
31
|
|
32
|
-
@wrapper.take_snapshot
|
32
|
+
@wrapper.take_snapshot
|
33
33
|
end
|
34
34
|
it "delegates connect_backend" do
|
35
|
-
@
|
35
|
+
@source.should_receive(:connect_backend).once.with()
|
36
36
|
|
37
37
|
@wrapper.connect_backend
|
38
38
|
end
|
39
39
|
end
|
40
40
|
context "with grid and precision option" do
|
41
41
|
before(:each) do
|
42
|
-
@wrapper = described_class.new @category,
|
42
|
+
@wrapper = described_class.new @category, 4, 2
|
43
43
|
end
|
44
44
|
it "uses the given precision" do
|
45
|
-
@wrapper.precision.should == 2
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "locations_for" do
|
49
|
-
it "returns the right array" do
|
50
|
-
@wrapper.locations_for(15).should == [13, 14, 15, 16, 17]
|
51
|
-
end
|
52
|
-
it "returns the right array" do
|
53
|
-
@wrapper.locations_for(2).should == [0, 1, 2, 3, 4]
|
54
|
-
end
|
55
|
-
it "returns the right array" do
|
56
|
-
@wrapper.locations_for(16).should == [14, 15, 16, 17, 18]
|
57
|
-
end
|
45
|
+
@wrapper.calculation.precision.should == 2
|
58
46
|
end
|
59
47
|
end
|
60
48
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.
|
5
|
+
version: 2.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-14 00:00:00 +10:00
|
14
14
|
default_executable: picky
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -33,15 +33,14 @@ extensions:
|
|
33
33
|
extra_rdoc_files: []
|
34
34
|
|
35
35
|
files:
|
36
|
+
- aux/picky/cli.rb
|
36
37
|
- lib/bundling.rb
|
37
38
|
- lib/constants.rb
|
38
39
|
- lib/deployment.rb
|
39
40
|
- lib/picky/aliases.rb
|
40
41
|
- lib/picky/analyzer.rb
|
41
42
|
- lib/picky/application.rb
|
42
|
-
- lib/picky/auxiliary/terminal.rb
|
43
43
|
- lib/picky/character_substituters/west_european.rb
|
44
|
-
- lib/picky/cli.rb
|
45
44
|
- lib/picky/cores.rb
|
46
45
|
- lib/picky/generators/aliases.rb
|
47
46
|
- lib/picky/index/base.rb
|
@@ -56,7 +55,6 @@ files:
|
|
56
55
|
- lib/picky/internals/adapters/rack/query.rb
|
57
56
|
- lib/picky/internals/adapters/rack.rb
|
58
57
|
- lib/picky/internals/calculations/location.rb
|
59
|
-
- lib/picky/internals/configuration/index.rb
|
60
58
|
- lib/picky/internals/ext/maybe_compile.rb
|
61
59
|
- lib/picky/internals/ext/ruby19/extconf.rb
|
62
60
|
- lib/picky/internals/extensions/array.rb
|
@@ -104,17 +102,19 @@ files:
|
|
104
102
|
- lib/picky/internals/indexed/wrappers/bundle/calculation.rb
|
105
103
|
- lib/picky/internals/indexed/wrappers/bundle/location.rb
|
106
104
|
- lib/picky/internals/indexed/wrappers/bundle/wrapper.rb
|
105
|
+
- lib/picky/internals/indexed/wrappers/category/location.rb
|
107
106
|
- lib/picky/internals/indexed/wrappers/exact_first.rb
|
108
|
-
- lib/picky/internals/indexers/
|
107
|
+
- lib/picky/internals/indexers/base.rb
|
108
|
+
- lib/picky/internals/indexers/parallel.rb
|
109
109
|
- lib/picky/internals/indexers/serial.rb
|
110
110
|
- lib/picky/internals/indexers/solr.rb
|
111
111
|
- lib/picky/internals/indexing/bundle/base.rb
|
112
112
|
- lib/picky/internals/indexing/bundle/memory.rb
|
113
113
|
- lib/picky/internals/indexing/bundle/redis.rb
|
114
114
|
- lib/picky/internals/indexing/bundle/super_base.rb
|
115
|
-
- lib/picky/internals/indexing/categories.rb
|
116
115
|
- lib/picky/internals/indexing/category.rb
|
117
116
|
- lib/picky/internals/indexing/index.rb
|
117
|
+
- lib/picky/internals/indexing/wrappers/category/location.rb
|
118
118
|
- lib/picky/internals/performant.rb
|
119
119
|
- lib/picky/internals/query/allocation.rb
|
120
120
|
- lib/picky/internals/query/allocations.rb
|
@@ -127,13 +127,16 @@ files:
|
|
127
127
|
- lib/picky/internals/query/token.rb
|
128
128
|
- lib/picky/internals/query/tokens.rb
|
129
129
|
- lib/picky/internals/query/weights.rb
|
130
|
+
- lib/picky/internals/shared/category.rb
|
130
131
|
- lib/picky/internals/solr/schema_generator.rb
|
131
132
|
- lib/picky/internals/tokenizers/base.rb
|
132
133
|
- lib/picky/internals/tokenizers/index.rb
|
134
|
+
- lib/picky/internals/tokenizers/location.rb
|
133
135
|
- lib/picky/internals/tokenizers/query.rb
|
134
136
|
- lib/picky/internals.rb
|
135
137
|
- lib/picky/loader.rb
|
136
138
|
- lib/picky/loggers/search.rb
|
139
|
+
- lib/picky/no_source_specified_exception.rb
|
137
140
|
- lib/picky/query/solr.rb
|
138
141
|
- lib/picky/query.rb
|
139
142
|
- lib/picky/rack/harakiri.rb
|
@@ -164,14 +167,13 @@ files:
|
|
164
167
|
- lib/tasks/todo.rake
|
165
168
|
- lib/tasks/try.rake
|
166
169
|
- lib/picky/internals/ext/ruby19/performant.c
|
170
|
+
- spec/aux/picky/cli_spec.rb
|
167
171
|
- spec/ext/performant_spec.rb
|
168
172
|
- spec/lib/aliases_spec.rb
|
169
173
|
- spec/lib/analyzer_spec.rb
|
170
174
|
- spec/lib/application_spec.rb
|
171
|
-
- spec/lib/auxiliary/terminal_spec.rb
|
172
175
|
- spec/lib/bundling_spec.rb
|
173
176
|
- spec/lib/character_substituters/west_european_spec.rb
|
174
|
-
- spec/lib/cli_spec.rb
|
175
177
|
- spec/lib/generators/aliases_spec.rb
|
176
178
|
- spec/lib/index/base_spec.rb
|
177
179
|
- spec/lib/index/redis_spec.rb
|
@@ -182,7 +184,6 @@ files:
|
|
182
184
|
- spec/lib/internals/adapters/rack/live_parameters_spec.rb
|
183
185
|
- spec/lib/internals/adapters/rack/query_spec.rb
|
184
186
|
- spec/lib/internals/calculations/location_spec.rb
|
185
|
-
- spec/lib/internals/configuration/index_spec.rb
|
186
187
|
- spec/lib/internals/cores_spec.rb
|
187
188
|
- spec/lib/internals/extensions/array_spec.rb
|
188
189
|
- spec/lib/internals/extensions/hash_spec.rb
|
@@ -221,12 +222,12 @@ files:
|
|
221
222
|
- spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb
|
222
223
|
- spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb
|
223
224
|
- spec/lib/internals/indexed/wrappers/exact_first_spec.rb
|
225
|
+
- spec/lib/internals/indexers/parallel_spec.rb
|
224
226
|
- spec/lib/internals/indexers/serial_spec.rb
|
225
227
|
- spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb
|
226
228
|
- spec/lib/internals/indexing/bundle/memory_spec.rb
|
227
229
|
- spec/lib/internals/indexing/bundle/redis_spec.rb
|
228
230
|
- spec/lib/internals/indexing/bundle/super_base_spec.rb
|
229
|
-
- spec/lib/internals/indexing/categories_spec.rb
|
230
231
|
- spec/lib/internals/indexing/category_spec.rb
|
231
232
|
- spec/lib/internals/indexing/index_spec.rb
|
232
233
|
- spec/lib/internals/indexing/indexes_spec.rb
|
@@ -290,14 +291,13 @@ signing_key:
|
|
290
291
|
specification_version: 3
|
291
292
|
summary: "Picky: Semantic Search Engine. Clever Interface. Good Tools."
|
292
293
|
test_files:
|
294
|
+
- spec/aux/picky/cli_spec.rb
|
293
295
|
- spec/ext/performant_spec.rb
|
294
296
|
- spec/lib/aliases_spec.rb
|
295
297
|
- spec/lib/analyzer_spec.rb
|
296
298
|
- spec/lib/application_spec.rb
|
297
|
-
- spec/lib/auxiliary/terminal_spec.rb
|
298
299
|
- spec/lib/bundling_spec.rb
|
299
300
|
- spec/lib/character_substituters/west_european_spec.rb
|
300
|
-
- spec/lib/cli_spec.rb
|
301
301
|
- spec/lib/generators/aliases_spec.rb
|
302
302
|
- spec/lib/index/base_spec.rb
|
303
303
|
- spec/lib/index/redis_spec.rb
|
@@ -308,7 +308,6 @@ test_files:
|
|
308
308
|
- spec/lib/internals/adapters/rack/live_parameters_spec.rb
|
309
309
|
- spec/lib/internals/adapters/rack/query_spec.rb
|
310
310
|
- spec/lib/internals/calculations/location_spec.rb
|
311
|
-
- spec/lib/internals/configuration/index_spec.rb
|
312
311
|
- spec/lib/internals/cores_spec.rb
|
313
312
|
- spec/lib/internals/extensions/array_spec.rb
|
314
313
|
- spec/lib/internals/extensions/hash_spec.rb
|
@@ -347,12 +346,12 @@ test_files:
|
|
347
346
|
- spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb
|
348
347
|
- spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb
|
349
348
|
- spec/lib/internals/indexed/wrappers/exact_first_spec.rb
|
349
|
+
- spec/lib/internals/indexers/parallel_spec.rb
|
350
350
|
- spec/lib/internals/indexers/serial_spec.rb
|
351
351
|
- spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb
|
352
352
|
- spec/lib/internals/indexing/bundle/memory_spec.rb
|
353
353
|
- spec/lib/internals/indexing/bundle/redis_spec.rb
|
354
354
|
- spec/lib/internals/indexing/bundle/super_base_spec.rb
|
355
|
-
- spec/lib/internals/indexing/categories_spec.rb
|
356
355
|
- spec/lib/internals/indexing/category_spec.rb
|
357
356
|
- spec/lib/internals/indexing/index_spec.rb
|
358
357
|
- spec/lib/internals/indexing/indexes_spec.rb
|
@@ -1,219 +0,0 @@
|
|
1
|
-
class Terminal
|
2
|
-
|
3
|
-
attr_reader :client
|
4
|
-
|
5
|
-
def initialize given_uri, id_amount = nil
|
6
|
-
check_highline_gem
|
7
|
-
check_picky_client_gem
|
8
|
-
|
9
|
-
require 'uri'
|
10
|
-
uri = URI.parse given_uri
|
11
|
-
|
12
|
-
# If the user gave a whole url without http, add that and reparse.
|
13
|
-
#
|
14
|
-
unless uri.path
|
15
|
-
uri = URI.parse "http://#{given_uri}"
|
16
|
-
end
|
17
|
-
|
18
|
-
# If the user gave a path without / in front, add one.
|
19
|
-
#
|
20
|
-
unless uri.path =~ /^\//
|
21
|
-
uri.path = "/#{uri.path}"
|
22
|
-
end
|
23
|
-
|
24
|
-
@searches = 0
|
25
|
-
@durations = 0
|
26
|
-
@current_text = ''
|
27
|
-
@cursor_offset = 0
|
28
|
-
@last_ids = ''
|
29
|
-
@id_amount = id_amount && Integer(id_amount) || 20
|
30
|
-
@client = Picky::Client.new :host => (uri.host || 'localhost'), :port => (uri.port || 8080), :path => uri.path
|
31
|
-
|
32
|
-
install_trap
|
33
|
-
end
|
34
|
-
def check_highline_gem # :nodoc:
|
35
|
-
require "highline/system_extensions"
|
36
|
-
extend HighLine::SystemExtensions
|
37
|
-
rescue LoadError
|
38
|
-
warn_gem_missing 'highline', 'the terminal interface'
|
39
|
-
exit 1
|
40
|
-
end
|
41
|
-
def check_picky_client_gem # :nodoc:
|
42
|
-
require 'picky-client'
|
43
|
-
rescue LoadError
|
44
|
-
warn_gem_missing 'picky-client', 'the terminal interface'
|
45
|
-
exit 1
|
46
|
-
end
|
47
|
-
|
48
|
-
# Install the Ctrl-C handler.
|
49
|
-
#
|
50
|
-
def install_trap
|
51
|
-
Signal.trap('INT') do
|
52
|
-
print "\e[100D"
|
53
|
-
flush
|
54
|
-
puts "\n"
|
55
|
-
puts "You performed #{@searches} searches, totalling #{"%.3f" % @durations} seconds."
|
56
|
-
print "\e[100D"
|
57
|
-
flush
|
58
|
-
exit
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Flush to STDOUT.
|
63
|
-
#
|
64
|
-
def flush
|
65
|
-
STDOUT.flush
|
66
|
-
end
|
67
|
-
|
68
|
-
# Position cursor amount to the left.
|
69
|
-
#
|
70
|
-
def left amount = 1
|
71
|
-
print "\e[#{amount}D"
|
72
|
-
flush
|
73
|
-
end
|
74
|
-
|
75
|
-
# Position cursor amount to the right.
|
76
|
-
#
|
77
|
-
def right amount = 1
|
78
|
-
print "\e[#{amount}C"
|
79
|
-
flush
|
80
|
-
end
|
81
|
-
|
82
|
-
# Move cursor to position.
|
83
|
-
#
|
84
|
-
def move_to position
|
85
|
-
relative = position - @cursor_offset
|
86
|
-
if relative > 0
|
87
|
-
right relative
|
88
|
-
else
|
89
|
-
left relative
|
90
|
-
end
|
91
|
-
@cursor_offset = position
|
92
|
-
flush
|
93
|
-
end
|
94
|
-
|
95
|
-
# Delete one character.
|
96
|
-
#
|
97
|
-
def backspace
|
98
|
-
chop_text
|
99
|
-
print "\e[1D \e[1D"
|
100
|
-
flush
|
101
|
-
end
|
102
|
-
|
103
|
-
# Write the text to the input area.
|
104
|
-
#
|
105
|
-
def write text
|
106
|
-
@cursor_offset += text.size
|
107
|
-
print text
|
108
|
-
flush
|
109
|
-
end
|
110
|
-
|
111
|
-
# Chop off one character.
|
112
|
-
#
|
113
|
-
def chop_text
|
114
|
-
@current_text.chop!
|
115
|
-
end
|
116
|
-
|
117
|
-
# Add the given text to the current text.
|
118
|
-
#
|
119
|
-
def add_text text
|
120
|
-
@current_text << text
|
121
|
-
end
|
122
|
-
|
123
|
-
# Type the given text into the input area.
|
124
|
-
#
|
125
|
-
def type_search character
|
126
|
-
add_text character
|
127
|
-
write character
|
128
|
-
end
|
129
|
-
|
130
|
-
# Write the amount of result ids.
|
131
|
-
#
|
132
|
-
def write_results results
|
133
|
-
move_to 0
|
134
|
-
write "%9d" % (results && results.total || 0)
|
135
|
-
move_to 10 + @current_text.size
|
136
|
-
end
|
137
|
-
|
138
|
-
# Move to the id area.
|
139
|
-
#
|
140
|
-
def move_to_ids
|
141
|
-
move_to 12 + @current_text.size
|
142
|
-
end
|
143
|
-
|
144
|
-
# Write the result ids.
|
145
|
-
#
|
146
|
-
def write_ids results
|
147
|
-
move_to_ids
|
148
|
-
write "=> #{results.total ? results.ids(@id_amount) : []}"
|
149
|
-
rescue StandardError => e
|
150
|
-
p e.message
|
151
|
-
p e.backtrace
|
152
|
-
end
|
153
|
-
|
154
|
-
# Clear the result ids.
|
155
|
-
#
|
156
|
-
def clear_ids
|
157
|
-
move_to_ids
|
158
|
-
write @ids_clearing_string ||= " "*200
|
159
|
-
end
|
160
|
-
|
161
|
-
# Log a search.
|
162
|
-
#
|
163
|
-
def log results
|
164
|
-
@searches += 1
|
165
|
-
@durations += (results[:duration] || 0)
|
166
|
-
end
|
167
|
-
|
168
|
-
# Perform a search.
|
169
|
-
#
|
170
|
-
def search full = false
|
171
|
-
client.search @current_text, :ids => (full ? @id_amount : 0)
|
172
|
-
end
|
173
|
-
|
174
|
-
# Perform a search and write the results.
|
175
|
-
#
|
176
|
-
# Handles 404s and connection problems.
|
177
|
-
#
|
178
|
-
def search_and_write full = false
|
179
|
-
results = search full
|
180
|
-
results.extend Picky::Convenience
|
181
|
-
|
182
|
-
log results
|
183
|
-
|
184
|
-
full ? write_ids(results) : clear_ids
|
185
|
-
|
186
|
-
write_results results
|
187
|
-
rescue Errno::ECONNREFUSED => e
|
188
|
-
write "Please start a Picky server listening to #{@client.path}."
|
189
|
-
rescue Yajl::ParseError => e
|
190
|
-
write "Got a 404. Maybe the path #{@client.path} isn't a correct one?"
|
191
|
-
end
|
192
|
-
|
193
|
-
# Run the terminal.
|
194
|
-
#
|
195
|
-
# Note: Uses a simple loop to handle input.
|
196
|
-
#
|
197
|
-
def run
|
198
|
-
puts "Type and see the result count update. Press enter for the first #{@id_amount} result ids."
|
199
|
-
puts "Break with Ctrl-C."
|
200
|
-
|
201
|
-
search_and_write
|
202
|
-
|
203
|
-
loop do
|
204
|
-
input = get_character
|
205
|
-
|
206
|
-
case input
|
207
|
-
when 127
|
208
|
-
backspace
|
209
|
-
search_and_write
|
210
|
-
when 13
|
211
|
-
search_and_write true
|
212
|
-
else # All other.
|
213
|
-
type_search input.chr
|
214
|
-
search_and_write
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
end
|