xapian_db 1.2.4.5 → 1.2.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ##1.2.4.6 (Decmber 17th, 2012)
2
+
3
+ Changes:
4
+
5
+ - progressbar gem replaced by ruby-progressbar
6
+ - XapianDb.rebuild_xapian_index resets the database to remove any stale index data
7
+
1
8
  ##1.2.4.5 (July 19th, 2012)
2
9
 
3
10
  Fixes:
@@ -165,6 +165,12 @@ module XapianDb
165
165
  # Nothing to do for an in memory database
166
166
  end
167
167
 
168
+ # Reset (empty) the database
169
+ def reset
170
+ @writer = Xapian::inmemory_open
171
+ @reader = @writer
172
+ end
173
+
168
174
  end
169
175
 
170
176
  # Persistent database on disk
@@ -212,6 +218,15 @@ module XapianDb
212
218
  writer.commit
213
219
  end
214
220
 
221
+ # Reset (empty) the database
222
+ def reset
223
+ # We must release the writer and run the garbage collector to remove the write lock
224
+ @writer = nil
225
+ GC.start
226
+ @writer = Xapian::WritableDatabase.new(@path, Xapian::DB_CREATE_OR_OVERWRITE)
227
+ @reader = Xapian::Database.new(@path)
228
+ end
229
+
215
230
  end
216
231
 
217
- end
232
+ end
@@ -32,12 +32,8 @@ module XapianDb
32
32
  # - attribute (see {#attribute} for details)
33
33
  # - index (see {#index} for details)
34
34
  def setup(klass_or_name, &block)
35
- if klass_or_name.is_a?(Class)
36
- warn "xapian_db: XapianDb::DocumentBlueprint.setup(Class) is deprecated; use XapianDb::DocumentBlueprint.setup(Symbol) or XapianDb::DocumentBlueprint.setup(String) instead"
37
- name = klass_or_name.name
38
- else
39
- name = klass_or_name.to_s
40
- end
35
+ name = class_name_from klass_or_name
36
+
41
37
  @blueprints ||= {}
42
38
  blueprint = DocumentBlueprint.new
43
39
  yield blueprint if block_given? # configure the blueprint through the block
@@ -47,16 +43,7 @@ module XapianDb
47
43
  @blueprints.delete_if { |indexed_class, blueprint| indexed_class == name }
48
44
  @blueprints[name] = blueprint
49
45
 
50
- # lazy load the adapter
51
- unless defined? blueprint._adapter
52
- adapter_file = blueprint._adapter.name.split("::").last.downcase + "_adapter"
53
- require File.dirname(__FILE__) + "../adapters/#{adapter_file}"
54
- end
55
-
56
- # Needed to add class helper methods to indexed pure ruby classes
57
- if eval("defined?(#{name}) && #{name}.is_a?(Class)")
58
- blueprint._adapter.add_class_helper_methods_to XapianDb::Utilities.constantize(name)
59
- end
46
+ lazy_load_adapter_for blueprint, name
60
47
 
61
48
  @searchable_prefixes = @blueprints.values.map { |blueprint| blueprint.searchable_prefixes }.flatten.compact.uniq || []
62
49
 
@@ -146,6 +133,28 @@ module XapianDb
146
133
 
147
134
  private
148
135
 
136
+ def class_name_from(klass_or_name)
137
+ if klass_or_name.is_a?(Class)
138
+ warn "xapian_db: XapianDb::DocumentBlueprint.setup(Class) is deprecated; use XapianDb::DocumentBlueprint.setup(Symbol) or XapianDb::DocumentBlueprint.setup(String) instead"
139
+ name = klass_or_name.name
140
+ else
141
+ name = klass_or_name.to_s
142
+ end
143
+ end
144
+
145
+ def lazy_load_adapter_for(blueprint, klass_name)
146
+ # lazy load the adapter
147
+ unless defined? blueprint._adapter
148
+ adapter_file = blueprint._adapter.name.split("::").last.downcase + "_adapter"
149
+ require File.dirname(__FILE__) + "../adapters/#{adapter_file}"
150
+ end
151
+
152
+ # Needed to add class helper methods to indexed pure ruby classes
153
+ if eval("defined?(#{klass_name}) && #{klass_name}.is_a?(Class)")
154
+ blueprint._adapter.add_class_helper_methods_to XapianDb::Utilities.constantize(klass_name)
155
+ end
156
+ end
157
+
149
158
  def validate_type_consistency_on(blueprint)
150
159
  blueprint.type_map.each do |method_name, type|
151
160
  if type_info_for(method_name) && type_info_for(method_name) != type
@@ -64,7 +64,7 @@ module XapianDb
64
64
  if opts[:verbose]
65
65
  show_progressbar = defined?(ProgressBar)
66
66
  puts "reindexing #{obj_count} objects of #{klass}..."
67
- pbar = ProgressBar.new("Status", obj_count) if show_progressbar
67
+ pbar = ProgressBar.create(:title => "Status", :total => obj_count, :format => ' %t %e %B %p%%') if show_progressbar
68
68
  end
69
69
 
70
70
  # Process the objects in batches to reduce the memory footprint
@@ -72,7 +72,7 @@ module XapianDb
72
72
  nr_of_batches.times do |batch|
73
73
  base_query.all(:offset => batch * BATCH_SIZE, :limit => BATCH_SIZE, :order => klass.order_condition(primary_key)).each do |obj|
74
74
  reindex obj, false
75
- pbar.inc if show_progressbar
75
+ pbar.increment if show_progressbar
76
76
  end
77
77
  end
78
78
  XapianDb.database.commit
data/lib/xapian_db.rb CHANGED
@@ -142,6 +142,7 @@ module XapianDb
142
142
  # @option options [Boolean] :verbose (false) Should the reindexing give status informations?
143
143
  # @return [Boolean] Did we reindex anything?
144
144
  def self.rebuild_xapian_index(options={})
145
+ database.reset
145
146
  configured_classes = XapianDb::DocumentBlueprint.configured_classes
146
147
  return false unless configured_classes.size > 0
147
148
  configured_classes.each do |klass|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4.5
4
+ version: 1.2.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: progressbar
111
+ name: ruby-progressbar
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -155,6 +155,22 @@ dependencies:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: 1.2.7.1
158
+ - !ruby/object:Gem::Dependency
159
+ name: pry-rails
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
158
174
  description: XapianDb is a ruby gem that combines features of nosql databases and
159
175
  fulltext indexing. It is based on Xapian, an efficient and powerful indexing library
160
176
  email: gernot.kogler (at) garaio (dot) com
@@ -230,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
246
  version: '0'
231
247
  segments:
232
248
  - 0
233
- hash: 1478598025924087543
249
+ hash: 2931539374051915858
234
250
  required_rubygems_version: !ruby/object:Gem::Requirement
235
251
  none: false
236
252
  requirements: