xapian-fu 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 1.3.2 (4th December 2011)
2
+
3
+ * Number range queries (Damian Janowski)
4
+
1
5
  === 1.3.1 (12th October 2011)
2
6
 
3
7
  * Fix casting of values on search. (Damian Janowski)
@@ -96,6 +96,15 @@ module XapianFu #:nodoc:
96
96
  fields.each do |name, type|
97
97
  qp.add_prefix(name.to_s.downcase, "X" + name.to_s.upcase)
98
98
  end
99
+
100
+ database.sortable_fields.each do |field, opts|
101
+ if opts[:range_prefix]
102
+ qp.add_valuerangeprocessor(Xapian::NumberValueRangeProcessor.new(XapianDocValueAccessor.value_key(field), opts[:range_prefix], true))
103
+ else
104
+ qp.add_valuerangeprocessor(Xapian::NumberValueRangeProcessor.new(XapianDocValueAccessor.value_key(field), opts[:range_postfix], false))
105
+ end
106
+ end if database
107
+
99
108
  @query_parser = qp
100
109
  end
101
110
  end
@@ -0,0 +1,3 @@
1
+ module XapianFu #:nodoc:
2
+ VERSION = "1.3.2"
3
+ end
@@ -114,6 +114,7 @@ module XapianFu #:nodoc:
114
114
  attr_reader :unindexed_fields
115
115
  # Whether this db will generate a spelling dictionary during indexing
116
116
  attr_reader :spelling
117
+ attr_reader :sortable_fields
117
118
 
118
119
  def initialize( options = { } )
119
120
  @options = { :index_positions => true, :spelling => true }.merge(options)
@@ -315,8 +316,9 @@ module XapianFu #:nodoc:
315
316
  @fields = { }
316
317
  @unindexed_fields = []
317
318
  @store_values = []
319
+ @sortable_fields = {}
318
320
  return nil if field_options.nil?
319
- default_opts = {
321
+ default_opts = {
320
322
  :store => true,
321
323
  :index => true,
322
324
  :type => String
@@ -332,6 +334,7 @@ module XapianFu #:nodoc:
332
334
  opts = { :type => opts } unless opts.is_a? Hash
333
335
  opts = default_opts.merge(opts)
334
336
  @store_values << name if opts[:store]
337
+ @sortable_fields[name] = {:range_prefix => opts[:range_prefix], :range_postfix => opts[:range_postfix]} if opts[:sortable]
335
338
  @unindexed_fields << name if opts[:index] == false
336
339
  @fields[name] = opts[:type]
337
340
  end
@@ -85,11 +85,17 @@ module XapianFu #:nodoc:
85
85
  # <tt>from_xapian_fu_storage_value</tt> class method on retrieval.
86
86
  def store(key, value, type = nil)
87
87
  type = @doc.db.fields[key] if type.nil? and @doc.db
88
- if type and type.respond_to?(:to_xapian_fu_storage_value)
89
- converted_value = type.to_xapian_fu_storage_value(value)
88
+
89
+ if @doc.db && @doc.db.sortable_fields.include?(key)
90
+ converted_value = Xapian.sortable_serialise(value)
90
91
  else
91
- converted_value = value.to_s
92
+ if type and type.respond_to?(:to_xapian_fu_storage_value)
93
+ converted_value = type.to_xapian_fu_storage_value(value)
94
+ else
95
+ converted_value = value.to_s
96
+ end
92
97
  end
98
+
93
99
  @doc.xapian_document.add_value(XapianDocValueAccessor.value_key(key), converted_value)
94
100
  value
95
101
  end
@@ -444,6 +444,30 @@ describe XapianDb do
444
444
  doc.values.fetch(:age).should == "32"
445
445
  end
446
446
 
447
+ it "should allow range searches on sortable values with prefixes" do
448
+ xdb = XapianDb.new(:fields => { :price => { :type => Integer, :sortable => true, :range_prefix => "$" } })
449
+
450
+ xdb << XapianDoc.new(:price => 10)
451
+ xdb << XapianDoc.new(:price => 20)
452
+ xdb << XapianDoc.new(:price => 15)
453
+
454
+ docs = xdb.search("$10..15")
455
+
456
+ docs.map { |d| d.id }.should == [1, 3]
457
+ end
458
+
459
+ it "should allow range searches on sortable values with postfixes" do
460
+ xdb = XapianDb.new(:fields => { :age => { :type => Integer, :sortable => true, :range_postfix => "y" } })
461
+
462
+ xdb << XapianDoc.new(:age => 32)
463
+ xdb << XapianDoc.new(:age => 40)
464
+ xdb << XapianDoc.new(:age => 35)
465
+
466
+ docs = xdb.search("32..35y")
467
+
468
+ docs.map { |d| d.id }.should == [1, 3]
469
+ end
470
+
447
471
  it "should store values declared as to be collapsible" do
448
472
  xdb = XapianDb.new(:collapsible => :group_id)
449
473
  xdb << XapianDoc.new(:group_id => "666", :author => "Jim Jones")
@@ -72,7 +72,7 @@ describe XapianDocValueAccessor do
72
72
  time = Time.now
73
73
  doc = xdb.documents.new(:created_at => time)
74
74
  doc.values.store(:created_at, time).should == time
75
- doc.values.fetch(:created_at).should be_close(time, 0.0001) # ignore milliseconds
75
+ doc.values.fetch(:created_at).should be_within(0.0001).of(time) # ignore milliseconds
76
76
  doc.to_xapian_document.values.first.value.should == [time.utc.to_f].pack("G")
77
77
  end
78
78
 
@@ -81,7 +81,7 @@ describe XapianDocValueAccessor do
81
81
  datetime = DateTime.now
82
82
  doc = xdb.documents.new(:created_at => datetime)
83
83
  doc.values.store(:created_at, datetime).should == datetime
84
- doc.values.fetch(:created_at).should be_close(datetime, 0.0001) # miliseconds are not stored
84
+ doc.values.fetch(:created_at).should be_within(0.0001).of(datetime) # miliseconds are not stored
85
85
  doc.to_xapian_document.values.first.value.should == datetime.to_s
86
86
  end
87
87
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian-fu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 1
10
- version: 1.3.1
9
+ - 2
10
+ version: 1.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Leach
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-12 00:00:00 Z
18
+ date: 2011-12-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -23,16 +23,44 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - "="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 27
28
+ hash: 19
29
29
  segments:
30
- - 1
31
- - 3
30
+ - 2
31
+ - 7
32
32
  - 0
33
- version: 1.3.0
33
+ version: 2.7.0
34
34
  type: :development
35
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rdoc
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
36
64
  description: A library to provide a more Ruby-like interface to the Xapian search engine.
37
65
  email: john@johnleach.co.uk
38
66
  executables: []
@@ -47,6 +75,7 @@ files:
47
75
  - lib/xapian_fu.rb
48
76
  - lib/xapian_fu/xapian_doc_value_accessor.rb
49
77
  - lib/xapian_fu/query_parser.rb
78
+ - lib/xapian_fu/version.rb
50
79
  - lib/xapian_fu/xapian_db.rb
51
80
  - lib/xapian_fu/xapian_documents_accessor.rb
52
81
  - lib/xapian_fu/xapian_doc.rb
@@ -133,7 +162,6 @@ files:
133
162
  - spec/xapian_doc_value_accessor_spec.rb
134
163
  - spec/build_db_for_value_testing.rb
135
164
  - spec/query_parser_spec.rb
136
- - spec/spec.opts
137
165
  homepage: http://github.com/johnl/xapian-fu
138
166
  licenses: []
139
167
 
@@ -230,4 +258,3 @@ test_files:
230
258
  - spec/xapian_doc_value_accessor_spec.rb
231
259
  - spec/build_db_for_value_testing.rb
232
260
  - spec/query_parser_spec.rb
233
- - spec/spec.opts
@@ -1,5 +0,0 @@
1
- --colour
2
- --format n
3
- --loadby mtime
4
- --reverse
5
-