picky 4.6.3 → 4.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/performant.c +4 -4
- data/lib/picky/analyzer.rb +6 -3
- data/lib/picky/backends/backend.rb +40 -0
- data/lib/picky/backends/file/json.rb +4 -0
- data/lib/picky/backends/file.rb +1 -25
- data/lib/picky/backends/memory/json.rb +4 -0
- data/lib/picky/backends/memory.rb +1 -29
- data/lib/picky/backends/redis/directly_manipulable.rb +15 -7
- data/lib/picky/backends/redis.rb +91 -92
- data/lib/picky/backends/sqlite/basic.rb +6 -0
- data/lib/picky/bundle.rb +12 -10
- data/lib/picky/categories_indexing.rb +0 -13
- data/lib/picky/category.rb +24 -21
- data/lib/picky/category_indexing.rb +8 -22
- data/lib/picky/constants.rb +0 -1
- data/lib/picky/generators/aliases.rb +2 -0
- data/lib/picky/generators/partial.rb +27 -0
- data/lib/picky/generators/similarity.rb +27 -0
- data/lib/picky/generators/weights.rb +32 -0
- data/lib/picky/helpers/identification.rb +18 -0
- data/lib/picky/helpers/indexing.rb +16 -0
- data/lib/picky/index.rb +6 -0
- data/lib/picky/index_indexing.rb +9 -21
- data/lib/picky/indexes_indexing.rb +5 -14
- data/lib/picky/loader.rb +204 -199
- data/lib/picky/query/indexes.rb +12 -1
- data/lib/picky/search.rb +1 -0
- data/lib/picky/source.rb +23 -0
- data/lib/picky/tokenizer.rb +35 -13
- data/spec/functional/facets_spec.rb +1 -1
- data/spec/functional/remap_qualifiers_spec.rb +43 -0
- data/spec/functional/tokenizer_spec.rb +1 -1
- data/spec/lib/api/search/boost_spec.rb +1 -1
- data/spec/lib/category_spec.rb +1 -4
- data/spec/lib/generators/partial_spec.rb +58 -0
- data/spec/lib/generators/similarity_spec.rb +59 -0
- data/spec/lib/generators/weights_spec.rb +68 -0
- data/spec/lib/index_indexing_spec.rb +2 -4
- data/spec/lib/index_spec.rb +6 -0
- data/spec/lib/pool_spec.rb +39 -35
- data/spec/lib/sinatra_spec.rb +2 -2
- data/spec/lib/source_spec.rb +63 -0
- data/spec/lib/tokenizer_spec.rb +64 -2
- metadata +20 -20
- data/lib/picky/api/category/partial.rb +0 -26
- data/lib/picky/api/category/similarity.rb +0 -26
- data/lib/picky/api/category/weight.rb +0 -28
- data/lib/picky/api/source.rb +0 -35
- data/lib/picky/api/tokenizer.rb +0 -37
- data/lib/picky/deployment.rb +0 -211
- data/spec/lib/api/category/partial_spec.rb +0 -49
- data/spec/lib/api/category/similarity_spec.rb +0 -50
- data/spec/lib/api/category/weight_spec.rb +0 -55
- data/spec/lib/api/source_spec.rb +0 -68
- data/spec/lib/api/tokenizer_spec.rb +0 -42
@@ -0,0 +1,27 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
module Partial
|
6
|
+
extend Helpers::Identification
|
7
|
+
|
8
|
+
def self.from thing, index_name = nil, category_name = nil
|
9
|
+
return Default unless thing
|
10
|
+
|
11
|
+
if thing.respond_to? :each_partial
|
12
|
+
thing
|
13
|
+
else
|
14
|
+
raise <<-ERROR
|
15
|
+
partial options #{identifier_for(index_name, category_name)}should be either
|
16
|
+
* for example a Partial::Substring.new(from: m, to: n), Partial::Postfix.new(from: n), Partial::Infix.new(min: m, max: n) etc.
|
17
|
+
or
|
18
|
+
* an object that responds to #each_partial(str_or_sym) and yields each partial
|
19
|
+
ERROR
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
module Similarity
|
6
|
+
extend Helpers::Identification
|
7
|
+
|
8
|
+
def self.from thing, index_name = nil, category_name = nil
|
9
|
+
return Default unless thing
|
10
|
+
|
11
|
+
if thing.respond_to?(:encode) && thing.respond_to?(:prioritize)
|
12
|
+
thing
|
13
|
+
else
|
14
|
+
raise <<-ERROR
|
15
|
+
similarity options #{identifier_for(index_name, category_name)}should be either
|
16
|
+
* for example a Similarity::Phonetic.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
|
17
|
+
or
|
18
|
+
* an object that responds to #encode(text) => encoded_text and #prioritize(array_of_encoded, encoded)
|
19
|
+
ERROR
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
module Weights
|
6
|
+
extend Helpers::Identification
|
7
|
+
|
8
|
+
# Factory method to return a fitting
|
9
|
+
# weight handling thing for the given thing.
|
10
|
+
#
|
11
|
+
def self.from thing, index_name = nil, category_name = nil
|
12
|
+
return Default unless thing
|
13
|
+
|
14
|
+
if thing.respond_to? :weight_for
|
15
|
+
thing
|
16
|
+
elsif thing.respond_to? :to_int
|
17
|
+
Logarithmic.new thing
|
18
|
+
else
|
19
|
+
raise <<-ERROR
|
20
|
+
weight options #{identifier_for(index_name, category_name)}should be either
|
21
|
+
* for example a Weights::Logarithmic.new, Weights::Constant.new(int = 0), Weights::Dynamic.new(&block) etc.
|
22
|
+
or
|
23
|
+
* an object that responds to #weight_for(amount_of_ids_for_token) => float
|
24
|
+
ERROR
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
module Identification
|
6
|
+
|
7
|
+
def identifier_for index_name = nil, category_name = nil
|
8
|
+
specifics = ""
|
9
|
+
specifics << index_name.to_s if index_name
|
10
|
+
specifics << ":#{category_name}" if category_name
|
11
|
+
specifics = "for #{specifics} " unless specifics.empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -7,10 +7,26 @@ module Picky
|
|
7
7
|
|
8
8
|
include Measuring
|
9
9
|
|
10
|
+
# Runs the block and logs a few infos regarding the time it took.
|
11
|
+
#
|
10
12
|
def timed_indexing scheduler, &block
|
11
13
|
Picky.logger.info "Picky is indexing using #{scheduler.fork? ? 'multiple processes' : 'a single process'}: "
|
12
14
|
Picky.logger.info " Done in #{timed(&block).round}s.\n"
|
13
15
|
end
|
16
|
+
|
17
|
+
# Indexing works the same way, always:
|
18
|
+
# * Prepare the scheduler.
|
19
|
+
# * Cache the scheduler.
|
20
|
+
#
|
21
|
+
def index scheduler = Scheduler.new
|
22
|
+
timed_indexing scheduler do
|
23
|
+
prepare scheduler
|
24
|
+
scheduler.finish
|
25
|
+
|
26
|
+
cache scheduler
|
27
|
+
scheduler.finish
|
28
|
+
end
|
29
|
+
end
|
14
30
|
|
15
31
|
end
|
16
32
|
end
|
data/lib/picky/index.rb
CHANGED
@@ -178,6 +178,12 @@ module Picky
|
|
178
178
|
|
179
179
|
new_category
|
180
180
|
end
|
181
|
+
|
182
|
+
# The directory used by this index.
|
183
|
+
#
|
184
|
+
def directory
|
185
|
+
@directory ||= ::File.join(PICKY_ROOT, 'index', PICKY_ENVIRONMENT, name.to_s)
|
186
|
+
end
|
181
187
|
|
182
188
|
# Make this category range searchable with a fixed range. If you need other
|
183
189
|
# ranges, define another category with a different range value.
|
data/lib/picky/index_indexing.rb
CHANGED
@@ -3,10 +3,6 @@ module Picky
|
|
3
3
|
#
|
4
4
|
#
|
5
5
|
class Index
|
6
|
-
|
7
|
-
include API::Tokenizer
|
8
|
-
include API::Source
|
9
|
-
|
10
6
|
include Helpers::Indexing
|
11
7
|
|
12
8
|
# Delegators for indexing.
|
@@ -20,19 +16,7 @@ module Picky
|
|
20
16
|
# Parameters are the exact same as for indexing.
|
21
17
|
#
|
22
18
|
def indexing options = {}
|
23
|
-
@tokenizer =
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
def index scheduler = Scheduler.new
|
29
|
-
timed_indexing scheduler do
|
30
|
-
prepare scheduler
|
31
|
-
scheduler.finish
|
32
|
-
|
33
|
-
cache scheduler
|
34
|
-
scheduler.finish
|
35
|
-
end
|
19
|
+
@tokenizer = Tokenizer.from options
|
36
20
|
end
|
37
21
|
|
38
22
|
# Calling prepare on an index will call prepare
|
@@ -46,9 +30,7 @@ module Picky
|
|
46
30
|
check_source_empty
|
47
31
|
prepare_in_parallel scheduler
|
48
32
|
else
|
49
|
-
with_data_snapshot
|
50
|
-
categories.prepare scheduler
|
51
|
-
end
|
33
|
+
with_data_snapshot { categories.prepare scheduler }
|
52
34
|
end
|
53
35
|
end
|
54
36
|
|
@@ -98,7 +80,13 @@ module Picky
|
|
98
80
|
#
|
99
81
|
def source some_source = nil, &block
|
100
82
|
some_source ||= block
|
101
|
-
some_source ? (@source =
|
83
|
+
some_source ? (@source = Source.from(some_source, false, name)) : unblock_source
|
84
|
+
end
|
85
|
+
# Get the actual source if it is wrapped in a time
|
86
|
+
# capsule, i.e. a block/lambda.
|
87
|
+
#
|
88
|
+
def unblock_source
|
89
|
+
@source.respond_to?(:call) ? @source.call : @source
|
102
90
|
end
|
103
91
|
|
104
92
|
# Define a key_format on the index.
|
@@ -5,14 +5,17 @@ module Picky
|
|
5
5
|
class Indexes
|
6
6
|
|
7
7
|
extend Helpers::Indexing
|
8
|
+
include Helpers::Indexing
|
8
9
|
|
9
10
|
instance_delegate :clear,
|
10
11
|
:tokenizer
|
11
12
|
|
12
|
-
each_delegate :
|
13
|
+
each_delegate :cache,
|
14
|
+
:clear,
|
15
|
+
:prepare,
|
13
16
|
:to => :indexes
|
14
17
|
|
15
|
-
#
|
18
|
+
# Overrides index from the helper.
|
16
19
|
#
|
17
20
|
def self.index scheduler = Scheduler.new
|
18
21
|
timed_indexing scheduler do
|
@@ -20,18 +23,6 @@ module Picky
|
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
def index scheduler = Scheduler.new
|
26
|
-
indexes.each { |index| index.prepare scheduler }
|
27
|
-
scheduler.finish
|
28
|
-
|
29
|
-
# timed_exclaim "Tokenizing finished, generating data for indexes from tokenized data."
|
30
|
-
|
31
|
-
indexes.each { |index| index.cache scheduler }
|
32
|
-
scheduler.finish
|
33
|
-
end
|
34
|
-
|
35
26
|
#
|
36
27
|
#
|
37
28
|
def tokenizer
|