picky 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/index/base.rb +12 -0
- data/lib/picky/internals/indexers/base.rb +0 -8
- data/lib/picky/internals/indexing/bundle/base.rb +1 -1
- data/lib/picky/internals/indexing/category.rb +17 -6
- data/lib/picky/internals/indexing/index.rb +10 -0
- data/spec/lib/internals/indexers/base_spec.rb +16 -0
- data/spec/lib/internals/indexers/serial_spec.rb +0 -19
- data/spec/lib/internals/indexing/category_spec.rb +44 -1
- metadata +5 -3
data/lib/picky/index/base.rb
CHANGED
@@ -21,6 +21,7 @@ module Index
|
|
21
21
|
# * result_identifier: Use if you'd like a different identifier/name in the results than the name of the index.
|
22
22
|
# * after_indexing: As of this writing only used in the db source. Executes the given after_indexing as SQL after the indexing process.
|
23
23
|
# * tokenizer: The tokenizer to use for this index. Optional, can be defined in the block using #indexing.
|
24
|
+
# * key_format: The format the ids of this index are in. Optional, can be defined in the block using #key_format.
|
24
25
|
#
|
25
26
|
# Examples:
|
26
27
|
# my_index = Index::Memory.new(:my_index, source: some_source) do
|
@@ -139,6 +140,17 @@ INDEX
|
|
139
140
|
end
|
140
141
|
alias define_source source
|
141
142
|
|
143
|
+
# Define a key_format on the index.
|
144
|
+
#
|
145
|
+
# Parameter is a source, either one of the standard sources or
|
146
|
+
# anything responding to #each and returning objects that
|
147
|
+
# respond to id and the category names (or the category from option).
|
148
|
+
#
|
149
|
+
def key_format key_format
|
150
|
+
internal_indexing.define_key_format key_format
|
151
|
+
end
|
152
|
+
alias define_key_format key_format
|
153
|
+
|
142
154
|
# Defines a searchable category on the index.
|
143
155
|
#
|
144
156
|
# === Parameters
|
@@ -80,7 +80,7 @@ module Internals
|
|
80
80
|
key_format = self[:key_format] || :to_i
|
81
81
|
files.retrieve do |id, token|
|
82
82
|
initialize_index_for token
|
83
|
-
index[token] << id.send(key_format)
|
83
|
+
index[token] << id.send(key_format)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -21,14 +21,16 @@ module Internals
|
|
21
21
|
# * source: Use if the category should use a different source.
|
22
22
|
# * weights: Query::Weights.new( [:category1, :category2] => +2, ... )
|
23
23
|
# * tokenizer: Use a subclass of Tokenizers::Base that implements #tokens_for and #empty_tokens.
|
24
|
+
# * key_format: What this category's keys are formatted with (default is :to_i)
|
24
25
|
#
|
25
26
|
def initialize name, index, options = {}
|
26
27
|
@name = name
|
27
28
|
@index = index
|
28
29
|
|
29
|
-
@source
|
30
|
-
@from
|
31
|
-
@tokenizer
|
30
|
+
@source = options[:source]
|
31
|
+
@from = options[:from]
|
32
|
+
@tokenizer = options[:tokenizer]
|
33
|
+
@key_format = options[:key_format]
|
32
34
|
|
33
35
|
# TODO Push into Bundle. At least the weights.
|
34
36
|
#
|
@@ -46,6 +48,16 @@ module Internals
|
|
46
48
|
def source
|
47
49
|
@source || @index.source
|
48
50
|
end
|
51
|
+
# Return the key format.
|
52
|
+
#
|
53
|
+
# If the source has no key format, then
|
54
|
+
# check for an explicit key format, and
|
55
|
+
# if none is defined, ask the index for
|
56
|
+
# one.
|
57
|
+
#
|
58
|
+
def key_format
|
59
|
+
source.respond_to?(:key_format) && source.key_format || @key_format || index.key_format
|
60
|
+
end
|
49
61
|
# The indexer is lazily generated and cached.
|
50
62
|
#
|
51
63
|
def indexer
|
@@ -102,9 +114,8 @@ module Internals
|
|
102
114
|
# Uses the one defined in the indexer.
|
103
115
|
#
|
104
116
|
def configure
|
105
|
-
key_format =
|
106
|
-
|
107
|
-
partial[:key_format] = key_format
|
117
|
+
exact[:key_format] = self.key_format
|
118
|
+
partial[:key_format] = self.key_format
|
108
119
|
end
|
109
120
|
def generate_caches
|
110
121
|
generate_caches_from_source
|
@@ -28,6 +28,7 @@ module Internals
|
|
28
28
|
@after_indexing = options[:after_indexing]
|
29
29
|
@bundle_class = options[:indexing_bundle_class] # TODO This should actually be a fixed parameter.
|
30
30
|
@tokenizer = options[:tokenizer]
|
31
|
+
@key_format = options[:key_format]
|
31
32
|
|
32
33
|
@categories = []
|
33
34
|
end
|
@@ -71,6 +72,15 @@ Example:
|
|
71
72
|
)
|
72
73
|
end
|
73
74
|
|
75
|
+
#
|
76
|
+
#
|
77
|
+
def define_key_format key_format
|
78
|
+
@key_format = key_format
|
79
|
+
end
|
80
|
+
def key_format
|
81
|
+
@key_format || :to_i
|
82
|
+
end
|
83
|
+
|
74
84
|
#
|
75
85
|
#
|
76
86
|
def find category_name
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Indexers::Base do
|
4
|
+
|
5
|
+
let(:indexer) { described_class.new }
|
6
|
+
|
7
|
+
describe 'index' do
|
8
|
+
it 'messages, then processed' do
|
9
|
+
indexer.should_receive(:indexing_message).once.with.ordered
|
10
|
+
indexer.should_receive(:process).once.with.ordered
|
11
|
+
|
12
|
+
indexer.index
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -11,25 +11,6 @@ describe Indexers::Serial do
|
|
11
11
|
@indexer.stub! :timed_exclaim
|
12
12
|
end
|
13
13
|
|
14
|
-
describe 'key_format' do
|
15
|
-
context 'source has key_format' do
|
16
|
-
before(:each) do
|
17
|
-
@source.stub! :key_format => :some_key_format
|
18
|
-
end
|
19
|
-
it 'returns what the source returns' do
|
20
|
-
@indexer.key_format.should == :some_key_format
|
21
|
-
end
|
22
|
-
end
|
23
|
-
context 'source does not have key_format' do
|
24
|
-
before(:each) do
|
25
|
-
@source.stub! :key_format => nil
|
26
|
-
end
|
27
|
-
it 'returns :to_i' do
|
28
|
-
@indexer.key_format.should == :to_i
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
14
|
describe "tokenizer" do
|
34
15
|
it "returns the right one" do
|
35
16
|
@indexer.tokenizer.should == @tokenizer
|
@@ -106,6 +106,43 @@ describe Internals::Indexing::Category do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
describe 'key_format' do
|
110
|
+
context 'source has key_format' do
|
111
|
+
before(:each) do
|
112
|
+
category.stub! :source => stub(:source, :key_format => :some_key_format)
|
113
|
+
end
|
114
|
+
it 'returns that key_format' do
|
115
|
+
category.key_format.should == :some_key_format
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context 'source does not have key_format' do
|
119
|
+
before(:each) do
|
120
|
+
category.stub! :source => stub(:source)
|
121
|
+
end
|
122
|
+
context 'category has its own key_format' do
|
123
|
+
before(:each) do
|
124
|
+
category.instance_variable_set :@key_format, :other_key_format
|
125
|
+
end
|
126
|
+
it 'returns that key_format' do
|
127
|
+
category.key_format.should == :other_key_format
|
128
|
+
end
|
129
|
+
end
|
130
|
+
context 'category does not have its own key format' do
|
131
|
+
before(:each) do
|
132
|
+
category.instance_variable_set :@key_format, nil
|
133
|
+
end
|
134
|
+
context 'it has an index' do
|
135
|
+
before(:each) do
|
136
|
+
category.stub! :index => stub(:index, :key_format => :yet_another_key_format)
|
137
|
+
end
|
138
|
+
it 'returns that key_format' do
|
139
|
+
category.key_format.should == :yet_another_key_format
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
109
146
|
describe 'source' do
|
110
147
|
context 'with explicit source' do
|
111
148
|
let(:category) { described_class.new(:some_category, @index, :source => :category_source) }
|
@@ -121,15 +158,21 @@ describe Internals::Indexing::Category do
|
|
121
158
|
end
|
122
159
|
end
|
123
160
|
|
124
|
-
describe "cache" do
|
161
|
+
describe "cache!" do
|
125
162
|
before(:each) do
|
126
163
|
category.stub! :generate_caches
|
164
|
+
category.stub! :configure
|
127
165
|
end
|
128
166
|
it "prepares the cache directory" do
|
129
167
|
category.should_receive(:prepare_index_directory).once.with
|
130
168
|
|
131
169
|
category.cache!
|
132
170
|
end
|
171
|
+
it "configures" do
|
172
|
+
category.should_receive(:configure).once.with
|
173
|
+
|
174
|
+
category.cache!
|
175
|
+
end
|
133
176
|
it "tells the indexer to index" do
|
134
177
|
category.should_receive(:generate_caches).once.with
|
135
178
|
|
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.4.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-20 00:00:00 +10:00
|
14
14
|
default_executable: picky
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - "="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.
|
35
|
+
version: 2.4.0
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id002
|
38
38
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb
|
234
234
|
- spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb
|
235
235
|
- spec/lib/internals/indexed/wrappers/exact_first_spec.rb
|
236
|
+
- spec/lib/internals/indexers/base_spec.rb
|
236
237
|
- spec/lib/internals/indexers/parallel_spec.rb
|
237
238
|
- spec/lib/internals/indexers/serial_spec.rb
|
238
239
|
- spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb
|
@@ -357,6 +358,7 @@ test_files:
|
|
357
358
|
- spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb
|
358
359
|
- spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb
|
359
360
|
- spec/lib/internals/indexed/wrappers/exact_first_spec.rb
|
361
|
+
- spec/lib/internals/indexers/base_spec.rb
|
360
362
|
- spec/lib/internals/indexers/parallel_spec.rb
|
361
363
|
- spec/lib/internals/indexers/serial_spec.rb
|
362
364
|
- spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb
|