ferret(0.9.4)

PureRuby 版だけ試した。

動かないといっても 1.9 での仕様変更によるものがほとんど。
この間廃止された if cond: statement end が使われている(; じゃなくて : で区切る)。

あとは、1.9 だと include Comparable していると == メソッドには <=> メソッドが利用されるようで、それを考慮していない Ferret::Index::Term#<=> を修正。

あとは、Thread と WeakKeyHash のテストで GC.start すると YARV がお亡くなりになるので、とりあえずコメントアウト

diff -ru ferret-0.9.4/lib/ferret/index/compound_file_io.rb ferret-0.9.4-/lib/ferret/index/compound_file_io.rb
--- ferret-0.9.4/lib/ferret/index/compound_file_io.rb   2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/lib/ferret/index/compound_file_io.rb  2006-07-28 19:58:32.000000000 +0900
@@ -64,7 +64,7 @@
 
     def close()
       synchronize do
-        if (@stream == nil): raise(IOError, "Already closed") end
+        if (@stream == nil); raise(IOError, "Already closed") end
 
         @entries.clear()
         @stream.close()
@@ -115,7 +115,7 @@
     # Returns the length of a file in the directory.
     def length(name)
       e = @entries[name]
-      if (e == nil): raise(IOError, "File " + name + " does not exist") end
+      if (e == nil); raise(IOError, "File " + name + " does not exist") end
       return e.length
     end
 
@@ -151,7 +151,7 @@
         def read_internal(b, offset, len)
           @base.synchronize() do
             start = pos()
-            if(start + len > @length): raise(EOFError, "read past EOF") end
+            if(start + len > @length); raise(EOFError, "read past EOF") end
             @base.seek(@file_offset + start)
             @base.read_bytes(b, offset, len)
           end
@@ -331,7 +331,7 @@
           end
 
         ensure
-          if (is != nil): is.close() end
+          if (is != nil); is.close() end
         end
       end
   end
diff -ru ferret-0.9.4/lib/ferret/index/term.rb ferret-0.9.4-/lib/ferret/index/term.rb
--- ferret-0.9.4/lib/ferret/index/term.rb       2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/lib/ferret/index/term.rb      2006-07-28 20:06:17.000000000 +0900
@@ -29,6 +29,7 @@
 
     # implements comparable giving us the methods >, >=, <, <= and between? 
     def <=>(other)
+      return nil unless other.respond_to?(:text) and other.respond_to?(:field)
       if @field == other.field 
         return @text <=> other.text 
       else
diff -ru ferret-0.9.4/lib/ferret/search/boolean_scorer.rb ferret-0.9.4-/lib/ferret/search/boolean_scorer.rb
--- ferret-0.9.4/lib/ferret/search/boolean_scorer.rb    2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/lib/ferret/search/boolean_scorer.rb   2006-07-28 19:59:16.000000000 +0900
@@ -53,9 +53,12 @@
       end
 
       case occur
-      when BooleanClause::Occur::MUST: @required_scorers << scorer
-      when BooleanClause::Occur::SHOULD: @optional_scorers << scorer
-      when BooleanClause::Occur::MUST_NOT: @prohibited_scorers << scorer
+      when BooleanClause::Occur::MUST
+        @required_scorers << scorer
+      when BooleanClause::Occur::SHOULD
+        @optional_scorers << scorer
+      when BooleanClause::Occur::MUST_NOT
+        @prohibited_scorers << scorer
       end
     end
 
diff -ru ferret-0.9.4/lib/ferret/search/field_sorted_hit_queue.rb ferret-0.9.4-/lib/ferret/search/field_sorted_hit_queue.rb
--- ferret-0.9.4/lib/ferret/search/field_sorted_hit_queue.rb    2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/lib/ferret/search/field_sorted_hit_queue.rb   2006-07-28 19:59:30.000000000 +0900
@@ -119,9 +119,9 @@
       comparator = lookup(reader, field.name, field.sort_type, field.comparator)
       if (comparator == nil) 
         case (field.sort_type) 
-        when SortField::SortType::AUTO: 
+        when SortField::SortType::AUTO
           comparator = comparator_auto(reader, field.name)
-        when SortField::SortType::STRING: 
+        when SortField::SortType::STRING
           comparator = comparator_string(reader, field.name)
         else 
           comparator = comparator_simple(reader, field)
ferret-0.9.4-/testだけに発見: temp
diff -ru ferret-0.9.4/test/unit/utils/rtc_thread.rb ferret-0.9.4-/test/unit/utils/rtc_thread.rb
--- ferret-0.9.4/test/unit/utils/rtc_thread.rb  2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/test/unit/utils/rtc_thread.rb 2006-07-28 20:04:02.000000000 +0900
@@ -20,7 +20,7 @@
     10.times {|i| a[i] = "#{i}"; Thread.current.set_local(a[i], i) }
     10.times {|i| assert_equal(i, Thread.current.get_local(a[i])) }
     assert_equal(10, Thread.current.local_size)
-    GC.start
+#    GC.start
     assert_equal(10, Thread.current.local_size)
     10.times {|i| a[i] = nil; }
     #puts w
@@ -30,7 +30,7 @@
     10.times {|i| a[i] = "#{i}"; x[a[i]] = i }
 
     assert_equal(10, Thread.current.local_size)
-    GC.start
+#    GC.start
     assert(0, Thread.current.local_size)
   end
 
diff -ru ferret-0.9.4/test/unit/utils/rtc_weak_key_hash.rb ferret-0.9.4-/test/unit/utils/rtc_weak_key_hash.rb
--- ferret-0.9.4/test/unit/utils/rtc_weak_key_hash.rb   2006-07-28 20:05:38.000000000 +0900
+++ ferret-0.9.4-/test/unit/utils/rtc_weak_key_hash.rb  2006-07-28 01:43:52.000000000 +0900
@@ -17,7 +17,7 @@
     x = WeakKeyHash.new()
     10.times {|i| a[i] = "#{i}"; x[a[i]] = i }
 
-    GC.start
+    #GC.start
     #puts w.size
     #puts w
     assert(0, w.size)

ここまでやると、すべて通る(GC.start をコメントアウトしたテストはテストの意味がないけれど)。-

date@assam ferret-0.9.4- $ /usr/local/yarv/bin/rake test_runits
(in /home/date/tmp/ferret-0.9.4-)
/usr/local/yarv/bin/ruby-yarv -Ilib:test/unit -r 'lib/rferret' "/usr/local/yarv/lib/ruby/gems/2.0/gems/rake-0.7.1/lib/rake/rake_test_loader.rb" "test/unit/ts_document.rb" "test/unit/ts_index.rb" "test/unit/ts_store.rb" "test/unit/ts_analysis.rb" "test/unit/ts_utils.rb" "test/unit/ts_search.rb" "test/unit/ts_query_parser.rb" 
Loaded suite /usr/local/yarv/lib/ruby/gems/2.0/gems/rake-0.7.1/lib/rake/rake_test_loader
Started
.........................................................................................
.........................................................................................
.....................................
Finished in 27.826317 seconds.

215 tests, 5578 assertions, 0 failures, 0 errors