picky 2.5.2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/adapters/rack/base.rb +23 -0
- data/lib/picky/adapters/rack/live_parameters.rb +33 -0
- data/lib/picky/adapters/rack/query.rb +65 -0
- data/lib/picky/adapters/rack.rb +30 -0
- data/lib/picky/application.rb +5 -5
- data/lib/picky/backend/backend.rb +108 -0
- data/lib/picky/backend/file/basic.rb +101 -0
- data/lib/picky/backend/file/json.rb +34 -0
- data/lib/picky/backend/file/marshal.rb +34 -0
- data/lib/picky/backend/file/text.rb +56 -0
- data/lib/picky/backend/files.rb +30 -0
- data/lib/picky/backend/redis/basic.rb +85 -0
- data/lib/picky/backend/redis/list_hash.rb +49 -0
- data/lib/picky/backend/redis/string_hash.rb +40 -0
- data/lib/picky/backend/redis.rb +40 -0
- data/lib/picky/calculations/location.rb +57 -0
- data/lib/picky/categories.rb +62 -0
- data/lib/picky/categories_indexed.rb +93 -0
- data/lib/picky/categories_indexing.rb +12 -0
- data/lib/picky/category.rb +127 -0
- data/lib/picky/category_indexed.rb +64 -0
- data/lib/picky/category_indexing.rb +145 -0
- data/lib/picky/{internals/ext → ext}/maybe_compile.rb +0 -0
- data/lib/picky/{internals/ext → ext}/ruby19/extconf.rb +0 -0
- data/lib/picky/{internals/ext → ext}/ruby19/performant.c +0 -0
- data/lib/picky/{internals/extensions → extensions}/array.rb +0 -0
- data/lib/picky/extensions/class.rb +11 -0
- data/lib/picky/{internals/extensions → extensions}/hash.rb +0 -0
- data/lib/picky/{internals/extensions → extensions}/module.rb +0 -0
- data/lib/picky/{internals/extensions → extensions}/object.rb +0 -0
- data/lib/picky/{internals/extensions → extensions}/symbol.rb +0 -0
- data/lib/picky/frontend_adapters/rack.rb +146 -0
- data/lib/picky/generators/aliases.rb +3 -3
- data/lib/picky/generators/base.rb +15 -0
- data/lib/picky/generators/partial/default.rb +5 -0
- data/lib/picky/generators/partial/none.rb +31 -0
- data/lib/picky/generators/partial/strategy.rb +25 -0
- data/lib/picky/generators/partial/substring.rb +118 -0
- data/lib/picky/generators/partial_generator.rb +15 -0
- data/lib/picky/generators/similarity/default.rb +7 -0
- data/lib/picky/generators/similarity/double_metaphone.rb +28 -0
- data/lib/picky/generators/similarity/metaphone.rb +28 -0
- data/lib/picky/generators/similarity/none.rb +31 -0
- data/lib/picky/generators/similarity/phonetic.rb +65 -0
- data/lib/picky/generators/similarity/soundex.rb +28 -0
- data/lib/picky/generators/similarity/strategy.rb +9 -0
- data/lib/picky/generators/similarity_generator.rb +15 -0
- data/lib/picky/generators/strategy.rb +14 -0
- data/lib/picky/generators/weights/default.rb +7 -0
- data/lib/picky/generators/weights/logarithmic.rb +39 -0
- data/lib/picky/generators/weights/strategy.rb +9 -0
- data/lib/picky/generators/weights_generator.rb +15 -0
- data/lib/picky/{internals/helpers → helpers}/measuring.rb +0 -0
- data/lib/picky/index/base.rb +119 -104
- data/lib/picky/index/base_indexed.rb +27 -0
- data/lib/picky/index/base_indexing.rb +119 -0
- data/lib/picky/index/memory.rb +6 -18
- data/lib/picky/index/redis.rb +6 -18
- data/lib/picky/indexed/bundle/base.rb +110 -0
- data/lib/picky/indexed/bundle/memory.rb +91 -0
- data/lib/picky/indexed/bundle/redis.rb +45 -0
- data/lib/picky/indexed/wrappers/bundle/calculation.rb +35 -0
- data/lib/picky/indexed/wrappers/bundle/location.rb +42 -0
- data/lib/picky/indexed/wrappers/bundle/wrapper.rb +43 -0
- data/lib/picky/indexed/wrappers/category/location.rb +25 -0
- data/lib/picky/indexed/wrappers/exact_first.rb +55 -0
- data/lib/picky/{internals/indexers → indexers}/base.rb +0 -0
- data/lib/picky/{internals/indexers → indexers}/parallel.rb +0 -0
- data/lib/picky/{internals/indexers → indexers}/serial.rb +0 -0
- data/lib/picky/{internals/indexers → indexers}/solr.rb +0 -0
- data/lib/picky/indexes.rb +73 -0
- data/lib/picky/indexes_indexed.rb +29 -0
- data/lib/picky/indexes_indexing.rb +49 -0
- data/lib/picky/indexing/bundle/base.rb +212 -0
- data/lib/picky/indexing/bundle/memory.rb +25 -0
- data/lib/picky/indexing/bundle/redis.rb +24 -0
- data/lib/picky/indexing/bundle/super_base.rb +61 -0
- data/lib/picky/indexing/wrappers/category/location.rb +25 -0
- data/lib/picky/interfaces/live_parameters.rb +8 -8
- data/lib/picky/loader.rb +89 -95
- data/lib/picky/{internals/performant.rb → performant.rb} +0 -0
- data/lib/picky/query/allocation.rb +84 -0
- data/lib/picky/query/allocations.rb +114 -0
- data/lib/picky/query/combination.rb +76 -0
- data/lib/picky/query/combinations/base.rb +70 -0
- data/lib/picky/query/combinations/memory.rb +48 -0
- data/lib/picky/query/combinations/redis.rb +86 -0
- data/lib/picky/query/indexes.rb +195 -0
- data/lib/picky/query/qualifiers.rb +76 -0
- data/lib/picky/query/token.rb +198 -0
- data/lib/picky/query/tokens.rb +103 -0
- data/lib/picky/{internals/query → query}/weights.rb +0 -0
- data/lib/picky/results.rb +1 -1
- data/lib/picky/search.rb +6 -6
- data/lib/picky/{internals/solr → solr}/schema_generator.rb +0 -0
- data/lib/picky/sources/db.rb +7 -7
- data/lib/picky/sources/wrappers/location.rb +2 -2
- data/lib/picky/tokenizers/base.rb +224 -0
- data/lib/picky/tokenizers/index.rb +30 -0
- data/lib/picky/tokenizers/location.rb +49 -0
- data/lib/picky/tokenizers/query.rb +55 -0
- data/lib/tasks/index.rake +4 -3
- data/lib/tasks/try.rake +2 -2
- data/spec/lib/{internals/adapters → adapters}/rack/base_spec.rb +1 -1
- data/spec/lib/{internals/adapters → adapters}/rack/live_parameters_spec.rb +1 -1
- data/spec/lib/{internals/adapters → adapters}/rack/query_spec.rb +1 -1
- data/spec/lib/application_spec.rb +3 -3
- data/spec/lib/{internals/index → backend}/file/basic_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/file/json_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/file/marshal_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/file/text_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/files_spec.rb +3 -3
- data/spec/lib/{internals/index → backend}/redis/basic_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/redis/list_hash_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/redis/string_hash_spec.rb +1 -1
- data/spec/lib/{internals/index → backend}/redis_spec.rb +11 -5
- data/spec/lib/{internals/calculations → calculations}/location_spec.rb +1 -1
- data/spec/lib/{internals/indexed/categories_spec.rb → categories_indexed_spec.rb} +10 -10
- data/spec/lib/{internals/indexed/category_spec.rb → category_indexed_spec.rb} +12 -12
- data/spec/lib/{internals/indexing/category_spec.rb → category_indexing_spec.rb} +10 -10
- data/spec/lib/{internals/cores_spec.rb → cores_spec.rb} +0 -0
- data/spec/lib/{internals/extensions → extensions}/array_spec.rb +0 -0
- data/spec/lib/{internals/extensions → extensions}/hash_spec.rb +0 -0
- data/spec/lib/{internals/extensions → extensions}/module_spec.rb +0 -0
- data/spec/lib/{internals/extensions → extensions}/object_spec.rb +0 -0
- data/spec/lib/{internals/extensions → extensions}/symbol_spec.rb +0 -0
- data/spec/lib/{internals/frontend_adapters → frontend_adapters}/rack_spec.rb +10 -10
- data/spec/lib/generators/aliases_spec.rb +3 -3
- data/spec/lib/{internals/generators → generators}/cacher_strategy_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/partial/default_spec.rb +3 -3
- data/spec/lib/{internals/generators → generators}/partial/none_spec.rb +2 -2
- data/spec/lib/{internals/generators → generators}/partial/substring_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/partial_generator_spec.rb +3 -3
- data/spec/lib/{internals/generators → generators}/similarity/double_metaphone_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/similarity/metaphone_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/similarity/none_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/similarity/phonetic_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/similarity/soundex_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/similarity_generator_spec.rb +2 -2
- data/spec/lib/{internals/generators → generators}/weights/logarithmic_spec.rb +1 -1
- data/spec/lib/{internals/generators → generators}/weights_generator_spec.rb +5 -5
- data/spec/lib/{internals/helpers → helpers}/measuring_spec.rb +0 -0
- data/spec/lib/{internals/indexed/index_spec.rb → index/base_indexed_spec.rb} +5 -5
- data/spec/lib/{internals/indexing/index_spec.rb → index/base_indexing_spec.rb} +6 -19
- data/spec/lib/index/base_spec.rb +10 -53
- data/spec/lib/{internals/indexed → indexed}/bundle/memory_spec.rb +5 -5
- data/spec/lib/{internals/indexed → indexed}/bundle/redis_spec.rb +4 -4
- data/spec/lib/{internals/indexed → indexed}/wrappers/bundle/calculation_spec.rb +1 -1
- data/spec/lib/{internals/indexed → indexed}/wrappers/bundle/wrapper_spec.rb +1 -1
- data/spec/lib/{internals/indexed → indexed}/wrappers/exact_first_spec.rb +7 -7
- data/spec/lib/{internals/indexers → indexers}/base_spec.rb +0 -0
- data/spec/lib/{internals/indexers → indexers}/parallel_spec.rb +0 -0
- data/spec/lib/{internals/indexers → indexers}/serial_spec.rb +0 -0
- data/spec/lib/indexes_class_spec.rb +30 -0
- data/spec/lib/{indexed/indexes_spec.rb → indexes_indexed_spec.rb} +1 -1
- data/spec/lib/{indexing/indexes_spec.rb → indexes_indexing_spec.rb} +8 -8
- data/spec/lib/{internals/indexing/indexes_spec.rb → indexes_spec.rb} +15 -12
- data/spec/lib/{internals/indexing → indexing}/bundle/memory_partial_generation_speed_spec.rb +4 -4
- data/spec/lib/{internals/indexing → indexing}/bundle/memory_spec.rb +3 -3
- data/spec/lib/{internals/indexing → indexing}/bundle/redis_spec.rb +3 -3
- data/spec/lib/{internals/indexing → indexing}/bundle/super_base_spec.rb +2 -2
- data/spec/lib/{internals/interfaces → interfaces}/live_parameters_spec.rb +0 -0
- data/spec/lib/query/allocation_spec.rb +1 -1
- data/spec/lib/query/allocations_spec.rb +1 -1
- data/spec/lib/query/combination_spec.rb +5 -5
- data/spec/lib/query/combinations/base_spec.rb +1 -1
- data/spec/lib/query/combinations/memory_spec.rb +1 -1
- data/spec/lib/query/combinations/redis_spec.rb +1 -1
- data/spec/lib/query/indexes_spec.rb +1 -1
- data/spec/lib/query/qualifiers_spec.rb +4 -4
- data/spec/lib/query/token_spec.rb +3 -3
- data/spec/lib/query/tokens_spec.rb +32 -32
- data/spec/lib/search_spec.rb +5 -5
- data/spec/lib/{internals/solr → solr}/schema_generator_spec.rb +0 -0
- data/spec/lib/sources/db_spec.rb +4 -8
- data/spec/lib/sources/wrappers/location_spec.rb +1 -1
- data/spec/lib/{internals/tokenizers → tokenizers}/base_spec.rb +1 -1
- data/spec/lib/{internals/tokenizers → tokenizers}/index_spec.rb +1 -1
- data/spec/lib/{internals/tokenizers → tokenizers}/query_spec.rb +1 -1
- metadata +214 -215
- data/lib/picky/aliases.rb +0 -4
- data/lib/picky/index_bundle.rb +0 -48
- data/lib/picky/indexed/indexes.rb +0 -59
- data/lib/picky/indexing/indexes.rb +0 -87
- data/lib/picky/internals/adapters/rack/base.rb +0 -27
- data/lib/picky/internals/adapters/rack/live_parameters.rb +0 -37
- data/lib/picky/internals/adapters/rack/query.rb +0 -69
- data/lib/picky/internals/adapters/rack.rb +0 -34
- data/lib/picky/internals/calculations/location.rb +0 -59
- data/lib/picky/internals/frontend_adapters/rack.rb +0 -150
- data/lib/picky/internals/generators/base.rb +0 -19
- data/lib/picky/internals/generators/partial/default.rb +0 -7
- data/lib/picky/internals/generators/partial/none.rb +0 -35
- data/lib/picky/internals/generators/partial/strategy.rb +0 -29
- data/lib/picky/internals/generators/partial/substring.rb +0 -122
- data/lib/picky/internals/generators/partial_generator.rb +0 -19
- data/lib/picky/internals/generators/similarity/default.rb +0 -9
- data/lib/picky/internals/generators/similarity/double_metaphone.rb +0 -32
- data/lib/picky/internals/generators/similarity/metaphone.rb +0 -32
- data/lib/picky/internals/generators/similarity/none.rb +0 -35
- data/lib/picky/internals/generators/similarity/phonetic.rb +0 -69
- data/lib/picky/internals/generators/similarity/soundex.rb +0 -32
- data/lib/picky/internals/generators/similarity/strategy.rb +0 -11
- data/lib/picky/internals/generators/similarity_generator.rb +0 -19
- data/lib/picky/internals/generators/strategy.rb +0 -18
- data/lib/picky/internals/generators/weights/default.rb +0 -9
- data/lib/picky/internals/generators/weights/logarithmic.rb +0 -43
- data/lib/picky/internals/generators/weights/strategy.rb +0 -11
- data/lib/picky/internals/generators/weights_generator.rb +0 -19
- data/lib/picky/internals/index/backend.rb +0 -112
- data/lib/picky/internals/index/file/basic.rb +0 -105
- data/lib/picky/internals/index/file/json.rb +0 -38
- data/lib/picky/internals/index/file/marshal.rb +0 -38
- data/lib/picky/internals/index/file/text.rb +0 -60
- data/lib/picky/internals/index/files.rb +0 -34
- data/lib/picky/internals/index/redis/basic.rb +0 -89
- data/lib/picky/internals/index/redis/list_hash.rb +0 -53
- data/lib/picky/internals/index/redis/string_hash.rb +0 -44
- data/lib/picky/internals/index/redis.rb +0 -44
- data/lib/picky/internals/indexed/bundle/base.rb +0 -114
- data/lib/picky/internals/indexed/bundle/memory.rb +0 -95
- data/lib/picky/internals/indexed/bundle/redis.rb +0 -49
- data/lib/picky/internals/indexed/categories.rb +0 -140
- data/lib/picky/internals/indexed/category.rb +0 -111
- data/lib/picky/internals/indexed/index.rb +0 -63
- data/lib/picky/internals/indexed/wrappers/bundle/calculation.rb +0 -37
- data/lib/picky/internals/indexed/wrappers/bundle/location.rb +0 -44
- data/lib/picky/internals/indexed/wrappers/bundle/wrapper.rb +0 -45
- data/lib/picky/internals/indexed/wrappers/category/location.rb +0 -27
- data/lib/picky/internals/indexed/wrappers/exact_first.rb +0 -59
- data/lib/picky/internals/indexing/bundle/base.rb +0 -216
- data/lib/picky/internals/indexing/bundle/memory.rb +0 -29
- data/lib/picky/internals/indexing/bundle/redis.rb +0 -28
- data/lib/picky/internals/indexing/bundle/super_base.rb +0 -65
- data/lib/picky/internals/indexing/category.rb +0 -153
- data/lib/picky/internals/indexing/index.rb +0 -142
- data/lib/picky/internals/indexing/wrappers/category/location.rb +0 -27
- data/lib/picky/internals/query/allocation.rb +0 -88
- data/lib/picky/internals/query/allocations.rb +0 -118
- data/lib/picky/internals/query/combination.rb +0 -80
- data/lib/picky/internals/query/combinations/base.rb +0 -74
- data/lib/picky/internals/query/combinations/memory.rb +0 -52
- data/lib/picky/internals/query/combinations/redis.rb +0 -90
- data/lib/picky/internals/query/indexes.rb +0 -199
- data/lib/picky/internals/query/qualifiers.rb +0 -82
- data/lib/picky/internals/query/token.rb +0 -202
- data/lib/picky/internals/query/tokens.rb +0 -109
- data/lib/picky/internals/shared/category.rb +0 -52
- data/lib/picky/internals/tokenizers/base.rb +0 -228
- data/lib/picky/internals/tokenizers/index.rb +0 -34
- data/lib/picky/internals/tokenizers/location.rb +0 -54
- data/lib/picky/internals/tokenizers/query.rb +0 -59
- data/lib/picky/internals.rb +0 -2
- data/spec/lib/aliases_spec.rb +0 -9
- data/spec/lib/index_bundle_spec.rb +0 -69
@@ -1,111 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
|
3
|
-
module Indexed
|
4
|
-
|
5
|
-
# An index category holds a exact and a partial index for a given category.
|
6
|
-
#
|
7
|
-
# For example an index category for names holds a exact and
|
8
|
-
# a partial index bundle for names.
|
9
|
-
#
|
10
|
-
class Category
|
11
|
-
|
12
|
-
include Internals::Shared::Category
|
13
|
-
|
14
|
-
attr_accessor :exact
|
15
|
-
attr_reader :name, :index
|
16
|
-
attr_writer :partial
|
17
|
-
|
18
|
-
#
|
19
|
-
#
|
20
|
-
def initialize name, index, options = {}
|
21
|
-
@name = name
|
22
|
-
@index = index
|
23
|
-
|
24
|
-
# TODO Push the defaults out into the index.
|
25
|
-
#
|
26
|
-
@partial_strategy = options[:partial] || Internals::Generators::Partial::Default
|
27
|
-
similarity = options[:similarity] || Internals::Generators::Similarity::Default
|
28
|
-
|
29
|
-
bundle_class = options[:indexed_bundle_class] || Bundle::Memory
|
30
|
-
@exact = bundle_class.new :exact, self, similarity
|
31
|
-
@partial = bundle_class.new :partial, self, similarity
|
32
|
-
|
33
|
-
# @exact = exact_lambda.call(@exact, @partial) if exact_lambda = options[:exact_lambda]
|
34
|
-
# @partial = partial_lambda.call(@exact, @partial) if partial_lambda = options[:partial_lambda]
|
35
|
-
|
36
|
-
# TODO Extract?
|
37
|
-
#
|
38
|
-
Query::Qualifiers.add(name, generate_qualifiers_from(options) || [name])
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_s
|
42
|
-
<<-CATEGORY
|
43
|
-
Category(#{name}):
|
44
|
-
Exact:
|
45
|
-
#{exact.indented_to_s(4)}
|
46
|
-
Partial:
|
47
|
-
#{partial.indented_to_s(4)}
|
48
|
-
CATEGORY
|
49
|
-
end
|
50
|
-
|
51
|
-
# TODO Move to Index.
|
52
|
-
#
|
53
|
-
def generate_qualifiers_from options
|
54
|
-
options[:qualifiers] || options[:qualifier] && [options[:qualifier]]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Loads the index from cache.
|
58
|
-
#
|
59
|
-
def load_from_cache
|
60
|
-
timed_exclaim %Q{"#{identifier}": Loading index from cache.}
|
61
|
-
exact.load
|
62
|
-
partial.load
|
63
|
-
end
|
64
|
-
|
65
|
-
# Loads, analyzes, and clears the index.
|
66
|
-
#
|
67
|
-
# Note: The idea is not to run this while the search engine is running.
|
68
|
-
#
|
69
|
-
def analyze collector
|
70
|
-
collector[identifier] = {
|
71
|
-
:exact => Analyzer.new.analyze(exact),
|
72
|
-
:partial => Analyzer.new.analyze(partial)
|
73
|
-
}
|
74
|
-
collector
|
75
|
-
end
|
76
|
-
|
77
|
-
# Gets the weight for this token's text.
|
78
|
-
#
|
79
|
-
def weight token
|
80
|
-
bundle_for(token).weight token.text
|
81
|
-
end
|
82
|
-
|
83
|
-
# Gets the ids for this token's text.
|
84
|
-
#
|
85
|
-
def ids token
|
86
|
-
bundle_for(token).ids token.text
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns the right index bundle for this token.
|
90
|
-
#
|
91
|
-
def bundle_for token
|
92
|
-
token.partial?? partial : exact
|
93
|
-
end
|
94
|
-
|
95
|
-
# The partial strategy defines whether to really use the partial index.
|
96
|
-
#
|
97
|
-
def partial
|
98
|
-
@partial_strategy.use_exact_for_partial?? @exact : @partial
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
#
|
103
|
-
def combination_for token
|
104
|
-
weight(token) && Internals::Query::Combination.new(token, self)
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
|
3
|
-
module Indexed
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
class Index
|
8
|
-
|
9
|
-
attr_reader :name, :result_identifier, :combinator, :categories
|
10
|
-
|
11
|
-
delegate :load_from_cache,
|
12
|
-
:analyze,
|
13
|
-
:to => :categories
|
14
|
-
|
15
|
-
def initialize name, options = {}
|
16
|
-
@name = name
|
17
|
-
|
18
|
-
@result_identifier = options[:result_identifier] || name
|
19
|
-
@bundle_class = options[:indexed_bundle_class] # TODO This should actually be a fixed parameter.
|
20
|
-
ignore_unassigned_tokens = options[:ignore_unassigned_tokens] || false # TODO Move to query, somehow.
|
21
|
-
|
22
|
-
@categories = Categories.new ignore_unassigned_tokens: ignore_unassigned_tokens
|
23
|
-
end
|
24
|
-
|
25
|
-
def define_category category_name, options = {}
|
26
|
-
options = default_category_options.merge options
|
27
|
-
|
28
|
-
new_category = Category.new category_name, self, options
|
29
|
-
categories << new_category
|
30
|
-
new_category
|
31
|
-
end
|
32
|
-
|
33
|
-
# By default, the category uses
|
34
|
-
# * the index's bundle type.
|
35
|
-
#
|
36
|
-
def default_category_options
|
37
|
-
{
|
38
|
-
:indexed_bundle_class => @bundle_class
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return the possible combinations for this token.
|
43
|
-
#
|
44
|
-
# A combination is a tuple <token, index_bundle>.
|
45
|
-
#
|
46
|
-
def possible_combinations token
|
47
|
-
categories.possible_combinations_for token
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_s
|
51
|
-
<<-INDEX
|
52
|
-
Indexed(#{name}):
|
53
|
-
Result identifier: "#{result_identifier}"
|
54
|
-
Categories:
|
55
|
-
#{categories.indented_to_s}
|
56
|
-
INDEX
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
module Indexed
|
3
|
-
module Wrappers
|
4
|
-
|
5
|
-
module Bundle
|
6
|
-
|
7
|
-
# A calculation rewrites the symbol into a float.
|
8
|
-
#
|
9
|
-
# TODO I really need to allow integers as keys. The code below is just not up to the needed quality.
|
10
|
-
#
|
11
|
-
class Calculation < Wrapper
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
def recalculate float
|
16
|
-
float
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
def ids sym
|
22
|
-
@bundle.ids recalculate(sym.to_s.to_f).to_s.to_sym
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
def weight sym
|
28
|
-
@bundle.weight recalculate(sym.to_s.to_f).to_s.to_sym
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
module Indexed
|
3
|
-
module Wrappers
|
4
|
-
|
5
|
-
module Bundle
|
6
|
-
|
7
|
-
# A location calculation recalculates a location to the Picky internal location.
|
8
|
-
#
|
9
|
-
class Location < Calculation
|
10
|
-
|
11
|
-
def initialize bundle, options = {}
|
12
|
-
super bundle
|
13
|
-
|
14
|
-
precision = options[:precision] || 1
|
15
|
-
user_grid = options[:grid] || raise("Gridsize needs to be given for location #{bundle.identifier}.")
|
16
|
-
|
17
|
-
@calculation = Internals::Calculations::Location.new user_grid, precision
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
def recalculate float
|
23
|
-
@calculation.recalculate float
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
def load
|
29
|
-
# Load first the bundle, then extract the config.
|
30
|
-
#
|
31
|
-
bundle.load
|
32
|
-
# TODO Move the to_f to the backend.
|
33
|
-
#
|
34
|
-
minimum = bundle[:location_minimum] && bundle[:location_minimum].to_f || raise("Configuration :location_minimum for #{bundle.identifier} missing. Did you run rake index already?")
|
35
|
-
@calculation.minimum = minimum
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
module Indexed
|
3
|
-
module Wrappers
|
4
|
-
|
5
|
-
# Per Bundle wrappers.
|
6
|
-
#
|
7
|
-
module Bundle
|
8
|
-
|
9
|
-
# Base wrapper. Just delegates all methods to the bundle.
|
10
|
-
#
|
11
|
-
class Wrapper
|
12
|
-
|
13
|
-
attr_reader :bundle
|
14
|
-
|
15
|
-
def initialize bundle
|
16
|
-
@bundle = bundle
|
17
|
-
end
|
18
|
-
|
19
|
-
delegate :load,
|
20
|
-
:load_index,
|
21
|
-
:load_weights,
|
22
|
-
:load_similarity,
|
23
|
-
:load_configuration,
|
24
|
-
:clear_index,
|
25
|
-
:clear_weights,
|
26
|
-
:clear_similarity,
|
27
|
-
:clear_configuration,
|
28
|
-
:ids,
|
29
|
-
:weight,
|
30
|
-
:identifier,
|
31
|
-
:analyze,
|
32
|
-
:size,
|
33
|
-
:index,
|
34
|
-
:weights,
|
35
|
-
:similarity,
|
36
|
-
:configuration,
|
37
|
-
:to => :@bundle
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
module Indexed
|
3
|
-
module Wrappers
|
4
|
-
module Category
|
5
|
-
|
6
|
-
module Location
|
7
|
-
|
8
|
-
def self.install_on category, grid, precision = 1
|
9
|
-
wrapped_exact = Internals::Indexed::Wrappers::Bundle::Location.new category.exact, grid: grid, precision: precision
|
10
|
-
|
11
|
-
category.class_eval do
|
12
|
-
define_method :exact do
|
13
|
-
wrapped_exact
|
14
|
-
end
|
15
|
-
define_method :partial do
|
16
|
-
wrapped_exact
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module Internals
|
2
|
-
|
3
|
-
# encoding: utf-8
|
4
|
-
#
|
5
|
-
module Indexed
|
6
|
-
|
7
|
-
module Wrappers
|
8
|
-
|
9
|
-
# This index combines an exact and partial index.
|
10
|
-
# It serves to order the results such that exact hits are found first.
|
11
|
-
#
|
12
|
-
class ExactFirst < Indexed::Bundle::Base
|
13
|
-
|
14
|
-
delegate :similar,
|
15
|
-
:identifier,
|
16
|
-
:name,
|
17
|
-
:to => :@exact
|
18
|
-
delegate :index,
|
19
|
-
:category,
|
20
|
-
:weight,
|
21
|
-
:generate_partial_from,
|
22
|
-
:generate_caches_from_memory,
|
23
|
-
:generate_derived,
|
24
|
-
:dump,
|
25
|
-
:load,
|
26
|
-
:to => :@partial
|
27
|
-
|
28
|
-
def initialize category
|
29
|
-
@exact = category.exact
|
30
|
-
@partial = category.partial
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.wrap index_or_category
|
34
|
-
if index_or_category.respond_to? :categories
|
35
|
-
wrap_each_of index_or_category.categories
|
36
|
-
index_or_category
|
37
|
-
else
|
38
|
-
new index_or_category
|
39
|
-
end
|
40
|
-
end
|
41
|
-
def self.wrap_each_of categories
|
42
|
-
categories.categories.collect! { |category| new(category) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def ids text
|
46
|
-
@exact.ids(text) + @partial.ids(text)
|
47
|
-
end
|
48
|
-
|
49
|
-
def weight text
|
50
|
-
[@exact.weight(text) || 0, @partial.weight(text) || 0].max
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,216 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
module Internals
|
4
|
-
|
5
|
-
module Indexing # :nodoc:all
|
6
|
-
|
7
|
-
module Bundle
|
8
|
-
|
9
|
-
# This is the indexing bundle.
|
10
|
-
# It does all menial tasks that have nothing to do
|
11
|
-
# with the actual index running etc.
|
12
|
-
#
|
13
|
-
class Base < SuperBase
|
14
|
-
|
15
|
-
attr_accessor :partial_strategy, :weights_strategy
|
16
|
-
|
17
|
-
# Path is in which directory the cache is located.
|
18
|
-
#
|
19
|
-
def initialize name, category, similarity_strategy, partial_strategy, weights_strategy
|
20
|
-
super name, category, similarity_strategy
|
21
|
-
|
22
|
-
@partial_strategy = partial_strategy
|
23
|
-
@weights_strategy = weights_strategy
|
24
|
-
end
|
25
|
-
|
26
|
-
# Sets up a piece of the index for the given token.
|
27
|
-
#
|
28
|
-
def initialize_index_for token
|
29
|
-
index[token] ||= []
|
30
|
-
end
|
31
|
-
|
32
|
-
# Generation
|
33
|
-
#
|
34
|
-
|
35
|
-
# This method
|
36
|
-
# * Loads the base index from the "prepared..." file.
|
37
|
-
# * Generates derived indexes.
|
38
|
-
# * Dumps all the indexes into files.
|
39
|
-
#
|
40
|
-
def generate_caches_from_source
|
41
|
-
load_from_index_file
|
42
|
-
generate_caches_from_memory
|
43
|
-
end
|
44
|
-
# Generates derived indexes from the index and dumps.
|
45
|
-
#
|
46
|
-
# Note: assumes that there is something in the index
|
47
|
-
#
|
48
|
-
def generate_caches_from_memory
|
49
|
-
cache_from_memory_generation_message
|
50
|
-
generate_derived
|
51
|
-
end
|
52
|
-
def cache_from_memory_generation_message
|
53
|
-
timed_exclaim %Q{"#{identifier}": Caching from intermediate in-memory index.}
|
54
|
-
end
|
55
|
-
|
56
|
-
# Generates the weights and similarity from the main index.
|
57
|
-
#
|
58
|
-
def generate_derived
|
59
|
-
generate_weights
|
60
|
-
generate_similarity
|
61
|
-
end
|
62
|
-
|
63
|
-
# Load the data from the db.
|
64
|
-
#
|
65
|
-
def load_from_index_file
|
66
|
-
load_from_index_generation_message
|
67
|
-
clear
|
68
|
-
retrieve
|
69
|
-
end
|
70
|
-
def load_from_index_generation_message
|
71
|
-
timed_exclaim %Q{"#{identifier}": Loading index.}
|
72
|
-
end
|
73
|
-
# Retrieves the prepared index data into the index.
|
74
|
-
#
|
75
|
-
# This is in preparation for generating
|
76
|
-
# derived indexes (like weights, similarity)
|
77
|
-
# and later dumping the optimized index.
|
78
|
-
#
|
79
|
-
def retrieve
|
80
|
-
key_format = self[:key_format] || :to_i
|
81
|
-
files.retrieve do |id, token|
|
82
|
-
initialize_index_for token
|
83
|
-
index[token] << id.send(key_format)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Generates a new index (writes its index) using the
|
88
|
-
# partial caching strategy of this bundle.
|
89
|
-
#
|
90
|
-
def generate_partial
|
91
|
-
generator = Generators::PartialGenerator.new self.index
|
92
|
-
self.index = generator.generate self.partial_strategy
|
93
|
-
end
|
94
|
-
# Generate a partial index from the given exact index.
|
95
|
-
#
|
96
|
-
def generate_partial_from exact_index
|
97
|
-
timed_exclaim %Q{"#{identifier}": Generating partial index for index.}
|
98
|
-
self.index = exact_index
|
99
|
-
self.generate_partial
|
100
|
-
self
|
101
|
-
end
|
102
|
-
# Generates a new similarity index (writes its index) using the
|
103
|
-
# given similarity caching strategy.
|
104
|
-
#
|
105
|
-
def generate_similarity
|
106
|
-
generator = Generators::SimilarityGenerator.new self.index
|
107
|
-
self.similarity = generator.generate self.similarity_strategy
|
108
|
-
end
|
109
|
-
# Generates a new weights index (writes its index) using the
|
110
|
-
# given weight caching strategy.
|
111
|
-
#
|
112
|
-
def generate_weights
|
113
|
-
generator = Generators::WeightsGenerator.new self.index
|
114
|
-
self.weights = generator.generate self.weights_strategy
|
115
|
-
end
|
116
|
-
|
117
|
-
# Saves the indexes in a dump file.
|
118
|
-
#
|
119
|
-
def dump
|
120
|
-
dump_index
|
121
|
-
dump_similarity
|
122
|
-
dump_weights
|
123
|
-
dump_configuration
|
124
|
-
end
|
125
|
-
# Dumps the core index.
|
126
|
-
#
|
127
|
-
def dump_index
|
128
|
-
timed_exclaim %Q{"#{identifier}": Dumping index.}
|
129
|
-
backend.dump_index index
|
130
|
-
end
|
131
|
-
# Dumps the weights index.
|
132
|
-
#
|
133
|
-
def dump_weights
|
134
|
-
timed_exclaim %Q{"#{identifier}": Dumping weights of index.}
|
135
|
-
backend.dump_weights weights
|
136
|
-
end
|
137
|
-
# Dumps the similarity index.
|
138
|
-
#
|
139
|
-
def dump_similarity
|
140
|
-
timed_exclaim %Q{"#{identifier}": Dumping similarity of index.}
|
141
|
-
backend.dump_similarity similarity
|
142
|
-
end
|
143
|
-
# Dumps the similarity index.
|
144
|
-
#
|
145
|
-
def dump_configuration
|
146
|
-
timed_exclaim %Q{"#{identifier}": Dumping configuration for index.}
|
147
|
-
backend.dump_configuration configuration
|
148
|
-
end
|
149
|
-
|
150
|
-
# Alerts the user if an index is missing.
|
151
|
-
#
|
152
|
-
def raise_unless_cache_exists
|
153
|
-
raise_unless_index_exists
|
154
|
-
raise_unless_similarity_exists
|
155
|
-
end
|
156
|
-
# Alerts the user if one of the necessary indexes
|
157
|
-
# (core, weights) is missing.
|
158
|
-
#
|
159
|
-
def raise_unless_index_exists
|
160
|
-
if partial_strategy.saved?
|
161
|
-
warn_if_index_small
|
162
|
-
raise_unless_index_ok
|
163
|
-
end
|
164
|
-
end
|
165
|
-
# Alerts the user if the similarity
|
166
|
-
# index is missing (given that it's used).
|
167
|
-
#
|
168
|
-
def raise_unless_similarity_exists
|
169
|
-
if similarity_strategy.saved?
|
170
|
-
warn_if_similarity_small
|
171
|
-
raise_unless_similarity_ok
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
# Outputs a warning for the given cache.
|
176
|
-
#
|
177
|
-
def warn_cache_small what
|
178
|
-
warn "Warning: #{what} cache for #{identifier} smaller than 16 bytes."
|
179
|
-
end
|
180
|
-
# Raises an appropriate error message for the given cache.
|
181
|
-
#
|
182
|
-
def raise_cache_missing what
|
183
|
-
raise "Error: The #{what} cache for #{identifier} is missing."
|
184
|
-
end
|
185
|
-
|
186
|
-
# Warns the user if the similarity index is small.
|
187
|
-
#
|
188
|
-
def warn_if_similarity_small
|
189
|
-
warn_cache_small :similarity if backend.similarity_cache_small?
|
190
|
-
end
|
191
|
-
# Alerts the user if the similarity index is not there.
|
192
|
-
#
|
193
|
-
def raise_unless_similarity_ok
|
194
|
-
raise_cache_missing :similarity unless backend.similarity_cache_ok?
|
195
|
-
end
|
196
|
-
|
197
|
-
# Warns the user if the core or weights indexes are small.
|
198
|
-
#
|
199
|
-
def warn_if_index_small
|
200
|
-
warn_cache_small :index if backend.index_cache_small?
|
201
|
-
warn_cache_small :weights if backend.weights_cache_small?
|
202
|
-
end
|
203
|
-
# Alerts the user if the core or weights indexes are not there.
|
204
|
-
#
|
205
|
-
def raise_unless_index_ok
|
206
|
-
raise_cache_missing :index unless backend.index_cache_ok?
|
207
|
-
raise_cache_missing :weights unless backend.weights_cache_ok?
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
module Internals
|
4
|
-
|
5
|
-
module Indexing # :nodoc:all
|
6
|
-
|
7
|
-
module Bundle
|
8
|
-
|
9
|
-
# The memory version dumps its generated indexes to disk
|
10
|
-
# (mostly JSON) to load them into memory on startup.
|
11
|
-
#
|
12
|
-
class Memory < Base
|
13
|
-
|
14
|
-
# We're using files for the memory backend.
|
15
|
-
# E.g. dump writes files.
|
16
|
-
#
|
17
|
-
alias backend files
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
"Memory\n#{@backend.indented_to_s}"
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
module Internals
|
4
|
-
|
5
|
-
module Indexing # :nodoc:all
|
6
|
-
|
7
|
-
module Bundle
|
8
|
-
|
9
|
-
# The Redis version dumps its generated indexes to
|
10
|
-
# the Redis backend.
|
11
|
-
#
|
12
|
-
class Redis < Base
|
13
|
-
|
14
|
-
attr_reader :backend
|
15
|
-
|
16
|
-
def initialize name, category, *args
|
17
|
-
super name, category, *args
|
18
|
-
|
19
|
-
@backend = Internals::Index::Redis.new name, category
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|