xapian-fu 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c807d9e1a6c4ce62f3565aaae147f9bca5f2c037ccd39b51d8fda583544451
4
- data.tar.gz: 3e12b31653f3cc34914e13597f67af5c632e072fe622447c1da879b92be06ee4
3
+ metadata.gz: 6c5695db34da1fceed61e5dc6b5b8e997838e15b0bc50e3d3ff0991f8abeba0d
4
+ data.tar.gz: 3cb11fb4955a85a4ab55a09aa4d0575bb944effa9fd8c1f73ed068002d464c2d
5
5
  SHA512:
6
- metadata.gz: 47fda9c3e053b1c3e8dd8c9bfecca1ddba6499d9e35d49ad1a37d6b8e4b6710a8f28af88b7d1b4dd927132151df3811f520cdfac30ed8d1b96b3fe62c5abed04
7
- data.tar.gz: 628fcdb102e4ab3ed4dcd4fe7832d7a9c15c681085c9bc87251d927e0db9dd305b400617217eaa97dec13bcf9fd73a26811c36e207aa6e9ef86d98a32c242137
6
+ metadata.gz: 35e471dee5c7cdf52f7370c692c7f15e5da5ad82d0899f243c5dcb9036081ba207fbcf8bd9e0d4b6a6e8f21ed709fe08fc9d058bd04b4c4fbece0773587f4501
7
+ data.tar.gz: 26b8d54f4cea15bef6580f9a9cf00f4aefd2fc4d1dd97e53d0b600fb72a6b301aa9a9bcbb7b35e0f83b328f928fe375cee05926198ef92e3d22b7fe6325e7ea2
@@ -1,3 +1,8 @@
1
+ === 1.7.0 (22nd March 2020)
2
+
3
+ * Add support for setting stemmer_strategy
4
+ * Remove support for Ruby version < 2.1
5
+
1
6
  === 1.6.0 (7th October 2019)
2
7
 
3
8
  * Support newer versions of xapian
@@ -20,7 +20,7 @@ Hash with full text indexing (and ACID transactions).
20
20
  === Xapian Bindings
21
21
 
22
22
  Xapian Fu requires the Xapian Ruby bindings to be available. On
23
- Debian/Ubuntu, you can install the `libxapian-ruby1.8` package to get
23
+ Debian/Ubuntu, you can install the `ruby-xapian` package to get
24
24
  them. Alternatively, you can install the `xapian-ruby` gem, which
25
25
  reportedly will also provide them. You can also just get the
26
26
  upstream Xapian release and manually install it.
@@ -1,3 +1,3 @@
1
1
  module XapianFu #:nodoc:
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
@@ -38,6 +38,11 @@ module XapianFu #:nodoc:
38
38
  # XapianDb to wipe the current on-disk database and start afresh.
39
39
  # The default is <tt>false</tt>.
40
40
  #
41
+ # Setting the <tt>:type</tt> option to either :glass or :chert will force that
42
+ # database backend, if supported. Leave as nil to auto-detect existing
43
+ # databases and create new databases with the library default (recommended).
44
+ # Requires xapian >=1.4
45
+ #
41
46
  # db = XapianDb.new(:dir => '/tmp/mydb', :create => true)
42
47
  #
43
48
  # == Language, Stemmers and Stoppers
@@ -57,6 +62,10 @@ module XapianFu #:nodoc:
57
62
  #
58
63
  # db = XapianDb.new(:language => :italian, :stopper => false)
59
64
  #
65
+ # The <tt>:stopper_strategy</tt> option specifies the default stop strategy
66
+ # that will be used when indexing and can be: <tt>:none</tt>, <tt>:all</tt> or
67
+ # <tt>:stemmed</tt>. Defaults to <tt>:stemmed</tt>
68
+ #
60
69
  # == Spelling suggestions
61
70
  #
62
71
  # The <tt>:spelling</tt> option controls generation of a spelling
@@ -167,6 +176,8 @@ module XapianFu #:nodoc:
167
176
  attr_reader :field_options
168
177
  attr_accessor :weights_function
169
178
  attr :field_weights
179
+ # The default stopper strategy
180
+ attr_accessor :stopper_strategy
170
181
 
171
182
  def initialize( options = { } )
172
183
  @options = { :index_positions => true, :spelling => true }.merge(options)
@@ -175,10 +186,23 @@ module XapianFu #:nodoc:
175
186
  @db_flag = Xapian::DB_OPEN
176
187
  @db_flag = Xapian::DB_CREATE_OR_OPEN if @options[:create]
177
188
  @db_flag = Xapian::DB_CREATE_OR_OVERWRITE if @options[:overwrite]
189
+ case @options[:type]
190
+ when :glass
191
+ raise XapianFuError.new("type glass not recognised") unless defined?(Xapian::DB_BACKEND_GLASS)
192
+ @db_flag |= Xapian::DB_BACKEND_GLASS
193
+ when :chert
194
+ raise XapianFuError.new("type chert not recognised") unless defined?(Xapian::DB_BACKEND_CHERT)
195
+ @db_flag |= Xapian::DB_BACKEND_CHERT
196
+ when nil
197
+ # use library defaults
198
+ else
199
+ raise XapianFuError.new("type #{@options[:type].inspect} not recognised")
200
+ end
178
201
  @tx_mutex = Mutex.new
179
202
  @language = @options.fetch(:language, :english)
180
203
  @stemmer = @options.fetch(:stemmer, @language)
181
204
  @stopper = @options.fetch(:stopper, @language)
205
+ @stopper_strategy = @options.fetch(:stopper_strategy, :stemmed)
182
206
  @field_options = {}
183
207
  setup_fields(@options[:fields])
184
208
  @store_values << @options[:store]
@@ -227,6 +227,27 @@ module XapianFu #:nodoc:
227
227
  end
228
228
  end
229
229
 
230
+ STOPPER_STRATEGIES = {
231
+ :none => 0,
232
+ :all => 1,
233
+ :stemmed => 2
234
+ }
235
+
236
+ def stopper_strategy
237
+ if @stopper_strategy
238
+ @stopper_strategy
239
+ else
240
+ @stopper_strategy =
241
+ if ! @options[:stopper_strategy].nil?
242
+ @options[:stopper_strategy]
243
+ elsif db
244
+ db.stopper_strategy
245
+ else
246
+ :stemmed
247
+ end
248
+ end
249
+ end
250
+
230
251
  # Return this document's language which is set on initialize, inherited
231
252
  # from the database or defaults to :english
232
253
  def language
@@ -276,6 +297,7 @@ module XapianFu #:nodoc:
276
297
  tg.document = xapian_document
277
298
  tg.stopper = stopper if stopper
278
299
  tg.stemmer = stemmer
300
+ tg.set_stopper_strategy(XapianDoc::STOPPER_STRATEGIES.fetch(stopper_strategy, 2))
279
301
  tg.set_flags Xapian::TermGenerator::FLAG_SPELLING if db.spelling
280
302
  index_method = db.index_positions ? :index_text : :index_text_without_positions
281
303
  fields.each do |k,o|
@@ -38,6 +38,27 @@ describe XapianDb do
38
38
  File.exists?(tmp_dir).should be_true
39
39
  end
40
40
 
41
+ it "should create a glass database when type is glass" do
42
+ pending "this version of xapian doesn't support glass" unless defined?(Xapian::DB_BACKEND_GLASS)
43
+ glassdir = tmp_dir + 'glass'
44
+ XapianDb.new(:dir => glassdir, :create => true, :type => :glass).rw
45
+ File.exists?(glassdir + '/iamglass').should == true
46
+ end
47
+
48
+ it "should create a chert database when type is chert" do
49
+ pending "this version of xapian doesn't support chert" unless defined?(Xapian::DB_BACKEND_CHERT)
50
+ chertdir = tmp_dir + 'chert'
51
+ XapianDb.new(:dir => chertdir, :create => true, :type => :chert).rw
52
+ File.exists?(chertdir + '/iamchert').should == true
53
+ end
54
+
55
+ it "should raise an exception when type is unrecognised" do
56
+ chertdir = tmp_dir + 'whatever'
57
+ lambda {
58
+ XapianDb.new(:dir => chertdir, :create => true, :type => :whatever).rw
59
+ }.should raise_error(XapianFu::XapianFuError)
60
+ end
61
+
41
62
  it "should flush documents to the index when flush is called" do
42
63
  xdb = XapianDb.new(:dir => tmp_dir, :create => true)
43
64
  xdb.flush
@@ -261,4 +261,38 @@ describe XapianDoc do
261
261
  end
262
262
  end
263
263
 
264
+ describe "stopper_strategy" do
265
+ it "should stop all stop words when stopper_strategy is set to :all " do
266
+ xdb = XapianDb.new(:stopper_strategy => :all )
267
+ xdoc = xdb.documents.new("She fished for fish").to_xapian_document
268
+ terms = xdoc.terms.collect { |t| t.term }
269
+ terms.should_not include "for"
270
+ terms.should include "fish"
271
+ end
272
+
273
+ it "should stop stemmed words by when stopper_strategy is set to :stemmed " do
274
+ xdb = XapianDb.new(:stopper_strategy => :stemmed)
275
+ xdoc = xdb.documents.new("She fished for fish").to_xapian_document
276
+ terms = xdoc.terms.collect { |t| t.term }
277
+ terms.should_not include "Zfor"
278
+ terms.should include "fish"
279
+ end
280
+
281
+ it "should stop no words by when stopper_strategy is set to :none " do
282
+ xdb = XapianDb.new(:stopper_strategy => :none)
283
+ xdoc = xdb.documents.new("She fished for fish").to_xapian_document
284
+ terms = xdoc.terms.collect { |t| t.term }
285
+ terms.should include "Zfor"
286
+ terms.should include "for"
287
+ terms.should include "fish"
288
+ end
289
+
290
+ it "should stop stemmed words by default " do
291
+ xdb = XapianDb.new
292
+ xdoc = xdb.documents.new("She fished for fish").to_xapian_document
293
+ terms = xdoc.terms.collect { |t| t.term }
294
+ terms.should_not include "Zfor"
295
+ terms.should include "fish"
296
+ end
297
+ end
264
298
  end
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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-07 00:00:00.000000000 Z
12
+ date: 2020-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: irb
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rdoc
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
185
  requirements:
172
186
  - - ">="
173
187
  - !ruby/object:Gem::Version
174
- version: 1.9.3
188
+ version: 2.1.0
175
189
  required_rubygems_version: !ruby/object:Gem::Requirement
176
190
  requirements:
177
191
  - - ">="
@@ -179,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
193
  version: '0'
180
194
  requirements:
181
195
  - libxapian-dev, or the xapian-ruby gem
182
- rubyforge_project:
183
- rubygems_version: 2.7.6.2
196
+ rubygems_version: 3.1.2
184
197
  signing_key:
185
198
  specification_version: 4
186
199
  summary: A Ruby interface to the Xapian search engine