xapian-fu 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWQ0ZTRhYmZlNmM5MWVlMWJmMjg1OTViNjYyNTBjYTc4NGMyYjlkMQ==
4
+ YTU3ZmE1ZDAxMjgwZWQ1OTgzMDRlNGIwYWUwZTAyNmE3ODRlMTY3NQ==
5
5
  data.tar.gz: !binary |-
6
- MGEyZjY2MDcxMTRjNWY4NjQ4ZDllNDAyYjY0Y2MzOTBmODg4ZTRmNA==
6
+ OWYzOTNiYjVmOTMzZTVjNDZhYWU5MjQ1NDMzMzM3ZWM1OTlkMzA4NQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGVhZDMyNzM4YzU3MDVkZDQwZDkwZTQ0NTdjZWM3N2U2YzM4Mjk2ZjExNWU3
10
- NDA2MjI3N2YyNzEzNGY5NWNhZWYzMjZjYjViYzBjYmJjNTdjZmQ3YTUzOWFj
11
- ZWFmMDI2OGFmOWVmNTMyYmE5OTI2MzgwMmNkNzM0NmZlMTZjOTM=
9
+ MTZhNWNjMmY1ZGI2ODIwNjM1ZTdmNTRjNjNjMzczYzNmOGY1OTg4NjA1NzM2
10
+ N2E4MThmZDU2ZGRiYjFkYmJlMjg4NjExMmM3NGZlM2UzZmFhZWNlOTk3YTIy
11
+ MTAzYmU3ZDA1ZjRiODk1OGY0ZTJkZWVhMDMyMjM3NjI4OWE0M2Y=
12
12
  data.tar.gz: !binary |-
13
- MGUxNWFjYzAxMWNiZmU5ZGRkYWI2YTVjOThlYjk5Y2EwMjQ4ZjE4ZTE5MjUw
14
- ZDFjODA2NDQ3ZGRhMDAyNzg1ZmFmY2EyNTAwMmFmNDk0NjdjNjI5NzI5NTRj
15
- OGY2MDAxYjUxOTJkNzQ4NTEyMTZhYmEwMDQzMTU0MDQ4ZDdlNGM=
13
+ NmVlMzRlZGNlMmVjNjkwMjYzMzliNmM2OTY5MWE5ZjZkZDM1Y2QxMGU5OGI5
14
+ NzU2M2MzYjkxYzljMWEwZGRmYjk0Mjc3MzY1ODlhNzdjMmFiMzg2ODZjZmYw
15
+ MTJiYjc1ZTZjZTc5Nzk3NDgxZjFlOWZkMTU4ZmZhYjNjNmM3YjM=
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.5.3 (19th February 2015)
2
+
3
+ * Added support for indexing multiple terms without stemming (`:exact`).
4
+
1
5
  === 1.5.2 (25th July 2014)
2
6
 
3
7
  * Added `XapianDb#close` to close both the read and write databases.
@@ -1,3 +1,3 @@
1
1
  module XapianFu #:nodoc:
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.3"
3
3
  end
@@ -137,6 +137,7 @@ module XapianFu #:nodoc:
137
137
  # Whether this db will generate a spelling dictionary during indexing
138
138
  attr_reader :spelling
139
139
  attr_reader :sortable_fields
140
+ attr_reader :field_options
140
141
  attr_accessor :weights_function
141
142
  attr :field_weights
142
143
 
@@ -151,6 +152,7 @@ module XapianFu #:nodoc:
151
152
  @language = @options.fetch(:language, :english)
152
153
  @stemmer = @options.fetch(:stemmer, @language)
153
154
  @stopper = @options.fetch(:stopper, @language)
155
+ @field_options = {}
154
156
  setup_fields(@options[:fields])
155
157
  @store_values << @options[:store]
156
158
  @store_values << @options[:sortable]
@@ -444,6 +446,7 @@ module XapianFu #:nodoc:
444
446
  @boolean_fields << name if opts[:boolean]
445
447
  @fields[name] = opts[:type]
446
448
  @field_weights[name] = opts[:weight] if opts.include?(:weight)
449
+ @field_options[name] = opts
447
450
  end
448
451
  @fields
449
452
  end
@@ -268,19 +268,33 @@ module XapianFu #:nodoc:
268
268
  tg.stemmer = stemmer
269
269
  tg.set_flags Xapian::TermGenerator::FLAG_SPELLING if db.spelling
270
270
  index_method = db.index_positions ? :index_text : :index_text_without_positions
271
- fields.each do |k,v|
271
+ fields.each do |k,o|
272
272
  next if unindexed_fields.include?(k)
273
- if v.respond_to?(:to_xapian_fu_string)
274
- v = v.to_xapian_fu_string
273
+
274
+ if db.fields[k] == Array
275
+ values = Array(o)
275
276
  else
276
- v = v.to_s
277
+ values = [o]
278
+ end
279
+
280
+ values.each do |v|
281
+ if v.respond_to?(:to_xapian_fu_string)
282
+ v = v.to_xapian_fu_string
283
+ else
284
+ v = v.to_s
285
+ end
286
+
287
+ # get the custom term weight if a weights function exists
288
+ weight = db.weights_function ? db.weights_function.call(k, v, fields).to_i : db.field_weights[k]
289
+ # add value with field name
290
+ tg.send(index_method, v, weight, 'X' + k.to_s.upcase)
291
+ # add value without field name
292
+ tg.send(index_method, v, weight)
293
+
294
+ if db.field_options[k] && db.field_options[k][:exact]
295
+ xapian_document.add_term("X#{k.to_s.upcase}#{v.to_s.downcase}", weight)
296
+ end
277
297
  end
278
- # get the custom term weight if a weights function exists
279
- weight = db.weights_function ? db.weights_function.call(k, v, fields).to_i : db.field_weights[k]
280
- # add value with field name
281
- tg.send(index_method, v, weight, 'X' + k.to_s.upcase)
282
- # add value without field name
283
- tg.send(index_method, v, weight)
284
298
  end
285
299
 
286
300
  db.boolean_fields.each do |name|
@@ -289,6 +289,23 @@ describe XapianDb do
289
289
  xdb.search("red").map(&:id).should == [1, 2]
290
290
  end
291
291
 
292
+ it "should index arrays with exact option" do
293
+ xdb = XapianDb.new(:dir => tmp_dir, :create => true,
294
+ :fields => {
295
+ :colors => { :index => true, :type => Array, :exact => true }
296
+ })
297
+
298
+ xdb << {:colors => ["light blue", "red"]}
299
+
300
+ xdb.flush
301
+
302
+ doc = xdb.documents.find(1)
303
+
304
+ terms = doc.terms.map(&:term)
305
+
306
+ terms.should include("XCOLORSlight blue")
307
+ terms.should include("XCOLORSred")
308
+ end
292
309
  end
293
310
 
294
311
  describe "search" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach