xapian-full-alaveteli 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rbconfig'
2
+ c = Config::CONFIG
3
+
4
+ def system!(cmd)
5
+ puts cmd
6
+ system(cmd) or raise
7
+ end
8
+
9
+ ver = '1.2.9'
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
+ prefix = Dir.pwd
20
+
21
+ system! "mkdir -p lib"
22
+
23
+ Dir.chdir core do
24
+ system! "./configure --prefix=#{prefix} --exec-prefix=#{prefix}"
25
+ ENV['LDFLAGS'] = "-R#{prefix}/lib"
26
+ system! "make clean all"
27
+ ENV['LDFLAGS'] = ""
28
+ system! "cp -RL .libs/* ../lib/"
29
+ end
30
+
31
+ Dir.chdir bindings do
32
+ ENV['RUBY'] ||= "#{c['bindir']}/#{c['RUBY_INSTALL_NAME']}"
33
+ ENV['XAPIAN_CONFIG'] = xapian_config
34
+ system! "./configure --prefix=#{prefix} --exec-prefix=#{prefix} --with-ruby"
35
+ ENV['LDFLAGS'] = "-R#{prefix}/lib"
36
+ system! "make clean all"
37
+ ENV['LDFLAGS'] = ""
38
+ end
39
+
40
+ system! "cp -RL #{bindings}/ruby/.libs/_xapian.* lib"
41
+ system! "cp #{bindings}/ruby/xapian.rb lib"
42
+ 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
Binary file
Binary file
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{xapian-full-alaveteli}
5
+ s.version = "1.2.9"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tom Adams", "Rich Lane", "Seb Bacon"]
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.2.9.tar.gz",
17
+ "xapian-core-1.2.9.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 ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xapian-full-alaveteli
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 9
10
+ version: 1.2.9
11
+ platform: ruby
12
+ authors:
13
+ - Tom Adams
14
+ - Rich Lane
15
+ - Seb Bacon
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2009-12-21 00:00:00 +00:00
21
+ default_executable:
22
+ dependencies: []
23
+
24
+ description: Xapian bindings for Ruby without dependency on system Xapian library
25
+ email: rlane@club.cc.cmu.edu
26
+ executables: []
27
+
28
+ extensions:
29
+ - Rakefile
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - lib/xapian.rb
34
+ - Rakefile
35
+ - xapian-bindings-1.2.9.tar.gz
36
+ - xapian-core-1.2.9.tar.gz
37
+ - xapian-full.gemspec
38
+ has_rdoc: true
39
+ homepage:
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.6.2
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: xapian-core + Ruby xapian-bindings
72
+ test_files: []
73
+