xapian-full 1.1.3 → 1.1.3.1

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.
Files changed (5) hide show
  1. data/Rakefile +30 -22
  2. data/lib/xapian.rb +265 -0
  3. data/xapian-full.gemspec +34 -0
  4. metadata +5 -4
  5. data/extconf.rb +0 -32
data/Rakefile CHANGED
@@ -1,26 +1,34 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rubygems/ext'
1
+ require 'rbconfig'
2
+ c = Config::CONFIG
4
3
 
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = "xapian-full"
9
- gem.version = '1.1.3'
10
- gem.summary = %Q{xapian-core + Ruby xapian-bindings}
11
- gem.description = %Q{Xapian bindings for Ruby without dependency on system Xapian library}
12
- gem.email = "rlane@club.cc.cmu.edu"
13
- #gem.homepage = "http://gitorious.org/holizz-projects/xapian-ruby"
14
- gem.authors = ["Tom Adams", "Rich Lane"]
4
+ def system!(cmd)
5
+ puts cmd
6
+ system(cmd) or raise
7
+ end
8
+
9
+ ver = '1.1.3'
10
+ core = "xapian-core-#{ver}"
11
+ bindings = "xapian-bindings-#{ver}"
12
+ xapian_config = "#{Dir.pwd}/#{core}/xapian-config"
13
+
14
+ task :default do
15
+ [core,bindings].each do |x|
16
+ system! "tar -xzvf #{x}.tar.gz"
17
+ end
18
+
19
+ Dir.chdir core do
20
+ system! "./configure"
21
+ system! "make clean all"
22
+ end
15
23
 
16
- gem.files += Dir.glob(%w[
17
- extconf.rb
18
- Rakefile
19
- xapian*.tar.gz
20
- ])
24
+ Dir.chdir bindings do
25
+ ENV['RUBY'] ||= "#{c['bindir']}/#{c['RUBY_INSTALL_NAME']}"
26
+ ENV['XAPIAN_CONFIG'] = xapian_config
27
+ system! "./configure --with-ruby"
28
+ system! "make clean all"
29
+ end
21
30
 
22
- gem.extensions << 'extconf.rb'
23
- end
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
31
+ system! "mkdir -p lib"
32
+ system! "cp #{bindings}/ruby/.libs/_xapian.so lib"
33
+ system! "cp #{bindings}/ruby/xapian.rb lib"
26
34
  end
data/lib/xapian.rb ADDED
@@ -0,0 +1,265 @@
1
+ # :title:Ruby Xapian bindings
2
+ # =Ruby Xapian bindings
3
+ #
4
+ # Original version by Paul Legato (plegato@nks.net), 4/20/06.
5
+ #
6
+ # Copyright (C) 2006 Networked Knowledge Systems, Inc.
7
+ # Copyright (C) 2008 Olly Betts
8
+ #
9
+ # This program is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU General Public License as
11
+ # published by the Free Software Foundation; either version 2 of the
12
+ # License, or (at your option) any later version.
13
+ #
14
+ # This program is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with this program; if not, write to the Free Software
21
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22
+ # USA
23
+ #
24
+ # ==Underscore methods
25
+ # Note: Methods whose names start with an underscore character _ are internal
26
+ # methods from the C++ API. Their functionality is not accessible in a
27
+ # Ruby-friendly way, so this file provides wrapper code to make it easier to
28
+ # use them from a Ruby programming idiom. Most are also dangerous insofar as
29
+ # misusing them can cause your program to segfault. In particular, all of
30
+ # Xapian's *Iterator classes are wrapped into nice Ruby-friendly Arrays.
31
+ #
32
+ # It should never be necessary to use any method whose name starts with an
33
+ # underscore from user-level code. Make sure you are _VERY_ certain that you
34
+ # know exactly what you're doing if you do use one of these methods. Beware.
35
+ # You've been warned...
36
+ #
37
+
38
+
39
+ module Xapian
40
+ ######## load the SWIG-generated library
41
+ require '_xapian'
42
+
43
+
44
+ # iterate over two dangerous iterators (i.e. those that can cause segfaults
45
+ # if used improperly.)
46
+ # Return the results as an Array.
47
+ # Users should never need to use this method.
48
+ #
49
+ # Takes a block that returns some appropriate Ruby object to wrap the
50
+ # underlying Iterator
51
+ def _safelyIterate(dangerousStart, dangerousEnd) #:nodoc:
52
+ retval = Array.new
53
+
54
+ item = dangerousStart
55
+ lastTerm = dangerousEnd
56
+
57
+ return retval if dangerousStart.equals(dangerousEnd)
58
+
59
+ begin
60
+ retval.push(yield(item))
61
+ item.next()
62
+ end while not item.equals(lastTerm) # must use primitive C++ comparator
63
+
64
+ return retval
65
+ end # _safelyIterate
66
+ module_function :_safelyIterate
67
+
68
+ #--
69
+ ### safe Ruby wrapper for the dangerous C++ Xapian::TermIterator class
70
+ class Xapian::Term
71
+ attr_accessor :term, :wdf, :termfreq
72
+
73
+ def initialize(term, wdf=nil, termfreq=nil)
74
+ @term = term
75
+ @wdf = wdf
76
+ @termfreq = termfreq
77
+ end
78
+
79
+ def ==(other)
80
+ return other.is_a?(Xapian::Term) && other.term == @term && other.wdf == @wdf && other.termfreq == @termfreq
81
+ end
82
+ end # class Term
83
+
84
+ ### Ruby wrapper for a Match, i.e. a Xapian::MSetIterator (Match Set) in C++.
85
+ # it's no longer an iterator in the Ruby version, but we want to preserve its
86
+ # non-iterative data.
87
+ # (MSetIterator is not dangerous, but it is inconvenient to use from a Ruby
88
+ # idiom, so we wrap it..)
89
+ class Xapian::Match
90
+ attr_accessor :docid, :document, :rank, :weight, :collapse_count, :percent
91
+
92
+ def initialize(docid, document, rank, weight, collapse_count, percent)
93
+ @docid = docid
94
+ @document = document
95
+ @rank = rank
96
+ @weight = weight
97
+ @collapse_count = collapse_count
98
+ @percent = percent
99
+ end # initialize
100
+
101
+ def ==(other)
102
+ return other.is_a?(Xapian::Match) && other.docid == @docid && other.rank == @rank &&
103
+ other.weight == @weight && other.collapse_count == @collapse_count && other.percent == @percent
104
+ end
105
+
106
+ end # class Xapian::Match
107
+
108
+ # Ruby wrapper for an ExpandTerm, i.e. a Xapian::ESetIterator in C++
109
+ # Not dangerous, but inconvenient to use from a Ruby programming idiom, so we
110
+ # wrap it.
111
+ class Xapian::ExpandTerm
112
+ attr_accessor :name, :weight
113
+
114
+ def initialize(name, weight)
115
+ @name = name
116
+ @weight = weight
117
+ end # initialize
118
+
119
+ def ==(other)
120
+ return other.is_a?(Xapian::ExpandTerm) && other.name == @name && other.weight == @weight
121
+ end
122
+
123
+ end # Xapian::ExpandTerm
124
+
125
+ # Ruby wrapper for Xapian::ValueIterator
126
+ class Xapian::Value
127
+ attr_accessor :value, :valueno
128
+
129
+ def initialize(value, valueno)
130
+ @value = value
131
+ @valueno = valueno
132
+ end # initialize
133
+
134
+ def ==(other)
135
+ return other.is_a?(Xapian::Value) && other.value == @value && other.valueno == @valueno
136
+ end
137
+ end # Xapian::Value
138
+
139
+ #--
140
+ # Extend Xapian::Document with a nice wrapper for its nasty input_iterators
141
+ class Xapian::Document
142
+ def terms
143
+ Xapian._safelyIterate(self._dangerous_termlist_begin(), self._dangerous_termlist_end()) { |item|
144
+ Xapian::Term.new(item.term, item.wdf)
145
+ }
146
+ end # terms
147
+
148
+ def values
149
+ Xapian._safelyIterate(self._dangerous_values_begin(), self._dangerous_values_end()) { |item|
150
+ Xapian::Value.new(item.value, item.valueno)
151
+ }
152
+ end # terms
153
+
154
+ end # class Xapian::Document
155
+
156
+ #--
157
+ # Extend Xapian::Query with a nice wrapper for its dangerous iterators
158
+ class Xapian::Query
159
+ def terms
160
+ Xapian._safelyIterate(self._dangerous_terms_begin(), self._dangerous_terms_end()) { |item|
161
+ Xapian::Term.new(item.term, item.wdf)
162
+ # termfreq is not supported by TermIterators from Queries
163
+ }
164
+ end
165
+ end # Xapian::Query
166
+
167
+ #--
168
+ # Extend Xapian::Enquire with a nice wrapper for its dangerous iterators
169
+ class Xapian::Enquire
170
+ # Get matching terms for some document.
171
+ # document can be either a Xapian::DocID or a Xapian::MSetIterator
172
+ def matching_terms(document)
173
+ Xapian._safelyIterate(self._dangerous_matching_terms_begin(document),
174
+ self._dangerous_matching_terms_end(document)) { |item|
175
+ Xapian::Term.new(item.term, item.wdf)
176
+ }
177
+ end
178
+ end # Xapian::Enquire
179
+
180
+ # MSetIterators are not dangerous, just inconvenient to use within a Ruby
181
+ # programming idiom. So we wrap them.
182
+ class Xapian::MSet
183
+ def matches
184
+ Xapian._safelyIterate(self._begin(),
185
+ self._end()) { |item|
186
+ Xapian::Match.new(item.docid, item.document, item.rank, item.weight, item.collapse_count, item.percent)
187
+ }
188
+
189
+ end # matches
190
+ end # Xapian::MSet
191
+
192
+ # ESetIterators are not dangerous, just inconvenient to use within a Ruby
193
+ # programming idiom. So we wrap them.
194
+ class Xapian::ESet
195
+ def terms
196
+ Xapian._safelyIterate(self._begin(),
197
+ self._end()) { |item|
198
+ # note: in the ExpandTerm wrapper, we implicitly rename
199
+ # ESetIterator#term() (defined in xapian.i) to ExpandTerm#term()
200
+ Xapian::ExpandTerm.new(item.term, item.weight)
201
+ }
202
+
203
+ end # terms
204
+ end # Xapian::ESet
205
+
206
+
207
+ #--
208
+ # Wrapper for the C++ class Xapian::PostingIterator
209
+ class Xapian::Posting
210
+ attr_accessor :docid, :doclength, :wdf
211
+
212
+ def initialize(docid, doclength, wdf)
213
+ @docid = docid
214
+ @doclength = doclength
215
+ @wdf = wdf
216
+ end
217
+
218
+ def ==(other)
219
+ return other.is_a?(Xapian::Posting) && other.docid == @docid && other.doclength == @doclength &&
220
+ other.wdf == @wdf
221
+ end
222
+ end # Xapian::Posting
223
+
224
+ #--
225
+ # Wrap some dangerous iterators..
226
+ class Xapian::Database
227
+ # Returns an Array of all Xapian::Terms for this database.
228
+ def allterms
229
+ Xapian._safelyIterate(self._dangerous_allterms_begin(),
230
+ self._dangerous_allterms_end()) { |item|
231
+ Xapian::Term.new(item.term, 0, item.termfreq)
232
+ }
233
+ end # allterms
234
+
235
+ # Returns an Array of Xapian::Postings for the given term.
236
+ # term is a string.
237
+ def postlist(term)
238
+ Xapian._safelyIterate(self._dangerous_postlist_begin(term),
239
+ self._dangerous_postlist_end(term)) { |item|
240
+ Xapian::Posting.new(item.docid, item.doclength, item.wdf)
241
+ }
242
+ end # postlist(term)
243
+
244
+ # Returns an Array of Terms for the given docid.
245
+ def termlist(docid)
246
+ Xapian._safelyIterate(self._dangerous_termlist_begin(docid),
247
+ self._dangerous_termlist_end(docid)) { |item|
248
+ Xapian::Term.new(item.term, item.wdf, item.termfreq)
249
+ }
250
+ end # termlist(docid)
251
+
252
+
253
+ # Returns an Array of Xapian::Termpos objects for the given term (a String)
254
+ # in the given docid.
255
+ def positionlist(docid, term)
256
+ Xapian._safelyIterate(self._dangerous_positionlist_begin(docid, term),
257
+ self._dangerous_positionlist_end(docid, term)) { |item|
258
+ item.termpos
259
+ }
260
+ end # positionlist
261
+
262
+ end # Xapian::Database
263
+
264
+
265
+ end # Xapian module
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{xapian-full}
5
+ s.version = "1.1.3.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tom Adams", "Rich Lane"]
9
+ s.date = %q{2009-12-21}
10
+ s.description = %q{Xapian bindings for Ruby without dependency on system Xapian library}
11
+ s.email = %q{rlane@club.cc.cmu.edu}
12
+ s.extensions = ["Rakefile"]
13
+ s.files = [
14
+ "lib/xapian.rb",
15
+ "Rakefile",
16
+ "xapian-bindings-1.1.3.tar.gz",
17
+ "xapian-core-1.1.3.tar.gz",
18
+ "xapian-full.gemspec",
19
+ ]
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.require_paths = ["lib"]
22
+ s.rubygems_version = %q{1.3.3}
23
+ s.summary = %q{xapian-core + Ruby xapian-bindings}
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 3
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ else
31
+ end
32
+ else
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian-full
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Adams
@@ -19,14 +19,15 @@ email: rlane@club.cc.cmu.edu
19
19
  executables: []
20
20
 
21
21
  extensions:
22
- - extconf.rb
22
+ - Rakefile
23
23
  extra_rdoc_files: []
24
24
 
25
25
  files:
26
+ - lib/xapian.rb
26
27
  - Rakefile
27
- - extconf.rb
28
28
  - xapian-bindings-1.1.3.tar.gz
29
29
  - xapian-core-1.1.3.tar.gz
30
+ - xapian-full.gemspec
30
31
  has_rdoc: true
31
32
  homepage:
32
33
  licenses: []
@@ -51,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  requirements: []
52
53
 
53
54
  rubyforge_project:
54
- rubygems_version: 1.3.3
55
+ rubygems_version: 1.3.5
55
56
  signing_key:
56
57
  specification_version: 3
57
58
  summary: xapian-core + Ruby xapian-bindings
data/extconf.rb DELETED
@@ -1,32 +0,0 @@
1
- require 'rbconfig'
2
-
3
- def system!(cmd)
4
- puts cmd
5
- system(cmd) or raise
6
- end
7
-
8
- ver = '1.1.3'
9
- core = "xapian-core-#{ver}"
10
- bindings = "xapian-bindings-#{ver}"
11
- xapian_config = "#{Dir.pwd}/#{core}/xapian-config"
12
-
13
- [core,bindings].each do |x|
14
- system! "tar -xzvf #{x}.tar.gz"
15
- end
16
-
17
- Dir.chdir core do
18
- system! "./configure"
19
- system! "make clean all"
20
- end
21
-
22
- Dir.chdir bindings do
23
- c = Config::CONFIG
24
- ENV['RUBY'] ||= "#{c['bindir']}/#{c['RUBY_INSTALL_NAME']}"
25
- ENV['XAPIAN_CONFIG'] = xapian_config
26
- system! "./configure --with-ruby"
27
- system! "make clean all"
28
- end
29
-
30
- system! "mkdir -p lib"
31
- system! "cp #{bindings}/ruby/.libs/_xapian.so lib"
32
- system! "cp #{bindings}/ruby/xapian.rb lib"