picky 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/index/base.rb +1 -3
- data/lib/picky/index_bundle.rb +5 -7
- data/lib/picky/indexed/indexes.rb +6 -8
- data/lib/picky/indexing/indexes.rb +1 -14
- data/lib/picky/internals/indexed/category.rb +1 -1
- data/lib/picky/internals/indexing/bundle/base.rb +3 -3
- data/lib/picky/internals/indexing/category.rb +4 -2
- data/lib/tasks/index.rake +3 -2
- data/spec/lib/index_bundle_spec.rb +0 -2
- data/spec/lib/indexing/indexes_spec.rb +1 -45
- data/spec/lib/internals/indexing/category_spec.rb +1 -5
- metadata +2 -2
data/lib/picky/index/base.rb
CHANGED
@@ -218,9 +218,7 @@ INDEX
|
|
218
218
|
|
219
219
|
# Define a key_format on the index.
|
220
220
|
#
|
221
|
-
# Parameter is a
|
222
|
-
# anything responding to #each and returning objects that
|
223
|
-
# respond to id and the category names (or the category from option).
|
221
|
+
# Parameter is a method name to use on the key (e.g. :to_i, :to_s, :strip).
|
224
222
|
#
|
225
223
|
def key_format key_format
|
226
224
|
internal_indexing.define_key_format key_format
|
data/lib/picky/index_bundle.rb
CHANGED
@@ -9,14 +9,12 @@ class IndexBundle # :nodoc:all
|
|
9
9
|
:to => :indexes
|
10
10
|
|
11
11
|
delegate :analyze,
|
12
|
-
:reload,
|
13
12
|
:load_from_cache,
|
13
|
+
:reload,
|
14
14
|
:to => :indexed
|
15
15
|
|
16
16
|
delegate :check_caches,
|
17
17
|
:find,
|
18
|
-
:generate_cache_only,
|
19
|
-
:generate_index_only,
|
20
18
|
:index,
|
21
19
|
:index_for_tests,
|
22
20
|
:to => :indexing
|
@@ -29,10 +27,6 @@ class IndexBundle # :nodoc:all
|
|
29
27
|
@indexing = Indexing::Indexes.new
|
30
28
|
end
|
31
29
|
|
32
|
-
def to_s
|
33
|
-
indexes.map &:to_stats
|
34
|
-
end
|
35
|
-
|
36
30
|
def register index
|
37
31
|
self.indexes << index
|
38
32
|
self.index_mapping[index.name] = index
|
@@ -46,5 +40,9 @@ class IndexBundle # :nodoc:all
|
|
46
40
|
|
47
41
|
self.index_mapping[name]
|
48
42
|
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
indexes.map &:to_stats
|
46
|
+
end
|
49
47
|
|
50
48
|
end
|
@@ -5,13 +5,18 @@ module Indexed # :nodoc:all
|
|
5
5
|
class Indexes
|
6
6
|
|
7
7
|
attr_reader :indexes, :index_mapping
|
8
|
-
|
8
|
+
|
9
9
|
each_delegate :load_from_cache,
|
10
10
|
:to => :indexes
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
clear
|
14
14
|
end
|
15
|
+
|
16
|
+
# Reloads all indexes, one after another,
|
17
|
+
# in the order they were added.
|
18
|
+
#
|
19
|
+
alias reload load_from_cache
|
15
20
|
|
16
21
|
def to_s
|
17
22
|
indexes.indented_to_s
|
@@ -24,13 +29,6 @@ module Indexed # :nodoc:all
|
|
24
29
|
@index_mapping = {}
|
25
30
|
end
|
26
31
|
|
27
|
-
# Reloads all indexes, one after another,
|
28
|
-
# in the order they were added.
|
29
|
-
#
|
30
|
-
def reload
|
31
|
-
load_from_cache
|
32
|
-
end
|
33
|
-
|
34
32
|
# Registers an index with the indexes.
|
35
33
|
#
|
36
34
|
def register index
|
@@ -66,22 +66,9 @@ module Indexing # :nodoc:all
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
# Generate only the index for the given index:category pair.
|
70
|
-
#
|
71
|
-
def generate_index_only index_name, category_name = nil
|
72
|
-
found = find index_name, category_name
|
73
|
-
found.index! if found
|
74
|
-
end
|
75
|
-
# Generate only the cache for the given index:category pair.
|
76
|
-
#
|
77
|
-
def generate_cache_only index_name, category_name = nil
|
78
|
-
found = find index_name, category_name
|
79
|
-
found.generate_caches if found
|
80
|
-
end
|
81
|
-
|
82
69
|
# Find a given index:category pair.
|
83
70
|
#
|
84
|
-
def find index_name, category_name
|
71
|
+
def find index_name, category_name = nil
|
85
72
|
index_name = index_name.to_sym
|
86
73
|
|
87
74
|
indexes.each do |index|
|
@@ -33,9 +33,9 @@ module Internals
|
|
33
33
|
#
|
34
34
|
|
35
35
|
# This method
|
36
|
-
# *
|
37
|
-
# *
|
38
|
-
# *
|
36
|
+
# * Loads the base index from the "prepared..." file.
|
37
|
+
# * Generates derived indexes.
|
38
|
+
# * Dumps all the indexes into files.
|
39
39
|
#
|
40
40
|
def generate_caches_from_source
|
41
41
|
load_from_index_file
|
@@ -103,7 +103,9 @@ module Internals
|
|
103
103
|
exact.delete
|
104
104
|
partial.delete
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
|
+
# Indexes, creates the "prepared_..." file.
|
108
|
+
#
|
107
109
|
def index!
|
108
110
|
prepare_index_directory
|
109
111
|
indexer.index
|
@@ -113,7 +115,6 @@ module Internals
|
|
113
115
|
#
|
114
116
|
def cache!
|
115
117
|
prepare_index_directory
|
116
|
-
configure
|
117
118
|
generate_caches
|
118
119
|
end
|
119
120
|
# We need to set what formatting method should be used.
|
@@ -124,6 +125,7 @@ module Internals
|
|
124
125
|
partial[:key_format] = self.key_format
|
125
126
|
end
|
126
127
|
def generate_caches
|
128
|
+
configure
|
127
129
|
generate_caches_from_source
|
128
130
|
generate_partial
|
129
131
|
generate_caches_from_memory
|
data/lib/tasks/index.rake
CHANGED
@@ -23,8 +23,9 @@ namespace :index do
|
|
23
23
|
desc "Generates a specific index from index snapshots (category optional)."
|
24
24
|
task :specific, [:index, :category] => :application do |_, options|
|
25
25
|
index, category = options.index, options.category
|
26
|
-
Indexes.
|
27
|
-
|
26
|
+
specific_index = Indexes.find index.to_sym, (category && category.to_sym)
|
27
|
+
specific_index.index!
|
28
|
+
specific_index.cache!
|
28
29
|
end
|
29
30
|
|
30
31
|
end
|
@@ -28,8 +28,6 @@ describe IndexBundle do
|
|
28
28
|
|
29
29
|
it_delegates :check_caches, :indexing
|
30
30
|
it_delegates :find, :indexing
|
31
|
-
it_delegates :generate_cache_only, :indexing
|
32
|
-
it_delegates :generate_index_only, :indexing
|
33
31
|
it_delegates :index, :indexing
|
34
32
|
it_delegates :index_for_tests, :indexing
|
35
33
|
end
|
@@ -17,50 +17,6 @@ describe Indexing::Indexes do
|
|
17
17
|
indexes.register @index1
|
18
18
|
indexes.register @index2
|
19
19
|
end
|
20
|
-
describe 'generate_index_only' do
|
21
|
-
context 'with index:category found' do
|
22
|
-
before(:each) do
|
23
|
-
indexes.should_receive(:find).once.with(:index, :category).and_return @index1
|
24
|
-
end
|
25
|
-
it 'indexes' do
|
26
|
-
@index1.should_receive(:index!).once.with
|
27
|
-
|
28
|
-
indexes.generate_index_only :index, :category
|
29
|
-
end
|
30
|
-
end
|
31
|
-
context 'with index not found' do
|
32
|
-
before(:each) do
|
33
|
-
indexes.should_receive(:find).once.with(:index, :category).and_return nil
|
34
|
-
end
|
35
|
-
it 'indexes' do
|
36
|
-
@index1.should_receive(:index).never
|
37
|
-
|
38
|
-
indexes.generate_index_only :index, :category
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
describe 'generate_cache_only' do
|
43
|
-
context 'with index:category found' do
|
44
|
-
before(:each) do
|
45
|
-
indexes.should_receive(:find).once.with(:index, :category).and_return @index1
|
46
|
-
end
|
47
|
-
it 'indexes' do
|
48
|
-
@index1.should_receive(:generate_caches).once.with
|
49
|
-
|
50
|
-
indexes.generate_cache_only :index, :category
|
51
|
-
end
|
52
|
-
end
|
53
|
-
context 'with index not found' do
|
54
|
-
before(:each) do
|
55
|
-
indexes.should_receive(:find).once.with(:index, :category).and_return nil
|
56
|
-
end
|
57
|
-
it 'indexes' do
|
58
|
-
@index1.should_receive(:generate_caches).never
|
59
|
-
|
60
|
-
indexes.generate_cache_only :index, :category
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
20
|
describe 'index_for_tests' do
|
65
21
|
it 'takes a snapshot, then indexes and caches each' do
|
66
22
|
indexes.should_receive(:take_snapshot).once.with.ordered
|
@@ -86,7 +42,7 @@ describe Indexing::Indexes do
|
|
86
42
|
end
|
87
43
|
def self.it_delegates_each name
|
88
44
|
describe name do
|
89
|
-
it
|
45
|
+
it "calls #{name} on each in order" do
|
90
46
|
@index1.should_receive(name).once.with.ordered
|
91
47
|
@index2.should_receive(name).once.with.ordered
|
92
48
|
|
@@ -96,6 +96,7 @@ describe Internals::Indexing::Category do
|
|
96
96
|
|
97
97
|
describe 'generate_caches' do
|
98
98
|
it 'should call multiple methods in order' do
|
99
|
+
category.should_receive(:configure).once.with().ordered
|
99
100
|
category.should_receive(:generate_caches_from_source).once.with().ordered
|
100
101
|
category.should_receive(:generate_partial).once.with().ordered
|
101
102
|
category.should_receive(:generate_caches_from_memory).once.with().ordered
|
@@ -168,11 +169,6 @@ describe Internals::Indexing::Category do
|
|
168
169
|
|
169
170
|
category.cache!
|
170
171
|
end
|
171
|
-
it "configures" do
|
172
|
-
category.should_receive(:configure).once.with
|
173
|
-
|
174
|
-
category.cache!
|
175
|
-
end
|
176
172
|
it "tells the indexer to index" do
|
177
173
|
category.should_receive(:generate_caches).once.with
|
178
174
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.5.
|
5
|
+
version: 2.5.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.5.
|
35
|
+
version: 2.5.1
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id002
|
38
38
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|