xapian_db 1.3.5.4 → 1.3.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module XapianDb
22
22
  def index(options)
23
23
  klass = constantize options['class']
24
24
  obj = klass.respond_to?('get') ? klass.get(options['id']) : klass.find(options['id'])
25
- DirectWriter.index obj
25
+ DirectWriter.index obj, true, changed_attrs: options[:changed_attrs]
26
26
  end
27
27
 
28
28
  def delete_doc(options)
@@ -34,7 +34,6 @@ module XapianDb
34
34
  DirectWriter.reindex_class klass, :verbose => false
35
35
  end
36
36
  end
37
-
38
37
  end
39
38
  end
40
39
  end
@@ -12,8 +12,8 @@ module XapianDb
12
12
 
13
13
  # Update an object in the index
14
14
  # @param [Object] obj An instance of a class with a blueprint configuration
15
- def index(obj, commit=true)
16
- Resque.enqueue worker_class, :index, :class => obj.class.name, :id => obj.id
15
+ def index(obj, commit=true, changed_attrs: [])
16
+ Resque.enqueue worker_class, :index, :class => obj.class.name, :id => obj.id, changed_attrs: changed_attrs
17
17
  end
18
18
 
19
19
  # Remove an object from the index
@@ -33,7 +33,6 @@ module XapianDb
33
33
  end
34
34
  private :worker_class
35
35
  end
36
-
37
36
  end
38
37
  end
39
38
  end
@@ -26,7 +26,7 @@ module XapianDb
26
26
  def index(options)
27
27
  klass = constantize options['class']
28
28
  obj = klass.respond_to?('get') ? klass.get(options['id']) : klass.find(options['id'])
29
- DirectWriter.index obj
29
+ DirectWriter.index obj, true, changed_attrs: options[:changed_attrs]
30
30
  end
31
31
 
32
32
  def delete_doc(options)
@@ -16,8 +16,8 @@ module XapianDb
16
16
 
17
17
  # Update an object in the index
18
18
  # @param [Object] obj An instance of a class with a blueprint configuration
19
- def index(obj, commit=true)
20
- Sidekiq::Client.enqueue worker_class, :index, :class => obj.class.name, :id => obj.id
19
+ def index(obj, commit=true, changed_attrs: [])
20
+ Sidekiq::Client.enqueue worker_class, :index, :class => obj.class.name, :id => obj.id, :changed_attrs => changed_attrs
21
21
  end
22
22
 
23
23
  # Remove an object from the index
@@ -37,7 +37,6 @@ module XapianDb
37
37
  end
38
38
  private :worker_class
39
39
  end
40
-
41
40
  end
42
41
  end
43
42
  end
@@ -20,7 +20,7 @@ module XapianDb
20
20
 
21
21
  # Update an object in the index
22
22
  # @param [Object] obj An instance of a class with a blueprint configuration
23
- def index(obj, commit=false)
23
+ def index(obj, commit=false, changed_attrs: [])
24
24
  @index_requests << obj
25
25
  end
26
26
 
@@ -45,8 +45,6 @@ module XapianDb
45
45
  @delete_requests.each { |xapian_id| writer.delete_doc_with xapian_id, false }
46
46
  XapianDb.database.commit
47
47
  end
48
-
49
48
  end
50
-
51
49
  end
52
- end
50
+ end
@@ -86,6 +86,7 @@ module XapianDb
86
86
  values = get_values_to_index_from obj
87
87
  values.each do |value|
88
88
  terms = value.to_s.downcase
89
+ terms = @blueprint.preprocess_terms.call(terms) if @blueprint.preprocess_terms
89
90
  terms = split(terms) if XapianDb::Config.term_splitter_count > 0 && !options.no_split
90
91
  # Add value with field name
91
92
  term_generator.index_text(terms, options.weight, "X#{method.upcase}") if options.prefixed
@@ -35,6 +35,10 @@ module XapianDb
35
35
 
36
36
  # Add the searchable prefixes to allow searches by field
37
37
  # (like "name:Kogler")
38
+ processors = [] # The reason for having a seemingly useless "processors" array is as follows:
39
+ # We need to add a reference to the generated Xapian::XYValueRangeProcessor objects to the scope that calls parser.parse_query.
40
+ # If we don't, the Ruby GC will often garbage collect the generated objects before parser.parse_query can be called,
41
+ # which would free the memory of the corresponding C++ objects and result in segmentation faults upon calling parse_query.
38
42
  XapianDb::DocumentBlueprint.searchable_prefixes.each do |prefix|
39
43
  parser.add_prefix(prefix.to_s.downcase, "X#{prefix.to_s.upcase}")
40
44
  type_info = XapianDb::DocumentBlueprint.type_info_for(prefix)
@@ -42,11 +46,17 @@ module XapianDb
42
46
  value_number = XapianDb::DocumentBlueprint.value_number_for(prefix)
43
47
  case type_info
44
48
  when :date
45
- parser.add_valuerangeprocessor Xapian::DateValueRangeProcessor.new(value_number, "#{prefix}:")
49
+ processor = Xapian::DateValueRangeProcessor.new(value_number, "#{prefix}:")
50
+ processors << processor
51
+ parser.add_valuerangeprocessor(processor)
46
52
  when :number
47
- parser.add_valuerangeprocessor Xapian::NumberValueRangeProcessor.new(value_number, "#{prefix}:")
53
+ processor = Xapian::NumberValueRangeProcessor.new(value_number, "#{prefix}:")
54
+ processors << processor
55
+ parser.add_valuerangeprocessor(processor)
48
56
  when :string
49
- parser.add_valuerangeprocessor Xapian::StringValueRangeProcessor.new(value_number, "#{prefix}:")
57
+ processor = Xapian::StringValueRangeProcessor.new(value_number, "#{prefix}:")
58
+ processors << processor
59
+ parser.add_valuerangeprocessor(processor)
50
60
  end
51
61
  end
52
62
  query = parser.parse_query(expression, @query_flags)
@@ -46,6 +46,7 @@ module XapianDb
46
46
  # @param [Hash] options
47
47
  # @option options [Integer] :db_size The current size (nr of docs) of the database
48
48
  # @option options [Integer] :limit The maximum number of documents to retrieve
49
+ # @option options [Integer] :offset The index of the first result to retrieve
49
50
  # @option options [Integer] :page (1) The page number to retrieve
50
51
  # @option options [Integer] :per_page (10) How many docs per page? Ignored if a limit option is given
51
52
  # @option options [String] :spelling_suggestion (nil) The spelling corrected query (if a language is configured)
@@ -56,25 +57,32 @@ module XapianDb
56
57
  db_size = params.delete :db_size
57
58
  @spelling_suggestion = params.delete :spelling_suggestion
58
59
  limit = params.delete :limit
60
+ offset = params.delete :offset
59
61
  page = params.delete :page
60
62
  per_page = params.delete :per_page
61
63
  raise ArgumentError.new "unsupported options for resultset: #{params}" if params.size > 0
62
64
  raise ArgumentError.new "db_size option is required" unless db_size
63
65
 
66
+ unless (page.nil? && per_page.nil?) || (limit.nil? && offset.nil?)
67
+ raise ArgumentError.new "Impossible combination of parameters. Either pass page and/or per_page, or limit and/or offset."
68
+ end
69
+
70
+ calculated_page = offset.nil? || limit.nil? ? nil : (offset.to_f / limit.to_f) + 1
71
+
64
72
  limit = limit.nil? ? db_size : limit.to_i
65
- per_page = per_page.nil? ? limit : per_page.to_i
66
- page = page.nil? ? 1 : page.to_i
67
- offset = (page - 1) * per_page
68
- count = offset + per_page < limit ? per_page : limit - offset
73
+ per_page = per_page.nil? ? limit.to_i : per_page.to_i
74
+ page = page.nil? ? (calculated_page.nil? ? 1 : calculated_page) : page.to_i
75
+ offset = offset.nil? ? (page - 1) * per_page : offset.to_i
76
+ count = per_page < limit ? per_page : limit
69
77
 
78
+ return build_empty_resultset if (page - 1) * per_page > db_size
70
79
  result_window = enquiry.mset(offset, count)
71
80
  @hits = result_window.matches_estimated
72
81
  return build_empty_resultset if @hits == 0
73
- raise ArgumentError.new "page #{@page} does not exist" if @hits > 0 && offset >= limit
74
82
 
75
83
  self.replace result_window.matches.map{|match| decorate(match).document}
76
84
  @total_pages = (@hits / per_page.to_f).ceil
77
- @current_page = page
85
+ @current_page = (page == page.to_i) ? page.to_i : page
78
86
  @limit_value = per_page
79
87
  end
80
88
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5.4
4
+ version: 1.3.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gernot Kogler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.3.1
47
+ version: 2.99.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.3.1
54
+ version: 2.99.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 1.2.15.1
145
+ version: 1.2.22
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 1.2.15.1
152
+ version: 1.2.22
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: pry-rails
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -164,9 +164,23 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: descendants_tracker
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: XapianDb is a ruby gem that combines features of nosql databases and
168
182
  fulltext indexing. It is based on Xapian, an efficient and powerful indexing library
169
- email: gernot.kogler (at) garaio (dot) com
183
+ email: gernot (at) kogler-informatik (dot) ch
170
184
  executables: []
171
185
  extensions: []
172
186
  extra_rdoc_files: []
@@ -221,11 +235,11 @@ files:
221
235
  - lib/xapian_db/utilities.rb
222
236
  - tasks/spec.rake
223
237
  - tasks/xapian_rebuild_index.rake
224
- homepage: https://github.com/garaio/xapian_db
238
+ homepage: https://github.com/gernotkogler/xapian_db
225
239
  licenses:
226
240
  - MIT
227
241
  metadata: {}
228
- post_install_message:
242
+ post_install_message:
229
243
  rdoc_options:
230
244
  - "--line-numbers"
231
245
  - "--inline-source"
@@ -239,16 +253,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
253
  requirements:
240
254
  - - ">="
241
255
  - !ruby/object:Gem::Version
242
- version: '0'
256
+ version: 2.3.0
243
257
  required_rubygems_version: !ruby/object:Gem::Requirement
244
258
  requirements:
245
259
  - - ">="
246
260
  - !ruby/object:Gem::Version
247
261
  version: 1.3.6
248
262
  requirements: []
249
- rubyforge_project:
250
- rubygems_version: 2.2.2
251
- signing_key:
263
+ rubyforge_project:
264
+ rubygems_version: 2.7.6
265
+ signing_key:
252
266
  specification_version: 4
253
267
  summary: Ruby library to use a Xapian db as a key/value store with high performance
254
268
  fulltext search