picky 4.12.1 → 4.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/backends/backend.rb +5 -3
- data/lib/picky/backends/file/basic.rb +1 -1
- data/lib/picky/backends/file/json.rb +1 -1
- data/lib/picky/backends/file.rb +5 -4
- data/lib/picky/backends/memory.rb +4 -4
- data/lib/picky/backends/prepared/text.rb +2 -0
- data/lib/picky/backends/redis.rb +1 -1
- data/lib/picky/bundle.rb +3 -3
- data/lib/picky/categories.rb +24 -14
- data/lib/picky/categories_convenience.rb +1 -2
- data/lib/picky/categories_indexed.rb +2 -4
- data/lib/picky/categories_indexing.rb +4 -4
- data/lib/picky/categories_realtime.rb +7 -7
- data/lib/picky/character_substituters/west_european.rb +1 -1
- data/lib/picky/extensions/class.rb +4 -4
- data/lib/picky/extensions/module.rb +29 -7
- data/lib/picky/index.rb +26 -25
- data/lib/picky/index_convenience.rb +1 -3
- data/lib/picky/index_indexed.rb +5 -5
- data/lib/picky/index_indexing.rb +2 -6
- data/lib/picky/index_realtime.rb +7 -7
- data/lib/picky/indexers/base.rb +2 -2
- data/lib/picky/indexes.rb +12 -17
- data/lib/picky/indexes_convenience.rb +1 -3
- data/lib/picky/indexes_indexed.rb +2 -5
- data/lib/picky/indexes_indexing.rb +2 -6
- data/lib/picky/loader.rb +1 -0
- data/lib/picky/query/allocation.rb +1 -1
- data/lib/picky/query/allocations.rb +7 -7
- data/lib/picky/query/boosts.rb +1 -2
- data/lib/picky/query/combinations.rb +3 -3
- data/lib/picky/query/indexes.rb +18 -18
- data/lib/picky/query/token.rb +1 -1
- data/lib/picky/query/tokens.rb +2 -2
- data/lib/picky/rack/harakiri.rb +1 -1
- data/lib/picky/results.rb +2 -2
- data/lib/picky/search.rb +5 -5
- data/lib/picky/search_facets.rb +3 -3
- data/lib/picky/sinatra.rb +1 -1
- data/lib/picky/tokenizer/regexp_wrapper.rb +19 -0
- data/lib/picky/tokenizer.rb +2 -13
- data/lib/picky/wrappers/bundle/delegators.rb +44 -44
- data/lib/picky/wrappers/bundle/wrapper.rb +1 -1
- data/lib/picky.rb +0 -2
- data/lib/tasks/server.rake +2 -1
- data/spec/functional/backends/redis_bundle_realtime_spec.rb +1 -1
- data/spec/functional/backends/sqlite_bundle_realtime_spec.rb +1 -1
- data/spec/functional/custom_delimiters_spec.rb +0 -2
- data/spec/functional/facets_spec.rb +1 -1
- data/spec/lib/backends/backend_spec.rb +1 -1
- data/spec/lib/backends/file/basic_spec.rb +1 -1
- data/spec/lib/backends/file_spec.rb +1 -1
- data/spec/lib/backends/memory/json_spec.rb +1 -1
- data/spec/lib/backends/memory/marshal_spec.rb +1 -1
- data/spec/lib/backends/redis/float_spec.rb +1 -1
- data/spec/lib/backends/redis/string_spec.rb +1 -1
- data/spec/lib/backends/sqlite/array_spec.rb +2 -2
- data/spec/lib/backends/sqlite/value_spec.rb +1 -1
- data/spec/lib/category_indexing_spec.rb +1 -1
- data/spec/lib/extensions/module_spec.rb +43 -6
- data/spec/lib/index_indexed_spec.rb +2 -2
- data/spec/lib/index_spec.rb +22 -1
- data/spec/lib/indexers/base_spec.rb +1 -1
- data/spec/lib/indexes_indexing_spec.rb +2 -2
- data/spec/lib/query/allocation_spec.rb +3 -3
- data/spec/lib/query/allocations_spec.rb +6 -6
- data/spec/lib/query/combinations_spec.rb +1 -1
- data/spec/lib/query/tokens_spec.rb +13 -13
- data/spec/lib/results_spec.rb +2 -2
- data/spec/lib/search_spec.rb +4 -4
- data/spec/lib/sinatra_spec.rb +2 -2
- metadata +5 -4
@@ -9,6 +9,8 @@ module Picky
|
|
9
9
|
# This is the default behaviour and should be overridden
|
10
10
|
# for different backends.
|
11
11
|
#
|
12
|
+
# TODO Push down.
|
13
|
+
#
|
12
14
|
|
13
15
|
# Returns an object that on #initial, #load returns
|
14
16
|
# an object that responds to:
|
@@ -21,9 +23,9 @@ module Picky
|
|
21
23
|
# an object that responds to:
|
22
24
|
# [:token] # => 1.23 (a weight)
|
23
25
|
#
|
24
|
-
def create_weights bundle
|
25
|
-
|
26
|
-
end
|
26
|
+
# def create_weights bundle
|
27
|
+
# json bundle.index_path(:weights)
|
28
|
+
# end
|
27
29
|
# # Returns an object that on #initial, #load returns
|
28
30
|
# # an object that responds to:
|
29
31
|
# # [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
|
@@ -27,7 +27,7 @@ module Picky
|
|
27
27
|
# This is the mapping file with the in-memory hash for the
|
28
28
|
# file position/offset mappings.
|
29
29
|
#
|
30
|
-
@mapping_file = Memory::JSON.new "#{cache_path}.file_mapping
|
30
|
+
@mapping_file = Memory::JSON.new "#{cache_path}.file_mapping"
|
31
31
|
|
32
32
|
@empty = options[:empty]
|
33
33
|
@initial = options[:initial]
|
data/lib/picky/backends/file.rb
CHANGED
@@ -9,10 +9,11 @@ module Picky
|
|
9
9
|
# ...[1,2,3,21,7,4,13,15]...
|
10
10
|
#
|
11
11
|
class File < Backend
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
def create_weights bundle
|
14
|
+
Memory::JSON.new bundle.index_path(:weights)
|
15
|
+
end
|
16
|
+
|
16
17
|
def create_similarity bundle
|
17
18
|
json bundle.index_path(:similarity)
|
18
19
|
end
|
@@ -4,10 +4,10 @@ module Picky
|
|
4
4
|
|
5
5
|
class Memory < Backend
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def create_weights bundle
|
8
|
+
JSON.new bundle.index_path(:weights)
|
9
|
+
end
|
10
|
+
|
11
11
|
def create_similarity bundle
|
12
12
|
Marshal.new bundle.index_path(:similarity)
|
13
13
|
end
|
data/lib/picky/backends/redis.rb
CHANGED
@@ -14,7 +14,7 @@ module Picky
|
|
14
14
|
check_hiredis_gem
|
15
15
|
check_redis_gem
|
16
16
|
|
17
|
-
@client
|
17
|
+
@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
|
18
18
|
@realtime = options[:realtime]
|
19
19
|
end
|
20
20
|
def maybe_load_hiredis
|
data/lib/picky/bundle.rb
CHANGED
@@ -41,8 +41,8 @@ module Picky
|
|
41
41
|
:partial_strategy,
|
42
42
|
:similarity_strategy
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
forward :[], :[]=, :to => :configuration
|
45
|
+
forward :index_directory, :to => :category
|
46
46
|
|
47
47
|
# TODO Move the strategies into options.
|
48
48
|
#
|
@@ -142,7 +142,7 @@ module Picky
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
# If a key format is set, use it, else
|
145
|
+
# If a key format is set, use it, else forward to the category.
|
146
146
|
#
|
147
147
|
def key_format
|
148
148
|
@key_format || @category.key_format
|
data/lib/picky/categories.rb
CHANGED
@@ -4,18 +4,18 @@ module Picky
|
|
4
4
|
|
5
5
|
attr_reader :categories, :category_hash
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
forward :each,
|
8
|
+
:first,
|
9
|
+
:map,
|
10
|
+
:to => :categories
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
each_forward :cache,
|
13
|
+
:dump,
|
14
|
+
:empty,
|
15
|
+
:inject,
|
16
|
+
:reindex,
|
17
|
+
:reset_backend,
|
18
|
+
:to => :categories
|
19
19
|
|
20
20
|
# A list of indexed categories.
|
21
21
|
#
|
@@ -37,14 +37,20 @@ module Picky
|
|
37
37
|
# To add the qualifiers to a search, you call this
|
38
38
|
# method.
|
39
39
|
#
|
40
|
-
def
|
41
|
-
@
|
40
|
+
def qualifier_mapper
|
41
|
+
@qualifier_mapper ||= QualifierMapper.new self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Resets the qualifier mapper used.
|
45
|
+
#
|
46
|
+
def reset_qualifier_mapper
|
47
|
+
@qualifier_mapper = nil
|
42
48
|
end
|
43
49
|
|
44
50
|
# Add the given category to the list of categories.
|
45
51
|
#
|
46
52
|
def << category
|
47
|
-
|
53
|
+
reset_qualifier_mapper # TODO Have an add method on QualifierMapper?
|
48
54
|
categories << category
|
49
55
|
category_hash[category.name] = category
|
50
56
|
end
|
@@ -58,6 +64,10 @@ module Picky
|
|
58
64
|
def raise_not_found category_name
|
59
65
|
raise %Q{Index category "#{category_name}" not found. Possible categories: "#{categories.map(&:name).join('", "')}".}
|
60
66
|
end
|
67
|
+
|
68
|
+
def to_stats
|
69
|
+
map(&:name).join(', ')
|
70
|
+
end
|
61
71
|
|
62
72
|
def to_s
|
63
73
|
"#{self.class}(#{categories.join(', ')})"
|
@@ -2,9 +2,7 @@ module Picky
|
|
2
2
|
|
3
3
|
class Categories
|
4
4
|
|
5
|
-
|
6
|
-
:analyze,
|
7
|
-
:to => :categories
|
5
|
+
each_forward :load, :analyze, :to => :categories
|
8
6
|
|
9
7
|
# Return all possible combinations for the given token.
|
10
8
|
#
|
@@ -64,7 +62,7 @@ module Picky
|
|
64
62
|
# TODO Called too often?
|
65
63
|
#
|
66
64
|
def possible_categories token
|
67
|
-
token.predefined_categories(
|
65
|
+
token.predefined_categories(qualifier_mapper) || categories
|
68
66
|
end
|
69
67
|
|
70
68
|
end
|
@@ -2,13 +2,13 @@ module Picky
|
|
2
2
|
|
3
3
|
class Categories
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
each_forward :remove,
|
6
|
+
:add,
|
7
|
+
:replace,
|
8
|
+
:replace_from,
|
9
|
+
:clear_realtime,
|
10
|
+
:build_realtime_mapping,
|
11
|
+
:to => :categories
|
12
12
|
|
13
13
|
end
|
14
14
|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
#
|
3
3
|
class Class
|
4
4
|
|
5
|
-
def
|
5
|
+
def instance_forward *method_names
|
6
6
|
method_names.each do |method_name|
|
7
|
-
module_eval(<<-
|
8
|
-
def self.#{method_name}(*args, &block)\n self.instance.#{method_name}(*args, &block)\nend
|
9
|
-
|
7
|
+
module_eval(<<-FORWARDING, "(__INSTANCE_FORWARDING__)", 1)
|
8
|
+
def self.#{method_name}(*args, &block)\n self.instance.#{method_name}(*args, &block)\nend\n
|
9
|
+
FORWARDING
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -1,15 +1,37 @@
|
|
1
1
|
# The original Module class.
|
2
2
|
#
|
3
3
|
class Module
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
|
5
|
+
def forward *methods
|
6
|
+
to = extract_to_from_options methods,
|
7
|
+
"Forwarding needs a target. Supply an options hash with a :to key as the last argument (e.g. forward :something, :to => :an_array_reader)."
|
8
|
+
forwarding methods do |method|
|
9
|
+
"def #{method}(*args, &block)\n#{to}.__send__(#{method.inspect}, *args, &block)\nend\n"
|
9
10
|
end
|
10
|
-
|
11
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
def each_forward *methods
|
14
|
+
to = extract_to_from_options methods,
|
15
|
+
"Multi forwarding needs a target. Supply an options hash with a :to key as the last argument (e.g. each_forward :something, :to => :an_array_reader)."
|
16
|
+
forwarding methods do |method|
|
17
|
+
"def #{method}(*args, &block)\n#{to}.each{ |t| t.__send__(#{method.inspect}, *args, &block) }\nend\n"
|
12
18
|
end
|
13
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def extract_to_from_options args, error_string
|
24
|
+
options = args.pop
|
25
|
+
unless options.is_a?(Hash) && to = options[:to]
|
26
|
+
raise ArgumentError, "Multi forwarding needs a target. Supply an options hash with a :to key as the last argument (e.g. each_forward :something, :to => :an_array_reader)."
|
27
|
+
end
|
28
|
+
to
|
29
|
+
end
|
30
|
+
|
31
|
+
def forwarding methods, &method_definition
|
32
|
+
methods.each do |method|
|
33
|
+
module_eval method_definition[method], "(__FORWARDING__)", 1
|
34
|
+
end
|
35
|
+
end
|
14
36
|
|
15
37
|
end
|
data/lib/picky/index.rb
CHANGED
@@ -89,12 +89,12 @@ module Picky
|
|
89
89
|
attr_reader :name,
|
90
90
|
:categories
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
forward :[],
|
93
|
+
:dump,
|
94
|
+
:each,
|
95
|
+
:inject,
|
96
|
+
:reset_backend,
|
97
|
+
:to => :categories
|
98
98
|
|
99
99
|
# Create a new index with a given source.
|
100
100
|
#
|
@@ -140,23 +140,23 @@ module Picky
|
|
140
140
|
@backend ||= Backends::Memory.new
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# Example:
|
147
|
-
# search = Search.new(index1, index2, index3) do
|
148
|
-
# ignore :name, :first_name
|
149
|
-
# end
|
150
|
-
#
|
151
|
-
# Cleans up / optimizes after being called.
|
152
|
-
#
|
153
|
-
# TODO This needs to move to the index.
|
143
|
+
|
144
|
+
# TODO Reinstate.
|
154
145
|
#
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
146
|
+
# # Ignore the categories with these qualifiers.
|
147
|
+
# #
|
148
|
+
# # Example:
|
149
|
+
# # search = Search.new(index1, index2, index3) do
|
150
|
+
# # ignore :name, :first_name
|
151
|
+
# # end
|
152
|
+
# #
|
153
|
+
# # Cleans up / optimizes after being called.
|
154
|
+
# #
|
155
|
+
# def ignore *qualifiers
|
156
|
+
# @ignored_categories ||= []
|
157
|
+
# @ignored_categories += qualifiers.map { |qualifier| @qualifier_mapper.map qualifier }.compact
|
158
|
+
# @ignored_categories.uniq!
|
159
|
+
# end
|
160
160
|
|
161
161
|
# SYMBOLS.
|
162
162
|
#
|
@@ -209,7 +209,7 @@ module Picky
|
|
209
209
|
#
|
210
210
|
def only *qualifiers
|
211
211
|
raise "Sorry, Picky::Search#only has been removed in version."
|
212
|
-
# @
|
212
|
+
# @qualifier_mapper.restrict_to *qualifiers
|
213
213
|
end
|
214
214
|
|
215
215
|
# The directory used by this index.
|
@@ -362,9 +362,10 @@ module Picky
|
|
362
362
|
stats = <<-INDEX
|
363
363
|
#{name} (#{self.class}):
|
364
364
|
#{"source: #{source}".indented_to_s}
|
365
|
-
#{"categories: #{categories.
|
365
|
+
#{"categories: #{categories.to_stats}".indented_to_s}
|
366
366
|
INDEX
|
367
|
-
stats << "
|
367
|
+
stats << "result identifier: \"#{result_identifier}\"".indented_to_s unless result_identifier.to_s == name.to_s
|
368
|
+
stats << "\n"
|
368
369
|
stats
|
369
370
|
end
|
370
371
|
|
data/lib/picky/index_indexed.rb
CHANGED
@@ -4,11 +4,11 @@ module Picky
|
|
4
4
|
#
|
5
5
|
class Index
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
forward :load,
|
8
|
+
:analyze,
|
9
|
+
:reindex,
|
10
|
+
:possible_combinations,
|
11
|
+
:to => :categories
|
12
12
|
|
13
13
|
# Define how the results of this index are identified.
|
14
14
|
# (Shown in the client, for example)
|
data/lib/picky/index_indexing.rb
CHANGED
@@ -5,11 +5,7 @@ module Picky
|
|
5
5
|
class Index
|
6
6
|
include Helpers::Indexing
|
7
7
|
|
8
|
-
|
9
|
-
#
|
10
|
-
delegate :cache,
|
11
|
-
:clear,
|
12
|
-
:to => :categories
|
8
|
+
forward :cache, :clear, :to => :categories
|
13
9
|
|
14
10
|
# Define an index tokenizer on the index.
|
15
11
|
#
|
@@ -23,7 +19,7 @@ module Picky
|
|
23
19
|
# on every category.
|
24
20
|
#
|
25
21
|
# Decides whether to use a parallel indexer or whether to
|
26
|
-
#
|
22
|
+
# forward to each category to prepare themselves.
|
27
23
|
#
|
28
24
|
def prepare scheduler = Scheduler.new
|
29
25
|
if source.respond_to?(:each)
|
data/lib/picky/index_realtime.rb
CHANGED
@@ -4,13 +4,13 @@ module Picky
|
|
4
4
|
#
|
5
5
|
class Index
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
forward :remove, # aka "delete".
|
8
|
+
:add, # aka "insert".
|
9
|
+
:replace, # aka "insert or update". Thus, not called update.
|
10
|
+
:replace_from,
|
11
|
+
:clear_realtime,
|
12
|
+
:build_realtime_mapping,
|
13
|
+
:to => :categories
|
14
14
|
|
15
15
|
# Add at the end.
|
16
16
|
#
|
data/lib/picky/indexers/base.rb
CHANGED
data/lib/picky/indexes.rb
CHANGED
@@ -3,7 +3,7 @@ module Picky
|
|
3
3
|
# Holds all indexes and provides operations
|
4
4
|
# for extracting and working on them.
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# Forwards a number of operations to the
|
7
7
|
# indexes.
|
8
8
|
#
|
9
9
|
class Indexes
|
@@ -11,12 +11,17 @@ module Picky
|
|
11
11
|
attr_reader :indexes,
|
12
12
|
:index_mapping
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
forward :size, :each, :to => :indexes
|
15
|
+
each_forward :reindex, :to => :indexes
|
16
|
+
instance_forward :clear,
|
17
|
+
:clear_indexes,
|
18
|
+
:register,
|
19
|
+
:reindex,
|
20
|
+
:[],
|
21
|
+
:to_s,
|
22
|
+
:size,
|
23
|
+
:each,
|
24
|
+
:each_category
|
20
25
|
|
21
26
|
def initialize *indexes
|
22
27
|
clear_indexes
|
@@ -32,16 +37,6 @@ module Picky
|
|
32
37
|
name
|
33
38
|
end
|
34
39
|
|
35
|
-
instance_delegate :clear,
|
36
|
-
:clear_indexes,
|
37
|
-
:register,
|
38
|
-
:reindex,
|
39
|
-
:[],
|
40
|
-
:to_s,
|
41
|
-
:size,
|
42
|
-
:each,
|
43
|
-
:each_category
|
44
|
-
|
45
40
|
# Clears the indexes and the mapping.
|
46
41
|
#
|
47
42
|
def clear_indexes
|
@@ -7,13 +7,9 @@ module Picky
|
|
7
7
|
extend Helpers::Indexing
|
8
8
|
include Helpers::Indexing
|
9
9
|
|
10
|
-
|
11
|
-
:tokenizer
|
10
|
+
instance_forward :clear, :tokenizer
|
12
11
|
|
13
|
-
|
14
|
-
:clear,
|
15
|
-
:prepare,
|
16
|
-
:to => :indexes
|
12
|
+
each_forward :cache, :clear, :prepare, :to => :indexes
|
17
13
|
|
18
14
|
# Overrides index from the helper.
|
19
15
|
#
|
data/lib/picky/loader.rb
CHANGED
@@ -265,6 +265,7 @@ module Picky
|
|
265
265
|
load_api
|
266
266
|
load_logging
|
267
267
|
load_relative 'source'
|
268
|
+
load_relative 'tokenizer/regexp_wrapper'
|
268
269
|
load_relative 'tokenizer'
|
269
270
|
# load_relative 'rack/harakiri' # Needs to be explicitly loaded/required.
|
270
271
|
load_relative 'character_substituters/west_european'
|
@@ -14,13 +14,13 @@ module Picky
|
|
14
14
|
#
|
15
15
|
class Allocations
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
forward :each,
|
18
|
+
:empty?,
|
19
|
+
:first,
|
20
|
+
:inject,
|
21
|
+
:size,
|
22
|
+
:map,
|
23
|
+
:to => :@allocations
|
24
24
|
|
25
25
|
def initialize allocations = []
|
26
26
|
@allocations = allocations
|
data/lib/picky/query/boosts.rb
CHANGED