~ubuntu-branches/ubuntu/quantal/ruby-ferret/quantal

« back to all changes in this revision

Viewing changes to test/unit/search/tm_searcher.rb

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2012-06-14 23:04:48 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120614230448-wd5se4ia1yz7dvms
Tags: 0.11.8.4+debian-1
* New upstream version from a new source
  + the new code fixes format security issues (Closes: #672069)
  + change homepage to https://github.com/jkraemer/ferret/
* Build for all Ruby versions (Closes: #655636)
  + change depends accordingly
  + do not set shebang of bin/ferret to ruby1.8
* Repack source to remove convenience copy of bzlib
  + build-dep on libbz2-dev
  + dversionmangle in debian/watch
  + add debian/README.source explaining how to clean the source
* debian/patches:
  + disable_load_path_manipulation.patch: do not override $LOAD_PATH
  + disable_test_causing_segfault.patch: temporarily disable a test known to
    cause segfaults
  + fix_compatibility_with_minitest.patch: fix a failing test with Ruby1.9
  + use_system_bzlib.patch: adapt the source to use system libbz2
  + fix_typos_in_source_code.patch: correct some spelling errors in the
    source code
  + block_variables_have_local_scopes.patch: fix syntax in
    bin/ferret-browser
* Override dh_auto_clean to remove test/temp when cleaning
* Bump Standards-Version to 3.9.3 (no changes needed)
* Set priority of transitional packages to extra
* Add myself to Uploaders:
* Update copyright to DEP-5 copyright-format/1.0
* Add TUTORIAL and debian/README.source to documents
* Override lintian warnings about duplicate descriptions of transitional
  packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    docs.length.times do |i|
35
35
      assert_equal(expected[i], docs[i].doc)
36
36
    end
 
37
    if options[:limit] == :all and options[:offset] == nil
 
38
      assert_equal(expected.sort, @searcher.scan(query))
 
39
    end
37
40
  end
38
41
 
39
42
  def test_offset
201
204
    check_hits(rq, [15,16,17])
202
205
  end
203
206
 
 
207
  def test_typed_range_query()
 
208
    rq = TypedRangeQuery.new(:number, :>= => "-1.0", :<= => 1.0)
 
209
    check_hits(rq, [0,1,4,10,15,17])
 
210
 
 
211
    rq = TypedRangeQuery.new(:number, :>  => "-1.0", :<  => 1.0)
 
212
    check_hits(rq, [0,1,4,15])
 
213
 
 
214
    if ENV['FERRET_DEV']
 
215
        # text hexadecimal
 
216
        rq = TypedRangeQuery.new(:number, :>  =>  "1.0", :<= =>"0xa")
 
217
        check_hits(rq, [6,7,9,12])
 
218
    end
 
219
 
 
220
    # test single bound
 
221
    rq = TypedRangeQuery.new(:number, :<= =>  "0.0")
 
222
    check_hits(rq, [5,11,15,16,17])
 
223
 
 
224
    # test single bound
 
225
    rq = TypedRangeQuery.new(:number, :>  =>  "0.0")
 
226
    check_hits(rq, [0,1,2,3,4,6,7,8,9,10,12,13,14])
 
227
 
 
228
    # below range - no results
 
229
    rq = TypedRangeQuery.new(:number, :>  =>  "10051006", :<  =>"10051010")
 
230
    check_hits(rq, [])
 
231
 
 
232
    # above range - no results
 
233
    rq = TypedRangeQuery.new(:number, :>  =>  "-12518421", :<  =>"-12518420")
 
234
    check_hits(rq, [])
 
235
  end
 
236
 
204
237
  def test_prefix_query()
205
238
    pq = PrefixQuery.new(:category, "cat1")
206
239
    check_hits(pq, [0, 1, 2, 3, 4, 13, 14, 15, 16, 17])
358
391
    assert_equal("<b>the words</b>...", highlights[0])
359
392
    assert_equal("...<b>one</b> <b>two</b>...", highlights[1])
360
393
 
361
 
    # {:dates => '20070505, 20071230, 20060920, 20081111'},
362
394
    [
363
395
      [RangeQuery.new(:dates, :>= => '20081111'),
364
396
        '20070505 20071230 20060920 <b>20081111</b>'],
381
413
    #assert_equal("<b>the words</b>...", highlights[0])
382
414
    #assert_equal("...<b>one</b> <b>two</b>...", highlights[1])
383
415
  end
 
416
 
 
417
  def test_highlighter_with_standard_analyzer()
 
418
    dir = Ferret::Store::RAMDirectory.new
 
419
    iw = Ferret::Index::IndexWriter.new(:dir => dir,
 
420
                  :analyzer => Ferret::Analysis::StandardAnalyzer.new())
 
421
    [
 
422
        {:field => "field has a url http://ferret.davebalmain.com/trac/ end"},
 
423
    ].each {|doc| iw << doc }
 
424
    iw.close
 
425
    
 
426
    searcher = Searcher.new(dir)
 
427
 
 
428
    q = TermQuery.new(:field, "ferret.davebalmain.com/trac");
 
429
    highlights = searcher.highlight(q, 0, :field,
 
430
                                    :excerpt_length => 1000,
 
431
                                    :num_excerpts => 1)
 
432
    assert_equal(1, highlights.size)
 
433
    assert_equal("field has a url <b>http://ferret.davebalmain.com/trac/</b> end",
 
434
                 highlights[0])
 
435
  end
384
436
end