picky 3.5.3 → 3.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/backends/internal.rb +23 -0
- data/lib/picky/bundle_indexed.rb +1 -1
- data/lib/picky/bundle_indexing.rb +2 -2
- data/lib/picky/category_indexing.rb +3 -2
- data/lib/picky/generators/similarity/none.rb +0 -6
- data/lib/picky/index_indexing.rb +0 -2
- data/lib/picky/indexers/base.rb +2 -0
- data/lib/picky/rack/harakiri.rb +46 -49
- data/spec/lib/category_indexing_spec.rb +1 -1
- data/spec/lib/generators/similarity/none_spec.rb +2 -8
- data/spec/lib/indexed/bundle_spec.rb +4 -3
- data/spec/lib/indexers/base_spec.rb +14 -2
- data/spec/lib/rack/harakiri_spec.rb +8 -8
- data/spec/specific/dynamic_weights_spec.rb +30 -32
- metadata +27 -26
data/lib/picky/bundle_indexed.rb
CHANGED
@@ -58,9 +58,9 @@ module Picky
|
|
58
58
|
# Dumps the similarity index.
|
59
59
|
#
|
60
60
|
def dump_similarity
|
61
|
-
@backend_similarity.dump @similarity
|
61
|
+
@backend_similarity.dump @similarity if @similarity_strategy.saved?
|
62
62
|
end
|
63
|
-
# Dumps the
|
63
|
+
# Dumps the configuration.
|
64
64
|
#
|
65
65
|
def dump_configuration
|
66
66
|
@backend_configuration.dump @configuration
|
data/lib/picky/index_indexing.rb
CHANGED
@@ -73,10 +73,8 @@ module Picky
|
|
73
73
|
# Only use where the category does have a #each source defined.
|
74
74
|
#
|
75
75
|
def index_in_parallel
|
76
|
-
categories.empty
|
77
76
|
indexer = Indexers::Parallel.new self
|
78
77
|
indexer.index categories
|
79
|
-
categories.cache
|
80
78
|
end
|
81
79
|
|
82
80
|
# Returns the installed tokenizer or the default.
|
data/lib/picky/indexers/base.rb
CHANGED
data/lib/picky/rack/harakiri.rb
CHANGED
@@ -1,61 +1,58 @@
|
|
1
|
-
module
|
1
|
+
module Rack # :nodoc:
|
2
|
+
|
3
|
+
# Simple Rack Middleware to kill Unicorns after X requests.
|
4
|
+
#
|
5
|
+
# Use as follows in e.g. your rackup File:
|
6
|
+
#
|
7
|
+
# Rack::Harakiri.after = 100
|
8
|
+
# use Rack::Harakiri
|
9
|
+
#
|
10
|
+
# Then the Unicorn will commit suicide after 100 requests (50 is the default).
|
11
|
+
#
|
12
|
+
# The Master Unicorn process forks a new child Unicorn to replace the old one.
|
13
|
+
#
|
14
|
+
class Harakiri
|
15
|
+
|
16
|
+
# Set the amount of requests before the Unicorn commits Harakiri.
|
17
|
+
#
|
18
|
+
class << self
|
19
|
+
attr_accessor :after
|
20
|
+
end
|
2
21
|
|
3
|
-
|
22
|
+
def initialize app
|
23
|
+
@app = app
|
4
24
|
|
5
|
-
|
25
|
+
@requests = 0
|
26
|
+
@quit_after_requests = self.class.after || 50
|
27
|
+
end
|
28
|
+
|
29
|
+
# #call interface method.
|
6
30
|
#
|
7
|
-
#
|
31
|
+
# Harakiri is a middleware, so it delegates the the app or
|
32
|
+
# the next middleware after checking if it is time to honorably retire.
|
8
33
|
#
|
9
|
-
|
10
|
-
|
34
|
+
def call env
|
35
|
+
harakiri
|
36
|
+
@app.call env
|
37
|
+
end
|
38
|
+
|
39
|
+
# Checks to see if it is time to honorably retire.
|
11
40
|
#
|
12
|
-
#
|
41
|
+
# If yes, kills itself (Unicorn will answer the request, honorably).
|
13
42
|
#
|
14
|
-
#
|
43
|
+
# Note: Sends its process a QUIT signal if it is time.
|
15
44
|
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
class << self
|
21
|
-
attr_accessor :after
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize app
|
25
|
-
@app = app
|
26
|
-
|
27
|
-
@requests = 0
|
28
|
-
@quit_after_requests = self.class.after || 50
|
29
|
-
end
|
30
|
-
|
31
|
-
# #call interface method.
|
32
|
-
#
|
33
|
-
# Harakiri is a middleware, so it delegates the the app or
|
34
|
-
# the next middleware after checking if it is time to honorably retire.
|
35
|
-
#
|
36
|
-
def call env
|
37
|
-
harakiri
|
38
|
-
@app.call env
|
39
|
-
end
|
40
|
-
|
41
|
-
# Checks to see if it is time to honorably retire.
|
42
|
-
#
|
43
|
-
# If yes, kills itself (Unicorn will answer the request, honorably).
|
44
|
-
#
|
45
|
-
# Note: Sends its process a QUIT signal if it is time.
|
46
|
-
#
|
47
|
-
def harakiri
|
48
|
-
@requests = @requests + 1
|
49
|
-
Process.kill(:QUIT, Process.pid) if harakiri?
|
50
|
-
end
|
51
|
-
|
52
|
-
# Is it time to honorably retire?
|
53
|
-
#
|
54
|
-
def harakiri?
|
55
|
-
@requests >= @quit_after_requests
|
56
|
-
end
|
45
|
+
def harakiri
|
46
|
+
@requests = @requests + 1
|
47
|
+
Process.kill(:QUIT, Process.pid) if harakiri?
|
48
|
+
end
|
57
49
|
|
50
|
+
# Is it time to honorably retire?
|
51
|
+
#
|
52
|
+
def harakiri?
|
53
|
+
@requests >= @quit_after_requests
|
58
54
|
end
|
55
|
+
|
59
56
|
end
|
60
57
|
|
61
58
|
end
|
@@ -7,23 +7,17 @@ describe Picky::Generators::Similarity::None do
|
|
7
7
|
before(:each) do
|
8
8
|
@similarity = described_class.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
describe "saved?" do
|
12
12
|
it "returns the right answer" do
|
13
13
|
@similarity.saved?.should == false
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
describe 'encode' do
|
18
18
|
it 'should always return nil' do
|
19
19
|
@similarity.encoded(:whatever).should == nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe 'generate_from' do
|
24
|
-
it 'should return an empty hash, always' do
|
25
|
-
@similarity.generate_from(:anything).should == {}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
23
|
end
|
@@ -7,8 +7,8 @@ describe Picky::Bundle do
|
|
7
7
|
@category = Picky::Category.new :some_category, @index
|
8
8
|
|
9
9
|
@weights = stub :weights, :saved? => true
|
10
|
-
@partial = stub :partial
|
11
|
-
@similarity = stub :similarity
|
10
|
+
@partial = stub :partial, :saved? => true
|
11
|
+
@similarity = stub :similarity, :saved? => true
|
12
12
|
@bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, @partial, @similarity
|
13
13
|
end
|
14
14
|
|
@@ -159,7 +159,8 @@ describe Picky::Bundle do
|
|
159
159
|
@category = Picky::Category.new :some_category, @index
|
160
160
|
|
161
161
|
@weights = stub :weights, :saved? => true
|
162
|
-
@
|
162
|
+
@partial = stub :partial, :saved? => true
|
163
|
+
@bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, @partial, :similarity
|
163
164
|
end
|
164
165
|
it 'should initialize the index correctly' do
|
165
166
|
@bundle.backend_inverted.should be_kind_of(Picky::Backends::Memory::JSON)
|
@@ -21,9 +21,21 @@ describe Picky::Indexers::Base do
|
|
21
21
|
|
22
22
|
describe 'index' do
|
23
23
|
it 'processes' do
|
24
|
-
|
24
|
+
categories = stub :categories, :empty => nil, :cache => nil
|
25
25
|
|
26
|
-
indexer.
|
26
|
+
indexer.should_receive(:process).once.with categories
|
27
|
+
|
28
|
+
indexer.index categories
|
29
|
+
end
|
30
|
+
it 'calls the right methods on the categories' do
|
31
|
+
indexer.stub! :process
|
32
|
+
|
33
|
+
categories = stub :categories
|
34
|
+
|
35
|
+
categories.should_receive(:empty).once.ordered
|
36
|
+
categories.should_receive(:cache).once.ordered
|
37
|
+
|
38
|
+
indexer.index categories
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Rack::Harakiri do
|
5
5
|
before(:each) do
|
6
6
|
@app = stub :app
|
7
7
|
Process.stub! :kill # not taking any chances
|
@@ -16,24 +16,24 @@ describe Picky::Rack::Harakiri do
|
|
16
16
|
describe 'harakiri?' do
|
17
17
|
it "should be true after 50 harakiri calls" do
|
18
18
|
50.times { @ronin.harakiri }
|
19
|
-
|
19
|
+
|
20
20
|
@ronin.harakiri?.should == true
|
21
21
|
end
|
22
22
|
it "should not be true after just 49 harakiri calls" do
|
23
23
|
49.times { @ronin.harakiri }
|
24
|
-
|
24
|
+
|
25
25
|
@ronin.harakiri?.should == false
|
26
26
|
end
|
27
27
|
end
|
28
28
|
describe "harakiri" do
|
29
29
|
it "should kill the process after 50 harakiri calls" do
|
30
30
|
Process.should_receive(:kill).once
|
31
|
-
|
31
|
+
|
32
32
|
50.times { @ronin.harakiri }
|
33
33
|
end
|
34
34
|
it "should not kill the process after 49 harakiri calls" do
|
35
35
|
Process.should_receive(:kill).never
|
36
|
-
|
36
|
+
|
37
37
|
49.times { @ronin.harakiri }
|
38
38
|
end
|
39
39
|
end
|
@@ -44,12 +44,12 @@ describe Picky::Rack::Harakiri do
|
|
44
44
|
end
|
45
45
|
it "calls harakiri" do
|
46
46
|
@ronin.should_receive(:harakiri).once.with
|
47
|
-
|
47
|
+
|
48
48
|
@ronin.call :env
|
49
49
|
end
|
50
50
|
it "calls the app" do
|
51
51
|
@app.should_receive(:call).once.with :env
|
52
|
-
|
52
|
+
|
53
53
|
@ronin.call :env
|
54
54
|
end
|
55
55
|
end
|
@@ -66,5 +66,5 @@ describe Picky::Rack::Harakiri do
|
|
66
66
|
@ronin.instance_variable_get(:@quit_after_requests).should == 100
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
end
|
@@ -6,39 +6,37 @@ describe "Weights" do
|
|
6
6
|
|
7
7
|
# This tests the weights option.
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
category :text4 # Default
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'ostruct'
|
20
|
-
|
21
|
-
thing = OpenStruct.new id: 1, text1: "ohai", text2: "hello", text3: "world", text4: "kthxbye"
|
22
|
-
other = OpenStruct.new id: 2, text1: "", text2: "", text3: "", text4: "kthxbye"
|
23
|
-
|
24
|
-
index.add thing
|
25
|
-
index.add other
|
26
|
-
|
27
|
-
try = Picky::Search.new index
|
28
|
-
|
29
|
-
try.search("text1:ohai").allocations.first.score.should == 0.0
|
30
|
-
try.search("text2:hello").allocations.first.score.should == 3.14
|
31
|
-
try.search("text3:world").allocations.first.score.should == 5
|
32
|
-
try.search("text4:kthxbye").allocations.first.score.should == 0.6931471805599453
|
33
|
-
|
34
|
-
try_with_boosts = Picky::Search.new index do
|
35
|
-
boost [:text1] => +7.65,
|
36
|
-
[:text2] => +1.86
|
37
|
-
end
|
38
|
-
|
39
|
-
try_with_boosts.search("text1:ohai").allocations.first.score.should == 7.65
|
40
|
-
try_with_boosts.search("text2:hello").allocations.first.score.should == 5.00
|
9
|
+
it 'can handle dynamic weights' do
|
10
|
+
index = Picky::Index.new :dynamic_weights do
|
11
|
+
source { [] }
|
12
|
+
category :text1, weights: Picky::Weights::Constant.new
|
13
|
+
category :text2, weights: Picky::Weights::Constant.new(3.14)
|
14
|
+
category :text3, weights: Picky::Weights::Dynamic.new { |str_or_sym| str_or_sym.size }
|
15
|
+
category :text4 # Default
|
41
16
|
end
|
17
|
+
|
18
|
+
require 'ostruct'
|
19
|
+
|
20
|
+
thing = OpenStruct.new id: 1, text1: "ohai", text2: "hello", text3: "world", text4: "kthxbye"
|
21
|
+
other = OpenStruct.new id: 2, text1: "", text2: "", text3: "", text4: "kthxbye"
|
22
|
+
|
23
|
+
index.add thing
|
24
|
+
index.add other
|
25
|
+
|
26
|
+
try = Picky::Search.new index
|
27
|
+
|
28
|
+
try.search("text1:ohai").allocations.first.score.should == 0.0
|
29
|
+
try.search("text2:hello").allocations.first.score.should == 3.14
|
30
|
+
try.search("text3:world").allocations.first.score.should == 5
|
31
|
+
try.search("text4:kthxbye").allocations.first.score.should == 0.6931471805599453
|
32
|
+
|
33
|
+
try_with_boosts = Picky::Search.new index do
|
34
|
+
boost [:text1] => +7.65,
|
35
|
+
[:text2] => +1.86
|
36
|
+
end
|
37
|
+
|
38
|
+
try_with_boosts.search("text1:ohai").allocations.first.score.should == 7.65
|
39
|
+
try_with_boosts.search("text2:hello").allocations.first.score.should == 5.00
|
42
40
|
end
|
43
41
|
|
44
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70194764507240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70194764507240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70194764520160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.5.
|
32
|
+
version: 3.5.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70194764520160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70194764515800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70194764515800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack_fast_escape
|
49
|
-
requirement: &
|
49
|
+
requirement: &70194764527800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70194764527800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: text
|
60
|
-
requirement: &
|
60
|
+
requirement: &70194764523720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70194764523720
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yajl-ruby
|
71
|
-
requirement: &
|
71
|
+
requirement: &70194764538580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70194764538580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &70194764536640 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '3.0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70194764536640
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: activerecord
|
93
|
-
requirement: &
|
93
|
+
requirement: &70194764534940 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '3.0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70194764534940
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: unicorn
|
104
|
-
requirement: &
|
104
|
+
requirement: &70194764534200 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70194764534200
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sinatra
|
115
|
-
requirement: &
|
115
|
+
requirement: &70194764533260 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70194764533260
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: redis
|
126
|
-
requirement: &
|
126
|
+
requirement: &70194764532140 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70194764532140
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: mysql
|
137
|
-
requirement: &
|
137
|
+
requirement: &70194764544080 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70194764544080
|
146
146
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
147
147
|
email: florian.hanke+picky@gmail.com
|
148
148
|
executables:
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/picky/backends/file/json.rb
|
164
164
|
- lib/picky/backends/file.rb
|
165
165
|
- lib/picky/backends/helpers/file.rb
|
166
|
+
- lib/picky/backends/internal.rb
|
166
167
|
- lib/picky/backends/memory/basic.rb
|
167
168
|
- lib/picky/backends/memory/json.rb
|
168
169
|
- lib/picky/backends/memory/marshal.rb
|