Sha256: f7556de90365b2be30596c249f6ce88b0b81a8b729d9e900dc042dd75c083ea1

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

#!/usr/local/bin/ruby -w
require 'fileutils'
require 'tmpdir'
require 'test/unit'
require 'rsi'

module RSI

  class TestX2SampleAnalyzer
    attr_accessor :base
    def initialize( base=RSI::DefaultTextAnalyzer.new() )
      @base = base
    end

    def get_field_types()
      return { "text" => RSI::FIELD_TYPE_TEXT,
          "subject" => RSI::FIELD_TYPE_TEXT }
    end

    def tokenize( content )
      r = {}
      content =~ /^(.*?)\n/
      r['subject'] = @base.tokenize_text( $1 )
      r['text'] = @base.tokenize_text( content )
      return r
    end

  end
end

class X2SampleAnalyzerTest < Test::Unit::TestCase
  
  DOC_A = "The subject was a long and pointless one\n" +
    "\n"+
    "Also, so was the story.\n\n";

  def setup()
    @tmp = Dir::tmpdir()
    @root = File.join( @tmp, "searchtest.#{$$}.#{rand(65535)}" )
    Dir.mkdir( @root )
    @failed = false
  end

  def add_failure( msg, bt )
    super
    @failed = true
  end

  # Delete the temp dir for the index tests
  def teardown()
    if @failed
      print "Test case failed, not cleaning up #@root\n";
    else
      FileUtils::rm_rf( @root )
    end
  end

  def test_sample()
    indexer = RSI::Indexer.new( @root )
    indexer.serializer = RSI::YAMLSerializer.new()
    indexer.analyzer = RSI::TestX2SampleAnalyzer.new()
    indexer.open()
    indexer.add_document( "DOC_A", DOC_A )
    indexer.flush()

    # TODO: queryanalyzers
    a = indexer.find_all( "pointless subject" )
  end

end
    

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rsi-0.4 tests/t_index_multi.rb