xapian-fu 1.0.1 → 1.1.0
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/README.rdoc +2 -0
- data/examples/spider.rb +3 -3
- data/lib/xapian-fu.rb +1 -0
- data/lib/xapian_fu/xapian_db.rb +2 -2
- data/lib/xapian_fu/xapian_doc_value_accessor.rb +40 -24
- data/lib/xapian_fu/xapian_documents_accessor.rb +2 -2
- data/spec/build_db_for_value_testing.rb +24 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/flintlock +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/iamflint +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/position.DB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/position.baseA +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/position.baseB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/postlist.DB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/postlist.baseA +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/postlist.baseB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/record.DB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/record.baseA +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/record.baseB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/termlist.DB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/termlist.baseA +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/termlist.baseB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/value.DB +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/value.baseA +0 -0
- data/spec/fixtures/film_data/i486-linux~1.8.7/value.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/flintlock +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/iamflint +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/position.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/position.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/position.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/record.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/record.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/record.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/value.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/value.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.8.7/value.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/flintlock +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/iamflint +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/position.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/position.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/position.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/record.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/record.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/record.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.baseB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/value.DB +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/value.baseA +0 -0
- data/spec/fixtures/film_data/x86_64-linux~1.9.1/value.baseB +0 -0
- data/spec/fixtures/film_data.rb +5 -0
- data/spec/stopper_factory_spec.rb +1 -0
- data/spec/xapian_doc_spec.rb +2 -1
- data/spec/xapian_doc_value_accessor_spec.rb +50 -11
- metadata +56 -2
data/README.rdoc
CHANGED
|
@@ -32,6 +32,8 @@ added to a Xapian database.
|
|
|
32
32
|
Create a database, add 3 documents to it and then search and retrieve
|
|
33
33
|
them.
|
|
34
34
|
|
|
35
|
+
require 'xapian-fu'
|
|
36
|
+
include XapianFu
|
|
35
37
|
db = XapianDb.new(:dir => 'example.db', :create => true,
|
|
36
38
|
:store => [:title, :year])
|
|
37
39
|
db << { :title => 'Brokeback Mountain', :year => 2005 }
|
data/examples/spider.rb
CHANGED
|
@@ -8,7 +8,7 @@ require 'rubygems'
|
|
|
8
8
|
require 'benchmark'
|
|
9
9
|
require 'lib/xapian_fu'
|
|
10
10
|
|
|
11
|
-
db = XapianFu::XapianDb.new(:
|
|
11
|
+
db = XapianFu::XapianDb.new(:store => [:filename, :filesize],
|
|
12
12
|
:overwrite => true)
|
|
13
13
|
|
|
14
14
|
base_path = ARGV[0] || '.'
|
|
@@ -31,12 +31,12 @@ while dir = index_queue.shift
|
|
|
31
31
|
next
|
|
32
32
|
end
|
|
33
33
|
next unless File.file?(filename)
|
|
34
|
-
next unless filename =~ /(txt|doc|README|c|h|pl|sh|rb|py|note|xml)$/i
|
|
34
|
+
next unless filename =~ /(txt|doc|README|c|cpp|h|pl|sh|rb|py|note|xml)$/i
|
|
35
35
|
file_count += 1
|
|
36
36
|
|
|
37
37
|
# Read the first 10k of data
|
|
38
38
|
text = File.open(filename) { |f| f.read(10 * 1024) }
|
|
39
|
-
file_data += text.size
|
|
39
|
+
file_data += text.to_s.size
|
|
40
40
|
# Index the data, filename and filesize
|
|
41
41
|
bm = Benchmark.measure do
|
|
42
42
|
db << {
|
data/lib/xapian-fu.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'xapian_fu'
|
data/lib/xapian_fu/xapian_db.rb
CHANGED
|
@@ -196,7 +196,7 @@ module XapianFu #:nodoc:
|
|
|
196
196
|
enquiry = Xapian::Enquire.new(ro)
|
|
197
197
|
setup_ordering(enquiry, options[:order], options[:reverse])
|
|
198
198
|
if options[:collapse]
|
|
199
|
-
enquiry.collapse_key = options[:collapse]
|
|
199
|
+
enquiry.collapse_key = XapianDocValueAccessor.value_key(options[:collapse])
|
|
200
200
|
end
|
|
201
201
|
enquiry.query = query
|
|
202
202
|
ResultSet.new(:mset => enquiry.mset(offset, per_page), :current_page => page + 1,
|
|
@@ -268,7 +268,7 @@ module XapianFu #:nodoc:
|
|
|
268
268
|
enquiry.sort_by_value!((1 << 32)-1, reverse)
|
|
269
269
|
enquiry.docid_order = reverse ? Xapian::Enquire::DESCENDING : Xapian::Enquire::ASCENDING
|
|
270
270
|
elsif order.is_a? String or order.is_a? Symbol
|
|
271
|
-
enquiry.sort_by_value!(order
|
|
271
|
+
enquiry.sort_by_value!(XapianDocValueAccessor.value_key(order), reverse)
|
|
272
272
|
else
|
|
273
273
|
enquiry.sort_by_relevance!
|
|
274
274
|
end
|
|
@@ -1,55 +1,73 @@
|
|
|
1
|
+
require 'zlib'
|
|
2
|
+
|
|
1
3
|
class Integer #:nodoc:
|
|
2
|
-
def to_xapian_fu_storage_value
|
|
3
|
-
[
|
|
4
|
+
def self.to_xapian_fu_storage_value(value)
|
|
5
|
+
[value].pack("G")
|
|
4
6
|
end
|
|
5
7
|
|
|
6
8
|
def self.from_xapian_fu_storage_value(value)
|
|
7
|
-
value.unpack("
|
|
9
|
+
value.unpack("G").first.truncate rescue nil
|
|
8
10
|
end
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
class Bignum #:nodoc:
|
|
12
|
-
def to_xapian_fu_storage_value
|
|
13
|
-
|
|
14
|
+
def self.to_xapian_fu_storage_value(value)
|
|
15
|
+
if value > 0x1fffffffffffff or value < -0x1fffffffffffff
|
|
16
|
+
raise XapianFu::ValueOutOfBounds
|
|
17
|
+
end
|
|
18
|
+
[value].pack("G")
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
def self.from_xapian_fu_storage_value(value)
|
|
17
|
-
value.unpack("G").first
|
|
22
|
+
value.unpack("G").first.truncate rescue nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Fixnum #:nodoc:
|
|
27
|
+
def self.to_xapian_fu_storage_value(value)
|
|
28
|
+
[value].pack("G")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.from_xapian_fu_storage_value(value)
|
|
32
|
+
value.unpack("G").first.truncate rescue nil
|
|
18
33
|
end
|
|
19
34
|
end
|
|
20
35
|
|
|
21
36
|
class Float #:nodoc:
|
|
22
|
-
def to_xapian_fu_storage_value
|
|
23
|
-
[
|
|
37
|
+
def self.to_xapian_fu_storage_value(value)
|
|
38
|
+
[value].pack("G")
|
|
24
39
|
end
|
|
25
40
|
|
|
26
41
|
def self.from_xapian_fu_storage_value(value)
|
|
27
|
-
value.unpack("G").first
|
|
42
|
+
value.unpack("G").first rescue nil
|
|
28
43
|
end
|
|
29
44
|
end
|
|
30
45
|
|
|
31
46
|
class Time #:nodoc:
|
|
32
|
-
def to_xapian_fu_storage_value
|
|
33
|
-
[
|
|
47
|
+
def self.to_xapian_fu_storage_value(value)
|
|
48
|
+
[value.utc.to_f].pack("G")
|
|
34
49
|
end
|
|
35
50
|
|
|
36
51
|
def self.from_xapian_fu_storage_value(value)
|
|
37
|
-
Time.at(value.unpack("G").first)
|
|
52
|
+
Time.at(value.unpack("G").first) rescue nil
|
|
38
53
|
end
|
|
39
54
|
end
|
|
40
55
|
|
|
41
56
|
class Date #:nodoc:
|
|
42
|
-
def to_xapian_fu_storage_value
|
|
43
|
-
to_s
|
|
57
|
+
def self.to_xapian_fu_storage_value(value)
|
|
58
|
+
value.to_s
|
|
44
59
|
end
|
|
45
60
|
|
|
46
61
|
def self.from_xapian_fu_storage_value(value)
|
|
47
|
-
self.parse(value)
|
|
62
|
+
self.parse(value) rescue nil
|
|
48
63
|
end
|
|
49
64
|
end
|
|
50
65
|
|
|
51
66
|
module XapianFu #:nodoc:
|
|
52
67
|
|
|
68
|
+
class ValueOutOfBounds < XapianFuError
|
|
69
|
+
end
|
|
70
|
+
|
|
53
71
|
# A XapianDocValueAccessor is used to provide the XapianDoc#values
|
|
54
72
|
# interface to read and write field values to a XapianDb. It is
|
|
55
73
|
# usually set up by a XapianDoc so you shouldn't need to set up your
|
|
@@ -67,12 +85,12 @@ module XapianFu #:nodoc:
|
|
|
67
85
|
# <tt>from_xapian_fu_storage_value</tt> class method on retrieval.
|
|
68
86
|
def store(key, value, type = nil)
|
|
69
87
|
type = @doc.db.fields[key] if type.nil? and @doc.db
|
|
70
|
-
if type and
|
|
71
|
-
converted_value =
|
|
88
|
+
if type and type.respond_to?(:to_xapian_fu_storage_value)
|
|
89
|
+
converted_value = type.to_xapian_fu_storage_value(value)
|
|
72
90
|
else
|
|
73
91
|
converted_value = value.to_s
|
|
74
92
|
end
|
|
75
|
-
@doc.xapian_document.add_value(value_key(key), converted_value)
|
|
93
|
+
@doc.xapian_document.add_value(XapianDocValueAccessor.value_key(key), converted_value)
|
|
76
94
|
value
|
|
77
95
|
end
|
|
78
96
|
alias_method "[]=", :store
|
|
@@ -92,7 +110,7 @@ module XapianFu #:nodoc:
|
|
|
92
110
|
# Due to the design of Xapian, if the value does not exist then an
|
|
93
111
|
# empty string is returned.
|
|
94
112
|
def fetch(key, type = nil)
|
|
95
|
-
value = @doc.xapian_document.value(value_key(key))
|
|
113
|
+
value = @doc.xapian_document.value(XapianDocValueAccessor.value_key(key))
|
|
96
114
|
type = @doc.db.fields[key] if type.nil? and @doc.db
|
|
97
115
|
if type and type.respond_to?(:from_xapian_fu_storage_value)
|
|
98
116
|
type.from_xapian_fu_storage_value(value)
|
|
@@ -110,16 +128,14 @@ module XapianFu #:nodoc:
|
|
|
110
128
|
# Remove the value with the given key from the XapianDoc and return it
|
|
111
129
|
def delete(key)
|
|
112
130
|
value = fetch(key)
|
|
113
|
-
@doc.xapian_document.remove_value(value_key(key))
|
|
131
|
+
@doc.xapian_document.remove_value(XapianDocValueAccessor.value_key(key))
|
|
114
132
|
value
|
|
115
133
|
end
|
|
116
134
|
|
|
117
|
-
private
|
|
118
|
-
|
|
119
135
|
# Convert the given key to an integer that can be used as a Xapian
|
|
120
136
|
# value number
|
|
121
|
-
def value_key(key)
|
|
122
|
-
key.is_a?(Integer) ? key : key.to_s
|
|
137
|
+
def self.value_key(key)
|
|
138
|
+
(key.is_a?(Integer) ? key : Zlib.crc32(key.to_s))
|
|
123
139
|
end
|
|
124
140
|
end
|
|
125
141
|
end
|
|
@@ -70,10 +70,10 @@ module XapianFu
|
|
|
70
70
|
find(@xdb.ro.lastdocid) rescue nil
|
|
71
71
|
else
|
|
72
72
|
# for other values, we do a search ordered by that key in descening order
|
|
73
|
-
query = Xapian::Query.new(Xapian::Query::OP_VALUE_GE, key
|
|
73
|
+
query = Xapian::Query.new(Xapian::Query::OP_VALUE_GE, XapianDocValueAccessor.value_key(key), "0")
|
|
74
74
|
e = Xapian::Enquire.new(@xdb.ro)
|
|
75
75
|
e.query = query
|
|
76
|
-
e.sort_by_value!(key
|
|
76
|
+
e.sort_by_value!(XapianDocValueAccessor.value_key(key))
|
|
77
77
|
r = e.mset(0, 1).matches.first
|
|
78
78
|
find(r.docid) rescue nil
|
|
79
79
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
require 'date'
|
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/xapian_fu')
|
|
6
|
+
include XapianFu
|
|
7
|
+
require File.join(File.dirname(__FILE__), 'fixtures/film_data')
|
|
8
|
+
require 'fileutils'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
db_name = [RUBY_PLATFORM, RUBY_VERSION].join('~')
|
|
12
|
+
db_path = File.join(File.dirname(__FILE__), 'fixtures/film_data')
|
|
13
|
+
FileUtils.mkdir_p db_path
|
|
14
|
+
db = XapianDb.new(:dir => File.join(db_path, db_name), :create => true,
|
|
15
|
+
:fields => {
|
|
16
|
+
:title => { :type => String, :store => true },
|
|
17
|
+
:released_on => { :type => Date, :store => true },
|
|
18
|
+
:revenue => { :type => Integer, :store => true }})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
FILM_DATA.each { |film| db << film }
|
|
23
|
+
|
|
24
|
+
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
FILM_DATA = []
|
|
3
|
+
FILM_DATA << { :title => "Cold Mountain", :released_on => Date.parse("2003/12/25"), :revenue => 173_013_509 }
|
|
4
|
+
FILM_DATA << { :title => "Brokeback Mountain", :released_on => Date.parse("2005/12/16"), :revenue => 178_062_759 }
|
|
5
|
+
FILM_DATA << { :title => "Yes Man", :released_on => Date.parse("2008/12/26"), :revenue => 301_455_191 }
|
data/spec/xapian_doc_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
1
2
|
require 'xapian'
|
|
2
3
|
require 'lib/xapian_fu.rb'
|
|
3
4
|
include XapianFu
|
|
@@ -109,7 +110,7 @@ describe XapianDoc do
|
|
|
109
110
|
:french => { "majestueusement" => "majestu" },
|
|
110
111
|
:swedish => { "kloekornas" => "kloek" },
|
|
111
112
|
:danish => { "indvendingerne" => "indvending" },
|
|
112
|
-
:russian => { "падшую"
|
|
113
|
+
:russian => { "падшую" => "падш" },
|
|
113
114
|
:italian => { "propagamento" => "propag" }
|
|
114
115
|
}
|
|
115
116
|
stems.keys.each do |lang|
|
|
@@ -2,9 +2,16 @@ require 'xapian'
|
|
|
2
2
|
require 'lib/xapian_fu.rb'
|
|
3
3
|
include XapianFu
|
|
4
4
|
require 'fileutils'
|
|
5
|
+
require 'fixtures/film_data'
|
|
5
6
|
|
|
6
7
|
describe XapianDocValueAccessor do
|
|
7
8
|
|
|
9
|
+
describe "value_key" do
|
|
10
|
+
it "should return the crc32 of the given string" do
|
|
11
|
+
XapianDocValueAccessor.value_key("louisa").should == 4040578532
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
8
15
|
it "should store and fetch values like a hash" do
|
|
9
16
|
values = XapianDocValueAccessor.new(XapianDoc.new(nil))
|
|
10
17
|
values.store(:city, "Leeds").should == "Leeds"
|
|
@@ -19,25 +26,38 @@ describe XapianDocValueAccessor do
|
|
|
19
26
|
lambda { values[:city] = "London" }.should change(doc.xapian_document, :values_count).by(1)
|
|
20
27
|
end
|
|
21
28
|
|
|
22
|
-
it "should store fields defined as Fixnum as packed
|
|
29
|
+
it "should store fields defined as Fixnum as packed double-precision float, network byte order" do
|
|
23
30
|
xdb = XapianDb.new(:fields => { :number => { :type => Fixnum, :store => true } })
|
|
24
|
-
[-83883, 256532, 0,
|
|
31
|
+
[-83883, 256532, 0, 0xffffff].each do |number|
|
|
25
32
|
doc = xdb.documents.new(:number => number)
|
|
26
33
|
doc.values.store(:number, number, Fixnum).should == number
|
|
27
34
|
doc.values.fetch(:number, Fixnum).should == number
|
|
28
|
-
doc.to_xapian_document.values.first.value.should == [number].pack("
|
|
35
|
+
doc.to_xapian_document.values.first.value.should == [number].pack("G")
|
|
29
36
|
end
|
|
30
37
|
end
|
|
31
38
|
|
|
32
|
-
it "should store fields defined as Bignum as packed
|
|
39
|
+
it "should store fields defined as Bignum as packed double-precision float, network byte order" do
|
|
33
40
|
xdb = XapianDb.new(:fields => { :number => { :type => Bignum, :store => true } })
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
[
|
|
42
|
+
(-0x1fffffffffffff..-0x1fffffffffffff + 10).to_a,
|
|
43
|
+
(0x1fffffffffffff-10..0x1fffffffffffff).to_a
|
|
44
|
+
].flatten.each do |number|
|
|
45
|
+
doc = xdb.documents.new(:number => number)
|
|
46
|
+
doc.values.store(:number, number, Bignum).should == number
|
|
47
|
+
doc.values.fetch(:number, Bignum).should == number
|
|
48
|
+
doc.to_xapian_document.values.first.value.should == [number].pack("G")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should raise an error when attempting to store Bignum values bigger or smaller than can be stored" do
|
|
53
|
+
xdb = XapianDb.new(:fields => { :number => { :type => Bignum, :store => true } })
|
|
54
|
+
[-(0x1fffffffffffff+1), 0x1fffffffffffff+1].each do |number|
|
|
55
|
+
doc = xdb.documents.new(:number => number)
|
|
56
|
+
lambda { doc.values.store(:number, number, Bignum) }.should raise_error XapianFu::ValueOutOfBounds
|
|
57
|
+
end
|
|
38
58
|
end
|
|
39
59
|
|
|
40
|
-
it "should store fields defined as Float as packed
|
|
60
|
+
it "should store fields defined as Float as packed double-precision float, network byte order" do
|
|
41
61
|
xdb = XapianDb.new(:fields => { :number => { :type => Float, :store => true } })
|
|
42
62
|
[-0.303393984588383833, 8.448488388488384, 1.0].each do |number|
|
|
43
63
|
doc = xdb.documents.new(:number => number)
|
|
@@ -47,12 +67,12 @@ describe XapianDocValueAccessor do
|
|
|
47
67
|
end
|
|
48
68
|
end
|
|
49
69
|
|
|
50
|
-
it "should store fields defined as Time in UTC as packed
|
|
70
|
+
it "should store fields defined as Time in UTC as packed double-precision float, network byte order" do
|
|
51
71
|
xdb = XapianDb.new(:fields => { :created_at => { :type => Time, :store => true }})
|
|
52
72
|
time = Time.now
|
|
53
73
|
doc = xdb.documents.new(:created_at => time)
|
|
54
74
|
doc.values.store(:created_at, time).should == time
|
|
55
|
-
doc.values.fetch(:created_at).should
|
|
75
|
+
doc.values.fetch(:created_at).should be_close(time, 0.0001) # ignore milliseconds
|
|
56
76
|
doc.to_xapian_document.values.first.value.should == [time.utc.to_f].pack("G")
|
|
57
77
|
end
|
|
58
78
|
|
|
@@ -87,6 +107,25 @@ describe XapianDocValueAccessor do
|
|
|
87
107
|
doc.values.delete(:city).should == "London"
|
|
88
108
|
end
|
|
89
109
|
|
|
110
|
+
film_data_path = File.join(File.dirname(__FILE__), "fixtures/film_data")
|
|
111
|
+
Dir.foreach(film_data_path) do |db_path|
|
|
112
|
+
next unless db_path =~ /.+~.+/
|
|
113
|
+
it "should read stored values from databases created by #{db_path}" do
|
|
114
|
+
db = XapianDb.new(:dir => File.join(film_data_path, db_path),
|
|
115
|
+
:fields => {
|
|
116
|
+
:title => { :type => String, :store => true },
|
|
117
|
+
:released_on => { :type => Date, :store => true },
|
|
118
|
+
:revenue => { :type => Integer, :store => true }
|
|
119
|
+
})
|
|
120
|
+
FILM_DATA.size.times do |i|
|
|
121
|
+
doc = db.documents[i+1]
|
|
122
|
+
[:title, :released_on, :revenue].each do |field|
|
|
123
|
+
doc.values[field].should === FILM_DATA[i][field]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
90
129
|
end
|
|
91
130
|
|
|
92
131
|
|
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.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Leach
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-12-13 00:00:00 +00:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -23,6 +23,7 @@ extra_rdoc_files:
|
|
|
23
23
|
- README.rdoc
|
|
24
24
|
- LICENSE
|
|
25
25
|
files:
|
|
26
|
+
- lib/xapian-fu.rb
|
|
26
27
|
- lib/xapian_fu.rb
|
|
27
28
|
- lib/xapian_fu/result_set.rb
|
|
28
29
|
- lib/xapian_fu/stopper_factory.rb
|
|
@@ -87,7 +88,60 @@ summary: A Ruby interface to the Xapian search engine
|
|
|
87
88
|
test_files:
|
|
88
89
|
- spec/stopper_factory_spec.rb
|
|
89
90
|
- spec/xapian_doc_spec.rb
|
|
91
|
+
- spec/build_db_for_value_testing.rb
|
|
90
92
|
- spec/xapian_db_spec.rb
|
|
93
|
+
- spec/fixtures/film_data.rb
|
|
94
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/position.baseA
|
|
95
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/flintlock
|
|
96
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/record.baseA
|
|
97
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.baseB
|
|
98
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/position.baseB
|
|
99
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/position.DB
|
|
100
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/record.baseB
|
|
101
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.DB
|
|
102
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.baseB
|
|
103
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/record.DB
|
|
104
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/iamflint
|
|
105
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.baseA
|
|
106
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/value.DB
|
|
107
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/termlist.baseA
|
|
108
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/postlist.DB
|
|
109
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/value.baseA
|
|
110
|
+
- spec/fixtures/film_data/x86_64-linux~1.8.7/value.baseB
|
|
111
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/position.baseA
|
|
112
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/flintlock
|
|
113
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/record.baseA
|
|
114
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.baseB
|
|
115
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/position.baseB
|
|
116
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/position.DB
|
|
117
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/record.baseB
|
|
118
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.DB
|
|
119
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.baseB
|
|
120
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/record.DB
|
|
121
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/iamflint
|
|
122
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.baseA
|
|
123
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/value.DB
|
|
124
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/termlist.baseA
|
|
125
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/postlist.DB
|
|
126
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/value.baseA
|
|
127
|
+
- spec/fixtures/film_data/x86_64-linux~1.9.1/value.baseB
|
|
128
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/position.baseA
|
|
129
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/flintlock
|
|
130
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/record.baseA
|
|
131
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/termlist.baseB
|
|
132
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/position.baseB
|
|
133
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/position.DB
|
|
134
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/record.baseB
|
|
135
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/termlist.DB
|
|
136
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/postlist.baseB
|
|
137
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/record.DB
|
|
138
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/iamflint
|
|
139
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/postlist.baseA
|
|
140
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/value.DB
|
|
141
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/termlist.baseA
|
|
142
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/postlist.DB
|
|
143
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/value.baseA
|
|
144
|
+
- spec/fixtures/film_data/i486-linux~1.8.7/value.baseB
|
|
91
145
|
- spec/query_parser_spec.rb
|
|
92
146
|
- spec/xapian_doc_value_accessor_spec.rb
|
|
93
147
|
- spec/spec.opts
|