picky 0.11.1 → 0.11.2
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 +1 -1
- data/lib/picky/cacher/partial/none.rb +6 -0
- data/lib/picky/cacher/partial/strategy.rb +3 -1
- data/lib/picky/cacher/similarity/none.rb +6 -0
- data/lib/picky/cacher/similarity/strategy.rb +3 -1
- data/lib/picky/cacher/strategy.rb +12 -0
- data/lib/picky/cacher/weights/strategy.rb +3 -1
- data/lib/picky/extensions/object.rb +6 -2
- data/lib/picky/index/file/basic.rb +1 -1
- data/lib/picky/index/file/json.rb +1 -1
- data/lib/picky/indexing/bundle.rb +29 -6
- data/lib/picky/loader.rb +5 -1
- data/lib/picky/sources/base.rb +26 -5
- data/lib/picky/sources/db.rb +0 -2
- data/lib/picky/types.rb +4 -3
- data/lib/tasks/index.rake +6 -16
- data/spec/lib/cacher/cacher_strategy_spec.rb +11 -0
- data/spec/lib/cacher/similarity/none_spec.rb +7 -1
- data/spec/lib/index/bundle_spec.rb +1 -1
- data/spec/lib/index/file/json_spec.rb +1 -1
- data/spec/lib/indexing/bundle_spec.rb +96 -29
- metadata +8 -5
data/lib/picky/bundle.rb
CHANGED
@@ -6,7 +6,7 @@ class Bundle
|
|
6
6
|
delegate :[], :[]=, :clear, :to => :index
|
7
7
|
|
8
8
|
def initialize name, category, type, similarity_strategy
|
9
|
-
@identifier = "#{name}: #{
|
9
|
+
@identifier = "#{type.name}: #{name} #{category.name}"
|
10
10
|
|
11
11
|
@index = {}
|
12
12
|
@weights = {}
|
@@ -1,10 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class Object
|
3
2
|
|
3
|
+
# Puts a text in the form:
|
4
|
+
# 12:34:56: text here
|
5
|
+
#
|
4
6
|
def timed_exclaim text
|
5
7
|
exclaim "#{Time.now.strftime("%H:%M:%S")}: #{text}"
|
6
8
|
end
|
7
9
|
|
10
|
+
# Just puts the given text.
|
11
|
+
#
|
8
12
|
def exclaim text
|
9
13
|
puts text
|
10
14
|
end
|
@@ -131,16 +131,39 @@ module Indexing
|
|
131
131
|
# Alerts the user if an index is missing.
|
132
132
|
#
|
133
133
|
def raise_unless_cache_exists
|
134
|
-
|
134
|
+
raise_unless_index_exists
|
135
|
+
raise_unless_similarity_exists
|
136
|
+
end
|
137
|
+
def raise_unless_index_exists
|
138
|
+
if partial_strategy.saved?
|
139
|
+
warn_if_index_small
|
140
|
+
raise_unless_index_ok
|
141
|
+
end
|
142
|
+
end
|
143
|
+
def raise_unless_similarity_exists
|
144
|
+
if similarity_strategy.saved?
|
145
|
+
warn_if_similarity_small
|
146
|
+
raise_unless_similarity_ok
|
147
|
+
end
|
148
|
+
end
|
149
|
+
def warn_if_similarity_small
|
135
150
|
warn_cache_small :similarity if files.similarity_cache_small?
|
136
|
-
|
137
|
-
|
138
|
-
raise_cache_missing :index unless files.index_cache_ok?
|
151
|
+
end
|
152
|
+
def raise_unless_similarity_ok
|
139
153
|
raise_cache_missing :similarity unless files.similarity_cache_ok?
|
140
|
-
|
154
|
+
end
|
155
|
+
# TODO Spec on down.
|
156
|
+
#
|
157
|
+
def warn_if_index_small
|
158
|
+
warn_cache_small :index if files.index_cache_small?
|
159
|
+
warn_cache_small :weights if files.weights_cache_small?
|
160
|
+
end
|
161
|
+
def raise_unless_index_ok
|
162
|
+
raise_cache_missing :index unless files.index_cache_ok?
|
163
|
+
raise_cache_missing :weights unless files.weights_cache_ok?
|
141
164
|
end
|
142
165
|
def warn_cache_small what
|
143
|
-
puts "#{what} cache for #{identifier} smaller than 16 bytes."
|
166
|
+
puts "Warning: #{what} cache for #{identifier} smaller than 16 bytes."
|
144
167
|
end
|
145
168
|
# Raises an appropriate error message.
|
146
169
|
#
|
data/lib/picky/loader.rb
CHANGED
@@ -123,7 +123,11 @@ module Loader
|
|
123
123
|
load_relative 'indexers/default'
|
124
124
|
#
|
125
125
|
# load_relative 'indexers/solr'
|
126
|
-
|
126
|
+
|
127
|
+
# Cacher.
|
128
|
+
#
|
129
|
+
load_relative 'cacher/strategy'
|
130
|
+
|
127
131
|
# Partial index generation strategies.
|
128
132
|
#
|
129
133
|
load_relative 'cacher/partial/strategy'
|
data/lib/picky/sources/base.rb
CHANGED
@@ -1,26 +1,47 @@
|
|
1
1
|
module Sources
|
2
2
|
|
3
3
|
# Sources are where your data comes from.
|
4
|
-
# Harvest is the most important method as it is used always to get data.
|
5
4
|
#
|
5
|
+
# Basically, a source has 1-3 methods.
|
6
|
+
# * harvest: Used by the indexer to gather data.
|
7
|
+
# Yields an indexed_id (string or integer) and a string value.
|
8
|
+
#
|
9
|
+
# * connect_backend: Optional, called once for each type/category pair.
|
10
|
+
# * take_snapshot: Optional, called once for each type.
|
6
11
|
class Base
|
7
12
|
|
8
13
|
# Note: Methods listed for illustrative purposes.
|
9
14
|
#
|
10
15
|
|
11
|
-
#
|
16
|
+
# Called by the indexer when gathering data.
|
17
|
+
#
|
18
|
+
# Yields the data (id, text for id) for the given type and field.
|
19
|
+
#
|
20
|
+
# When implementing or overriding your own,
|
21
|
+
# be sure to <tt>yield</tt> (or <tt>block.call</tt>) an id (as string or integer)
|
22
|
+
# and a corresponding text for the given type symbol and
|
23
|
+
# category symbol.
|
12
24
|
#
|
13
|
-
def harvest type,
|
25
|
+
def harvest type, category
|
14
26
|
# yields nothing
|
15
27
|
end
|
16
28
|
|
17
|
-
#
|
29
|
+
# Connect to the backend.
|
30
|
+
#
|
31
|
+
# Note: Called once per index/category combination
|
32
|
+
# before harvesting.
|
33
|
+
#
|
34
|
+
# For example, the db backend connects the db adapter.
|
18
35
|
#
|
19
36
|
def connect_backend
|
20
37
|
|
21
38
|
end
|
22
39
|
|
23
|
-
#
|
40
|
+
# Used to take a snapshot of your data if it is fast changing.
|
41
|
+
# e.g. in a database, a table based on the source's select
|
42
|
+
# statement is created.
|
43
|
+
#
|
44
|
+
# Note: Called before harvesting.
|
24
45
|
#
|
25
46
|
def take_snapshot type
|
26
47
|
|
data/lib/picky/sources/db.rb
CHANGED
data/lib/picky/types.rb
CHANGED
@@ -8,11 +8,12 @@ class Types
|
|
8
8
|
:load_from_cache,
|
9
9
|
:to => :@indexes
|
10
10
|
|
11
|
-
delegate :
|
11
|
+
delegate :check_caches,
|
12
|
+
:find,
|
13
|
+
:generate_cache_only,
|
14
|
+
:generate_index_only,
|
12
15
|
:index,
|
13
16
|
:index_for_tests,
|
14
|
-
:generate_index_only,
|
15
|
-
:generate_cache_only,
|
16
17
|
:to => :@indexings
|
17
18
|
|
18
19
|
def initialize
|
data/lib/tasks/index.rake
CHANGED
@@ -2,16 +2,6 @@
|
|
2
2
|
#
|
3
3
|
namespace :index do
|
4
4
|
|
5
|
-
# Not necessary anymore.
|
6
|
-
#
|
7
|
-
# namespace :directories do
|
8
|
-
# desc 'Creates the directory structure for the indexes.'
|
9
|
-
# task :make => :application do
|
10
|
-
# Indexes.create_directory_structure
|
11
|
-
# puts "Directory structure generated."
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
|
15
5
|
desc "Takes a snapshot, indexes, and caches in random order."
|
16
6
|
task :randomly => :application do
|
17
7
|
Indexes.index true
|
@@ -26,12 +16,6 @@ namespace :index do
|
|
26
16
|
Indexes.take_snapshot
|
27
17
|
end
|
28
18
|
|
29
|
-
# desc "E.g. Generates a specific index table. Note: intermediate indexes need to be there."
|
30
|
-
# task :only, [:type, :field] => :application do |_, options|
|
31
|
-
# type, field = options.type, options.field
|
32
|
-
# Indexes.generate_index_only type.to_sym, field.to_sym
|
33
|
-
# end
|
34
|
-
|
35
19
|
desc "Generates a specific index from index snapshots."
|
36
20
|
task :specific, [:type, :field] => :application do |_, options|
|
37
21
|
type, field = options.type, options.field
|
@@ -39,4 +23,10 @@ namespace :index do
|
|
39
23
|
Indexes.generate_cache_only type.to_sym, field.to_sym
|
40
24
|
end
|
41
25
|
|
26
|
+
desc 'Checks the index files for files that are suspiciously small or missing.'
|
27
|
+
task :check => :application do
|
28
|
+
Indexes.check_caches
|
29
|
+
puts "All indexes look ok."
|
30
|
+
end
|
31
|
+
|
42
32
|
end
|
@@ -7,7 +7,13 @@ describe Cacher::Similarity::None do
|
|
7
7
|
before(:each) do
|
8
8
|
@similarity = Cacher::Similarity::None.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
describe "saved?" do
|
12
|
+
it "returns the right answer" do
|
13
|
+
@similarity.saved?.should == false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
describe 'encode' do
|
12
18
|
it 'should always return nil' do
|
13
19
|
@similarity.encoded(:whatever).should == nil
|
@@ -14,7 +14,7 @@ describe Indexing::Bundle do
|
|
14
14
|
|
15
15
|
describe 'identifier' do
|
16
16
|
it 'should return a specific identifier' do
|
17
|
-
@index.identifier.should == '
|
17
|
+
@index.identifier.should == 'some_type: some_name some_category'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -99,47 +99,114 @@ describe Indexing::Bundle do
|
|
99
99
|
@index.dump
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
describe 'raise_unless_cache_exists' do
|
104
|
-
|
105
|
-
@
|
106
|
-
@
|
107
|
-
@files.stub! :similarity_cache_ok? => true
|
108
|
-
@files.stub! :weights_cache_ok? => true
|
109
|
-
@files.stub! :index_cache_small? => false
|
110
|
-
@files.stub! :similarity_cache_small? => false
|
111
|
-
@files.stub! :weights_cache_small? => false
|
104
|
+
it "calls methods in order" do
|
105
|
+
@index.should_receive(:raise_unless_index_exists).once.ordered
|
106
|
+
@index.should_receive(:raise_unless_similarity_exists).once.ordered
|
112
107
|
|
113
|
-
@index.
|
108
|
+
@index.raise_unless_cache_exists
|
114
109
|
end
|
115
|
-
|
110
|
+
end
|
111
|
+
describe 'raise_unless_index_exists' do
|
112
|
+
context 'partial strategy saved' do
|
116
113
|
before(:each) do
|
117
|
-
|
114
|
+
strategy = stub :strategy, :saved? => true
|
115
|
+
@index.stub! :partial_strategy => strategy
|
118
116
|
end
|
119
|
-
it
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
it "calls the methods in order" do
|
118
|
+
@index.should_receive(:warn_if_index_small).once.ordered
|
119
|
+
@index.should_receive(:raise_unless_index_ok).once.ordered
|
120
|
+
|
121
|
+
@index.raise_unless_index_exists
|
123
122
|
end
|
124
123
|
end
|
125
|
-
context '
|
124
|
+
context 'partial strategy not saved' do
|
126
125
|
before(:each) do
|
127
|
-
|
126
|
+
strategy = stub :strategy, :saved? => false
|
127
|
+
@index.stub! :partial_strategy => strategy
|
128
128
|
end
|
129
|
-
it
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
it "calls nothing" do
|
130
|
+
@index.should_receive(:warn_if_index_small).never
|
131
|
+
@index.should_receive(:raise_unless_index_ok).never
|
132
|
+
|
133
|
+
@index.raise_unless_index_exists
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
describe 'raise_unless_similarity_exists' do
|
138
|
+
context 'similarity strategy saved' do
|
139
|
+
before(:each) do
|
140
|
+
strategy = stub :strategy, :saved? => true
|
141
|
+
@index.stub! :similarity_strategy => strategy
|
133
142
|
end
|
143
|
+
it "calls the methods in order" do
|
144
|
+
@index.should_receive(:warn_if_similarity_small).once.ordered
|
145
|
+
@index.should_receive(:raise_unless_similarity_ok).once.ordered
|
146
|
+
|
147
|
+
@index.raise_unless_similarity_exists
|
148
|
+
end
|
149
|
+
end
|
150
|
+
context 'similarity strategy not saved' do
|
151
|
+
before(:each) do
|
152
|
+
strategy = stub :strategy, :saved? => false
|
153
|
+
@index.stub! :similarity_strategy => strategy
|
154
|
+
end
|
155
|
+
it "calls nothing" do
|
156
|
+
@index.should_receive(:warn_if_similarity_small).never
|
157
|
+
@index.should_receive(:raise_unless_similarity_ok).never
|
158
|
+
|
159
|
+
@index.raise_unless_similarity_exists
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
describe 'warn_if_similarity_small' do
|
164
|
+
before(:each) do
|
165
|
+
@files = @index.files
|
134
166
|
end
|
135
|
-
context
|
167
|
+
context "files similarity cache small" do
|
136
168
|
before(:each) do
|
137
|
-
@files.stub! :
|
169
|
+
@files.stub! :similarity_cache_small? => true
|
170
|
+
end
|
171
|
+
it "warns" do
|
172
|
+
@index.should_receive(:warn_cache_small).once.with :similarity
|
173
|
+
|
174
|
+
@index.warn_if_similarity_small
|
175
|
+
end
|
176
|
+
end
|
177
|
+
context "files similarity cache not small" do
|
178
|
+
before(:each) do
|
179
|
+
@files.stub! :similarity_cache_small? => false
|
180
|
+
end
|
181
|
+
it "does not warn" do
|
182
|
+
@index.should_receive(:warn_cache_small).never
|
183
|
+
|
184
|
+
@index.warn_if_similarity_small
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
describe 'raise_unless_similarity_ok' do
|
189
|
+
before(:each) do
|
190
|
+
@files = @index.files
|
191
|
+
end
|
192
|
+
context "files similarity cache ok" do
|
193
|
+
before(:each) do
|
194
|
+
@files.stub! :similarity_cache_ok? => true
|
195
|
+
end
|
196
|
+
it "warns" do
|
197
|
+
@index.should_receive(:raise_cache_missing).never
|
198
|
+
|
199
|
+
@index.raise_unless_similarity_ok
|
200
|
+
end
|
201
|
+
end
|
202
|
+
context "files similarity cache not ok" do
|
203
|
+
before(:each) do
|
204
|
+
@files.stub! :similarity_cache_ok? => false
|
138
205
|
end
|
139
|
-
it
|
140
|
-
|
141
|
-
|
142
|
-
|
206
|
+
it "does not warn" do
|
207
|
+
@index.should_receive(:raise_cache_missing).once.with :similarity
|
208
|
+
|
209
|
+
@index.raise_unless_similarity_ok
|
143
210
|
end
|
144
211
|
end
|
145
212
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 11
|
8
|
-
-
|
9
|
-
version: 0.11.
|
8
|
+
- 2
|
9
|
+
version: 0.11.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-10 00:00:00 +01:00
|
18
18
|
default_executable: picky
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: "0"
|
31
31
|
type: :development
|
32
32
|
version_requirements: *id001
|
33
|
-
description: Fast
|
33
|
+
description: Fast Ruby small-text search engine with comfortable single field interface.
|
34
34
|
email: florian.hanke+picky@gmail.com
|
35
35
|
executables:
|
36
36
|
- picky
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/picky/cacher/similarity/none.rb
|
58
58
|
- lib/picky/cacher/similarity/strategy.rb
|
59
59
|
- lib/picky/cacher/similarity_generator.rb
|
60
|
+
- lib/picky/cacher/strategy.rb
|
60
61
|
- lib/picky/cacher/weights/default.rb
|
61
62
|
- lib/picky/cacher/weights/logarithmic.rb
|
62
63
|
- lib/picky/cacher/weights/strategy.rb
|
@@ -159,6 +160,7 @@ files:
|
|
159
160
|
- project_prototype/unicorn.ru
|
160
161
|
- spec/ext/performant_spec.rb
|
161
162
|
- spec/lib/application_spec.rb
|
163
|
+
- spec/lib/cacher/cacher_strategy_spec.rb
|
162
164
|
- spec/lib/cacher/partial/default_spec.rb
|
163
165
|
- spec/lib/cacher/partial/none_spec.rb
|
164
166
|
- spec/lib/cacher/partial/subtoken_spec.rb
|
@@ -256,10 +258,11 @@ rubyforge_project: http://rubyforge.org/projects/picky
|
|
256
258
|
rubygems_version: 1.3.7
|
257
259
|
signing_key:
|
258
260
|
specification_version: 3
|
259
|
-
summary: Picky
|
261
|
+
summary: "Picky: Helps you find your data."
|
260
262
|
test_files:
|
261
263
|
- spec/ext/performant_spec.rb
|
262
264
|
- spec/lib/application_spec.rb
|
265
|
+
- spec/lib/cacher/cacher_strategy_spec.rb
|
263
266
|
- spec/lib/cacher/partial/default_spec.rb
|
264
267
|
- spec/lib/cacher/partial/none_spec.rb
|
265
268
|
- spec/lib/cacher/partial/subtoken_spec.rb
|