picky 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/picky/bundle.rb CHANGED
@@ -18,6 +18,8 @@ class Bundle
18
18
  #
19
19
  # TODO Move Files somewhere. Shared?
20
20
  #
21
+ # Files and the identifier are parametrized, the rest is not!
22
+ #
21
23
  @files = Index::Files.new name, category.name, type.name
22
24
  end
23
25
 
@@ -37,8 +37,6 @@ module Index
37
37
 
38
38
  # Loads the index from cache.
39
39
  #
40
- # TODO Metaprogram delegation? each_delegate?
41
- #
42
40
  def load_from_cache
43
41
  timed_exclaim "Loading index #{identifier}."
44
42
  exact.load
@@ -1,7 +1,5 @@
1
1
  module Index
2
2
 
3
- # TODO Think about using 3 instances of this in the bundle.
4
- #
5
3
  class Files
6
4
 
7
5
  attr_reader :bundle_name, :category_name, :type_name
@@ -21,6 +21,8 @@ module Indexers
21
21
  #
22
22
  # TODO Duplicate code in Index::Files.
23
23
  #
24
+ # TODO Rename to prepared_index_file_name.
25
+ #
24
26
  def search_index_file_name
25
27
  @category.search_index_file_name
26
28
  end
@@ -37,7 +39,7 @@ module Indexers
37
39
  @category.source || raise_no_source
38
40
  end
39
41
  def raise_no_source
40
- raise NoSourceSpecifiedException.new "No source given for index:#{@type.name}, category:#{@category.name}." # TODO field.identifier
42
+ raise NoSourceSpecifiedException.new("No source given for index:#{@type.name}, category:#{@category.name}.") # TODO field.identifier
41
43
  end
42
44
 
43
45
  # Selects the original id (indexed id) and a column to process. The column data is called "token".
@@ -50,7 +52,17 @@ module Indexers
50
52
 
51
53
  indexing_message
52
54
 
53
- # TODO Move open to Index::File.
55
+ # TODO Move open to Index::File.
56
+ #
57
+ # @category.prepared_index do |file|
58
+ # source.harvest(@type, @category) do |indexed_id, text|
59
+ # tokenizer.tokenize(text).each do |token_text|
60
+ # next unless token_text
61
+ # file.buffer indexed_id << comma << token_text << newline
62
+ # end
63
+ # file.write_maybe
64
+ # end
65
+ # end
54
66
  #
55
67
  File.open(search_index_file_name, 'w:binary') do |file|
56
68
  result = []
@@ -1,3 +1,3 @@
1
1
  module Indexers
2
- Default = Field
2
+ Default = Base
3
3
  end
@@ -29,6 +29,8 @@ module Indexing
29
29
  next unless category.name == category_name
30
30
  return category
31
31
  end
32
+
33
+ raise %Q{Index category "#{category_name}" not found. Possible categories: "#{categories.map(&:name).join('", "')}".}
32
34
  end
33
35
 
34
36
  end
@@ -26,6 +26,8 @@ module Indexing
26
26
  @exact = options[:exact_indexing_bundle] || Bundle.new(:exact, self, type, similarity, Cacher::Partial::None.new, weights)
27
27
  @partial = options[:partial_indexing_bundle] || Bundle.new(:partial, self, type, Cacher::Similarity::None.new, partial, weights)
28
28
 
29
+ # TODO Move to Query.
30
+ #
29
31
  # @remove = options[:remove] || false
30
32
  # @filter = options[:filter] || true
31
33
 
@@ -66,27 +68,11 @@ module Indexing
66
68
  exact.delete
67
69
  partial.delete
68
70
  end
69
- def create_directory_structure
70
- timed_exclaim "Creating directory structure for #{identifier}."
71
- exact.create_directory
72
- partial.create_directory
73
- end
74
-
75
- # Used for testing.
76
- #
77
- # TODO Remove?
78
- #
79
- def generate_indexes_from_exact_index
80
- generate_derived_exact
81
- generate_partial
82
- generate_derived_partial
83
- end
84
- def generate_derived_exact
85
- exact.generate_derived
86
- end
87
- def generate_derived_partial
88
- partial.generate_derived
89
- end
71
+ # def create_directory_structure
72
+ # timed_exclaim "Creating directory structure for #{identifier}."
73
+ # exact.create_directory
74
+ # partial.create_directory
75
+ # end
90
76
 
91
77
  # Generates all caches for this category.
92
78
  #
@@ -117,6 +103,8 @@ module Indexing
117
103
 
118
104
  # TODO Partially move to type. Duplicate Code in indexers/field.rb.
119
105
  #
106
+ # TODO Use the Files object.
107
+ #
120
108
  def search_index_root
121
109
  File.join PICKY_ROOT, 'index'
122
110
  end
@@ -128,6 +116,7 @@ module Indexing
128
116
  end
129
117
  def index
130
118
  prepare_cache_directory
119
+ # files.create_directory # TODO Make this possible!
131
120
  indexer.index
132
121
  end
133
122
  def prepare_cache_directory
@@ -46,14 +46,25 @@ module Indexing
46
46
  timed_exclaim "INDEXING FINISHED."
47
47
  end
48
48
 
49
+ # For testing.
50
+ #
51
+ def index_for_tests
52
+ take_snapshot
53
+
54
+ self.types.each do |type|
55
+ type.index
56
+ type.cache
57
+ end
58
+ end
59
+
49
60
  # TODO Spec
50
61
  #
51
- def generate_index_only type_name, field_name
52
- found = find type_name, field_name
62
+ def generate_index_only type_name, category_name
63
+ found = find type_name, category_name
53
64
  found.index if found
54
65
  end
55
66
  def generate_cache_only type_name, category_name
56
- found = find type_name, field_name
67
+ found = find type_name, category_name
57
68
  found.generate_caches if found
58
69
  end
59
70
 
@@ -68,6 +79,8 @@ module Indexing
68
79
  found = type.categories.find category_name
69
80
  return found if found
70
81
  end
82
+
83
+ raise %Q{Index "#{type_name}" not found. Possible indexes: "#{types.map(&:name).join('", "')}".}
71
84
  end
72
85
 
73
86
  end
data/lib/picky/loader.rb CHANGED
@@ -120,7 +120,6 @@ module Loader
120
120
  #
121
121
  load_relative 'indexers/no_source_specified_error'
122
122
  load_relative 'indexers/base'
123
- load_relative 'indexers/field'
124
123
  load_relative 'indexers/default'
125
124
  #
126
125
  # load_relative 'indexers/solr'
@@ -37,7 +37,7 @@ module Sources
37
37
  end
38
38
 
39
39
  def raise_no_db_given field_names
40
- raise NoCouchDBGiven.new field_names.join(', ')
40
+ raise NoCouchDBGiven.new(field_names.join(', '))
41
41
  end
42
42
  end
43
43
  end
@@ -18,7 +18,7 @@ module Sources
18
18
  #
19
19
  #
20
20
  def raise_no_file_given field_names
21
- raise NoCSVFileGiven.new field_names.join(', ')
21
+ raise NoCSVFileGiven.new(field_names.join(', '))
22
22
  end
23
23
 
24
24
  # Harvests the data to index.
data/lib/picky/types.rb CHANGED
@@ -8,7 +8,9 @@ class Types
8
8
  :load_from_cache,
9
9
  :to => :@indexes
10
10
 
11
- delegate :index,
11
+ delegate :find,
12
+ :index,
13
+ :index_for_tests,
12
14
  :generate_index_only,
13
15
  :generate_cache_only,
14
16
  :to => :@indexings
data/lib/tasks/index.rake CHANGED
@@ -12,17 +12,16 @@ namespace :index do
12
12
  # end
13
13
  # end
14
14
 
15
- # TODO Make option to also use non-random.
16
- # rake index:randomly (default)
17
- # rake index:ordered
18
- #
19
- desc "Takes a snapshot, indexes, and caches."
20
- task :generate, [:order] => :application do |_, options|
21
- randomly = (options.order == 'ordered') ? false : true
22
- Indexes.index randomly
15
+ desc "Takes a snapshot, indexes, and caches in random order."
16
+ task :randomly => :application do
17
+ Indexes.index true
18
+ end
19
+ desc "Takes a snapshot, indexes, and caches in order given."
20
+ task :ordered => :application do
21
+ Indexes.index false
23
22
  end
24
23
 
25
- desc "Generates the index snapshots."
24
+ # desc "Generates the index snapshots."
26
25
  task :generate_snapshots => :application do
27
26
  Indexes.take_snapshot
28
27
  end
@@ -1,6 +1,6 @@
1
- desc "Generate the index."
1
+ desc "Generate the index (random order)."
2
2
  task :index => :application do
3
- Rake::Task[:'index:generate'].invoke
3
+ Rake::Task[:'index:randomly'].invoke
4
4
  end
5
5
 
6
6
  desc "Try the given text in the indexer/query (type:field optional)."
@@ -24,41 +24,15 @@ describe Indexing::Category do
24
24
  @category.dump_caches
25
25
  end
26
26
  end
27
-
28
- describe 'generate_derived_partial' do
29
- it 'should delegate to partial' do
30
- @partial.should_receive(:generate_derived).once.with
31
-
32
- @category.generate_derived_partial
33
- end
34
- end
35
-
36
- describe 'generate_derived_exact' do
37
- it 'should delegate to exact' do
38
- @exact.should_receive(:generate_derived).once.with
39
-
40
- @category.generate_derived_exact
41
- end
42
- end
43
-
44
- describe 'generate_indexes_from_exact_index' do
45
- it 'should call three method in order' do
46
- @category.should_receive(:generate_derived_exact).once.with().ordered
47
- @category.should_receive(:generate_partial).once.with().ordered
48
- @category.should_receive(:generate_derived_partial).once.with().ordered
49
-
50
- @category.generate_indexes_from_exact_index
51
- end
52
- end
53
27
 
54
28
  describe 'generate_caches_from_memory' do
55
29
  it 'should delegate to partial' do
56
30
  @partial.should_receive(:generate_caches_from_memory).once.with
57
-
31
+
58
32
  @category.generate_caches_from_memory
59
33
  end
60
34
  end
61
-
35
+
62
36
  describe 'generate_partial' do
63
37
  it 'should return whatever the partial generation returns' do
64
38
  @exact.stub! :index
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 11
8
- - 0
9
- version: 0.11.0
8
+ - 1
9
+ version: 0.11.1
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-08 00:00:00 +01:00
17
+ date: 2010-11-09 00:00:00 +01:00
18
18
  default_executable: picky
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,6 @@ files:
64
64
  - lib/picky/character_substitution/european.rb
65
65
  - lib/picky/configuration/indexes.rb
66
66
  - lib/picky/configuration/queries.rb
67
- - lib/picky/configuration/type.rb
68
67
  - lib/picky/cores.rb
69
68
  - lib/picky/ext/maybe_compile.rb
70
69
  - lib/picky/ext/ruby19/extconf.rb
@@ -90,7 +89,6 @@ files:
90
89
  - lib/picky/index/wrappers/exact_first.rb
91
90
  - lib/picky/indexers/base.rb
92
91
  - lib/picky/indexers/default.rb
93
- - lib/picky/indexers/field.rb
94
92
  - lib/picky/indexers/no_source_specified_error.rb
95
93
  - lib/picky/indexers/solr.rb
96
94
  - lib/picky/indexing/bundle.rb
@@ -192,7 +190,6 @@ files:
192
190
  - spec/lib/index/type_spec.rb
193
191
  - spec/lib/index/wrappers/exact_first_spec.rb
194
192
  - spec/lib/indexers/base_spec.rb
195
- - spec/lib/indexers/field_spec.rb
196
193
  - spec/lib/indexing/bundle_partial_generation_speed_spec.rb
197
194
  - spec/lib/indexing/bundle_spec.rb
198
195
  - spec/lib/indexing/categories_spec.rb
@@ -294,7 +291,6 @@ test_files:
294
291
  - spec/lib/index/type_spec.rb
295
292
  - spec/lib/index/wrappers/exact_first_spec.rb
296
293
  - spec/lib/indexers/base_spec.rb
297
- - spec/lib/indexers/field_spec.rb
298
294
  - spec/lib/indexing/bundle_partial_generation_speed_spec.rb
299
295
  - spec/lib/indexing/bundle_spec.rb
300
296
  - spec/lib/indexing/categories_spec.rb
@@ -1,20 +0,0 @@
1
- module Configuration
2
- class Type
3
- attr_reader :name,
4
- :source,
5
- :result_type,
6
- :after_indexing,
7
- :ignore_unassigned_tokens
8
- def initialize name, source, options
9
- @name = name
10
- @source = source
11
-
12
- @result_type = options[:result_type] || name
13
- @after_indexing = options[:after_indexing] # Where do I use this?
14
- @ignore_unassigned_tokens = options[:ignore_unassigned_tokens] || false # TODO Move to query?
15
- end
16
- def generate
17
- Index::Type.new name, source, result_type, ignore_unassigned_tokens
18
- end
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- module Indexers
2
- # Base indexer for fields.
3
- #
4
- class Field < Base
5
-
6
- # TODO Still needed?
7
-
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- describe Indexers::Field do
6
-
7
-
8
-
9
- end