picky 4.8.1 → 4.9.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/picky/bundle.rb +3 -1
- data/lib/picky/category.rb +28 -14
- data/lib/picky/scheduler.rb +13 -1
- data/lib/picky.rb +0 -1
- data/spec/functional/reloading_spec.rb +4 -4
- metadata +4 -20
data/lib/picky/bundle.rb
CHANGED
@@ -43,7 +43,9 @@ module Picky
|
|
43
43
|
|
44
44
|
delegate :[], :[]=, :to => :configuration
|
45
45
|
delegate :index_directory, :to => :category
|
46
|
-
|
46
|
+
|
47
|
+
# TODO Move the strategies into options.
|
48
|
+
#
|
47
49
|
def initialize name, category, weight_strategy, partial_strategy, similarity_strategy, options = {}
|
48
50
|
@name = name
|
49
51
|
@category = category
|
data/lib/picky/category.rb
CHANGED
@@ -60,25 +60,39 @@ module Picky
|
|
60
60
|
# TODO I do a lot of helper method calls here. Refactor?
|
61
61
|
#
|
62
62
|
def configure_indexes_from options
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
partial = Generators::Partial.from options[:partial], index_name, name
|
67
|
-
similarity = Generators::Similarity.from options[:similarity], index_name, name
|
63
|
+
weights = weights_from options
|
64
|
+
partial = partial_from options
|
65
|
+
similarity = similarity_from options
|
68
66
|
|
69
|
-
|
70
|
-
|
67
|
+
@exact = exact_for weights, similarity, options
|
68
|
+
@partial = partial_for @exact, partial, weights, options
|
71
69
|
|
72
|
-
@
|
73
|
-
|
74
|
-
|
70
|
+
@prepared = Backends::Prepared::Text.new prepared_index_path
|
71
|
+
end
|
72
|
+
def weights_from options
|
73
|
+
Generators::Weights.from options[:weight], index_name, name
|
74
|
+
end
|
75
|
+
def partial_from options
|
76
|
+
Generators::Partial.from options[:partial], index_name, name
|
77
|
+
end
|
78
|
+
def similarity_from options
|
79
|
+
Generators::Similarity.from options[:similarity], index_name, name
|
80
|
+
end
|
81
|
+
def exact_for weights, similarity, options
|
82
|
+
Bundle.new :exact, self, weights, Generators::Partial::None.new, similarity, options
|
83
|
+
end
|
84
|
+
def partial_for exact, partial_options, weights, options
|
85
|
+
# TODO Also partial.extend Bundle::Exact like in the category.
|
86
|
+
#
|
87
|
+
# Instead of exact for partial, use respond_to? :exact= on eg. Partial::None, then set it on the instance?
|
88
|
+
#
|
89
|
+
if partial_options.respond_to?(:use_exact_for_partial?) && partial_options.use_exact_for_partial?
|
90
|
+
Wrappers::Bundle::ExactPartial.new exact
|
75
91
|
else
|
76
|
-
|
92
|
+
Bundle.new :partial, self, weights, partial_options, Generators::Similarity::None.new, options
|
77
93
|
end
|
78
|
-
|
79
|
-
@prepared = Backends::Prepared::Text.new prepared_index_path
|
80
94
|
end
|
81
|
-
|
95
|
+
|
82
96
|
# Indexes and loads the category.
|
83
97
|
#
|
84
98
|
def reindex
|
data/lib/picky/scheduler.rb
CHANGED
@@ -22,7 +22,11 @@ module Picky
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def scheduler
|
25
|
-
@scheduler ||=
|
25
|
+
@scheduler ||= create_scheduler
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_scheduler
|
29
|
+
Procrastinate::Scheduler.start Procrastinate::SpawnStrategy::Default.new(@factor)
|
26
30
|
end
|
27
31
|
else
|
28
32
|
def schedule
|
@@ -36,7 +40,15 @@ module Picky
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def fork?
|
43
|
+
require 'procrastinate'
|
39
44
|
parallel && Process.respond_to?(:fork)
|
45
|
+
rescue LoadError => e
|
46
|
+
warn_procrastinate_missing
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
def warn_procrastinate_missing
|
50
|
+
warn_gem_missing 'Procrastinate', 'parallelized indexing (with the procrastinate gem)' unless @gem_missing_warned
|
51
|
+
@gem_missing_warned = true
|
40
52
|
end
|
41
53
|
|
42
54
|
end
|
data/lib/picky.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe "Realtime Indexing" do
|
6
6
|
|
7
|
-
|
7
|
+
ReloadingBook = Struct.new(:id, :title, :author)
|
8
8
|
|
9
9
|
context 'default index' do
|
10
10
|
let(:index) do
|
@@ -16,12 +16,12 @@ describe "Realtime Indexing" do
|
|
16
16
|
let(:books) { Picky::Search.new index }
|
17
17
|
|
18
18
|
before(:each) do
|
19
|
-
index.add
|
19
|
+
index.add ReloadingBook.new(1, "Title", "Author")
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'dumping and loading' do
|
23
23
|
it "doesn't find books anymore after dumping and loading and updating" do
|
24
|
-
index.replace
|
24
|
+
index.replace ReloadingBook.new(2, "Title New", "Author New")
|
25
25
|
|
26
26
|
books.search("title").ids.should == [2, 1]
|
27
27
|
|
@@ -29,7 +29,7 @@ describe "Realtime Indexing" do
|
|
29
29
|
index.load
|
30
30
|
index.build_realtime_mapping
|
31
31
|
|
32
|
-
index.replace
|
32
|
+
index.replace ReloadingBook.new(2, "Blah New", "Author New")
|
33
33
|
|
34
34
|
books.search("title").ids.should == [1]
|
35
35
|
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: 4.
|
4
|
+
version: 4.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 4.
|
37
|
+
version: 4.9.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 4.
|
45
|
+
version: 4.9.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: text
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,22 +91,6 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '3.0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: procrastinate
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0.4'
|
102
|
-
type: :runtime
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0.4'
|
110
94
|
- !ruby/object:Gem::Dependency
|
111
95
|
name: rack_fast_escape
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|