xapian_db 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +12 -1
- data/lib/xapian_db/adapters/active_record_adapter.rb +1 -0
- data/lib/xapian_db/adapters/datamapper_adapter.rb +1 -0
- data/lib/xapian_db/database.rb +3 -3
- data/lib/xapian_db/document_blueprint.rb +23 -17
- data/lib/xapian_db/index_writers/direct_writer.rb +1 -1
- data/lib/xapian_db/resultset.rb +1 -0
- data/lib/xapian_db.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
##0.5.7 (March 7th, 2011)
|
2
|
+
|
3
|
+
Fixes:
|
4
|
+
|
5
|
+
- limit_value on the resultset is calculated again when the resultset is empty (thanks, Javi)
|
6
|
+
- added an order by id for rebuild_xapian_index to ensure that limit and offset work as expected
|
7
|
+
|
8
|
+
Features:
|
9
|
+
|
10
|
+
- option to specify a specific adapter for a blueprint overriding the global configuration
|
11
|
+
|
1
12
|
##0.5.6 (February 28th, 2011)
|
2
13
|
|
3
14
|
Features:
|
@@ -18,7 +29,7 @@ Features:
|
|
18
29
|
- configure only those environments in xapian_db.yml where you want to override the defaults
|
19
30
|
- XapianDb.rebuild_xapian_index rebuilds the index for all blueprints
|
20
31
|
|
21
|
-
##0.5.4 (February
|
32
|
+
##0.5.4 (February 22nd, 2011)
|
22
33
|
|
23
34
|
Fixes:
|
24
35
|
|
data/lib/xapian_db/database.rb
CHANGED
@@ -46,8 +46,8 @@ module XapianDb
|
|
46
46
|
# @option options [Integer] :per_page How many docs per page?
|
47
47
|
# @option options [Array<Integer>] :sort_indices (nil) An array of attribute indices to sort by. This
|
48
48
|
# option is used internally by the search method implemented on configured classes. Do not use it
|
49
|
-
# directly unless
|
50
|
-
#
|
49
|
+
# directly unless you know what you do
|
50
|
+
# @option options [Boolean] :sort_decending (false) Reverse the sort order?
|
51
51
|
# @example Simple Query
|
52
52
|
# resultset = db.search("foo")
|
53
53
|
# @example Wildcard Query
|
@@ -76,7 +76,7 @@ module XapianDb
|
|
76
76
|
raise ArgumentError.new("Sorting is available for class scoped searches only") unless expression =~ /^indexed_class:/
|
77
77
|
sorter = Xapian::MultiValueSorter.new
|
78
78
|
|
79
|
-
|
79
|
+
sort_indices.each do |index|
|
80
80
|
sorter.add(index, sort_decending)
|
81
81
|
end
|
82
82
|
enquiry.set_sort_by_key_then_relevance(sorter)
|
@@ -6,18 +6,12 @@ module XapianDb
|
|
6
6
|
# for a given class.
|
7
7
|
# @example A simple document blueprint configuration for the class Person
|
8
8
|
# XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
|
9
|
-
# # Our Person class has a method lang_cd. We use this method to
|
10
|
-
# # index each person with its language
|
11
|
-
# blueprint.language_method :lang_cd
|
12
9
|
# blueprint.attribute :name, :weight => 10
|
13
10
|
# blueprint.attribute :first_name
|
14
11
|
# blueprint.index :remarks
|
15
12
|
# end
|
16
13
|
# @example A document blueprint configuration with a complex attribute for the class Person
|
17
14
|
# XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
|
18
|
-
# # Our Person class has a method lang_cd. We use this method to
|
19
|
-
# # index each person with its language
|
20
|
-
# blueprint.language_method :lang_cd
|
21
15
|
# blueprint.attribute :complex, :weight => 10 do
|
22
16
|
# # add some logic here to evaluate the value of 'complex'
|
23
17
|
# end
|
@@ -40,8 +34,8 @@ module XapianDb
|
|
40
34
|
blueprint = DocumentBlueprint.new
|
41
35
|
yield blueprint if block_given? # configure the blueprint through the block
|
42
36
|
@blueprints[klass] = blueprint
|
43
|
-
@
|
44
|
-
@
|
37
|
+
@_adapter = blueprint._adapter || XapianDb::Config.adapter || Adapters::GenericAdapter
|
38
|
+
@_adapter.add_class_helper_methods_to klass
|
45
39
|
@searchable_prefixes = nil # force rebuild of the searchable prefixes
|
46
40
|
end
|
47
41
|
|
@@ -166,7 +160,7 @@ module XapianDb
|
|
166
160
|
end
|
167
161
|
|
168
162
|
# Let the adapter add its document helper methods (if any)
|
169
|
-
adapter = @
|
163
|
+
adapter = @_adapter || XapianDb::Config.adapter || XapianDb::Adapters::GenericAdapter
|
170
164
|
adapter.add_doc_helper_methods_to(@accessors_module)
|
171
165
|
@accessors_module
|
172
166
|
end
|
@@ -175,14 +169,8 @@ module XapianDb
|
|
175
169
|
# Blueprint DSL methods
|
176
170
|
# ---------------------------------------------------------------------------------
|
177
171
|
|
178
|
-
#
|
179
|
-
|
180
|
-
attr_reader :lang_method
|
181
|
-
|
182
|
-
# Set / read a custom adapter.
|
183
|
-
# Use this configuration option if you need a specific adapter for an indexed class.
|
184
|
-
# If set, it overrides the globally configured adapter (see also {Config#adapter})
|
185
|
-
attr_accessor :adapter
|
172
|
+
# An optional custom adapter
|
173
|
+
attr_accessor :_adapter
|
186
174
|
|
187
175
|
# Construct the blueprint
|
188
176
|
def initialize
|
@@ -190,6 +178,16 @@ module XapianDb
|
|
190
178
|
@indexed_methods_hash = {}
|
191
179
|
end
|
192
180
|
|
181
|
+
# Set the adapter
|
182
|
+
# @param [Symbol] type The adapter type; the following adapters are available:
|
183
|
+
# - :generic ({XapianDb::Adapters::GenericAdapter})
|
184
|
+
# - :active_record ({XapianDb::Adapters::ActiveRecordAdapter})
|
185
|
+
# - :datamapper ({XapianDb::Adapters::DatamapperAdapter})
|
186
|
+
def adapter(type)
|
187
|
+
# We try to guess the adapter name
|
188
|
+
@_adapter = XapianDb::Adapters.const_get("#{camelize(type.to_s)}Adapter")
|
189
|
+
end
|
190
|
+
|
193
191
|
# Add an attribute to the blueprint. Attributes will be stored in the xapian documents an can be
|
194
192
|
# accessed from a search result.
|
195
193
|
# @param [String] name The name of the method that delivers the value for the attribute
|
@@ -296,6 +294,14 @@ module XapianDb
|
|
296
294
|
@reserved_method_names ||= Xapian::Document.instance_methods
|
297
295
|
@reserved_method_names.include?(attr_name.to_sym)
|
298
296
|
end
|
297
|
+
|
298
|
+
private
|
299
|
+
|
300
|
+
# TODO: move this to a helper module
|
301
|
+
def camelize(string)
|
302
|
+
string.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
|
303
|
+
end
|
304
|
+
|
299
305
|
end
|
300
306
|
|
301
307
|
end
|
@@ -54,7 +54,7 @@ module XapianDb
|
|
54
54
|
# Process the objects in batches to reduce the memory footprint
|
55
55
|
nr_of_batches = (obj_count / 1000) + 1
|
56
56
|
nr_of_batches.times do |batch|
|
57
|
-
klass.all(:offset => batch * 1000, :limit => 1000)
|
57
|
+
klass.all(:offset => batch * 1000, :limit => 1000, :order => options[:primary_key]).each do |obj|
|
58
58
|
if blueprint.should_index? obj
|
59
59
|
doc = indexer.build_document_for(obj)
|
60
60
|
XapianDb.database.store_doc(doc)
|
data/lib/xapian_db/resultset.rb
CHANGED
data/lib/xapian_db.rb
CHANGED
@@ -92,7 +92,7 @@ module XapianDb
|
|
92
92
|
configured_classes = XapianDb::DocumentBlueprint.configured_classes
|
93
93
|
return false unless configured_classes.size > 0
|
94
94
|
configured_classes.each do |klass|
|
95
|
-
XapianDb::Config.writer.reindex_class(klass, options)
|
95
|
+
XapianDb::Config.writer.reindex_class(klass, options) if klass.respond_to?(:rebuild_xapian_index)
|
96
96
|
end
|
97
97
|
true
|
98
98
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: xapian_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gernot Kogler
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-07 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|