[Groonga-commit] ranguba/rroonga at d2b544e [master] IndexColumn#open_cursor supports :with_position for term ID

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Apr 25 15:59:12 JST 2017


Kouhei Sutou	2017-04-25 15:59:12 +0900 (Tue, 25 Apr 2017)

  New Revision: d2b544e0130e0a446978fbf896fc2880adb8571e
  https://github.com/ranguba/rroonga/commit/d2b544e0130e0a446978fbf896fc2880adb8571e

  Message:
    IndexColumn#open_cursor supports :with_position for term ID

  Modified files:
    ext/groonga/rb-grn-index-column.c
    ext/groonga/rb-grn-inverted-index-cursor.c
    test/test-index-cursor.rb

  Modified: ext/groonga/rb-grn-index-column.c (+2 -6)
===================================================================
--- ext/groonga/rb-grn-index-column.c    2017-04-25 15:53:05 +0900 (ff916d8)
+++ ext/groonga/rb-grn-index-column.c    2017-04-25 15:59:12 +0900 (4a9e32d)
@@ -1056,10 +1056,7 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
     }
 
     if (NIL_P(rb_with_position)) {
-        /* TODO: Remove this check. Require Groonga 7.0.1. */
-        if (table_cursor) {
-            flags |= column_flags & GRN_OBJ_WITH_POSITION;
-        }
+        flags |= column_flags & GRN_OBJ_WITH_POSITION;
     } else if (RVAL2CBOOL(rb_with_position)) {
         flags |= GRN_OBJ_WITH_POSITION;
     }
@@ -1080,8 +1077,7 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
                                        token_id,
                                        rid_min,
                                        rid_max,
-                                       /* TODO: Require Groonga 7.0.1. */
-                                       0, /* grn_ii_get_n_elements(context, ii), */
+                                       grn_ii_get_n_elements(context, ii),
                                        flags);
         rb_cursor = rb_grn_inverted_index_cursor_to_ruby_object(context,
                                                                 ii_cursor,

  Modified: ext/groonga/rb-grn-inverted-index-cursor.c (+0 -7)
===================================================================
--- ext/groonga/rb-grn-inverted-index-cursor.c    2017-04-25 15:53:05 +0900 (e43ba30)
+++ ext/groonga/rb-grn-inverted-index-cursor.c    2017-04-25 15:59:12 +0900 (40049e5)
@@ -80,12 +80,10 @@ rb_grn_inverted_index_cursor_to_ruby_object (grn_ctx *context,
     rb_iv_set(rb_cursor, "@table", rb_table);
     rb_iv_set(rb_cursor, "@lexicon", rb_lexicon);
 
-    /* TODO: Require Groonga 7.0.1.
     if (rb_grn_cursor->cursor &&
         (rb_grn_cursor->flags & GRN_OBJ_WITH_POSITION)) {
         grn_ii_cursor_next(context, cursor);
     }
-    */
 
     return rb_cursor;
 }
@@ -100,8 +98,6 @@ next_value (VALUE rb_posting,
     grn_ii_cursor *cursor = rb_grn_cursor->cursor;
     grn_posting *posting = NULL;
 
-    /* TODO: Require Groonga 7.0.1. */
-    /*
     if (rb_grn_cursor->flags & GRN_OBJ_WITH_POSITION) {
         posting = grn_ii_cursor_next_pos(context, cursor);
         while (!posting && grn_ii_cursor_next(context, cursor)) {
@@ -109,11 +105,8 @@ next_value (VALUE rb_posting,
             break;
         }
     } else {
-    */
         posting = grn_ii_cursor_next(context, cursor);
-    /*
     }
-    */
     if (!posting) {
         return Qnil;
     }

  Modified: test/test-index-cursor.rb (+22 -2)
===================================================================
--- test/test-index-cursor.rb    2017-04-25 15:53:05 +0900 (fde0af5)
+++ test/test-index-cursor.rb    2017-04-25 15:59:12 +0900 (4bee05e)
@@ -40,12 +40,13 @@ class IndexCursorTest < Test::Unit::TestCase
                    postings)
     end
 
-    def test_term_id
+    def test_term_id_without_position
       postings = []
       @terms.open_cursor do |table_cursor|
         table_cursor.each do |term|
           index_cursor = nil
-          @content_index.open_cursor(term.id) do |cursor|
+          @content_index.open_cursor(term.id,
+                                     :with_position => false) do |cursor|
             cursor.each do |posting|
               postings << posting.to_hash
             end
@@ -58,6 +59,25 @@ class IndexCursorTest < Test::Unit::TestCase
       assert_equal(expected_postings(:with_position => false),
                    postings)
     end
+
+    def test_term_id_with_position
+      postings = []
+      @terms.open_cursor do |table_cursor|
+        table_cursor.each do |term|
+          index_cursor = nil
+          @content_index.open_cursor(term.id) do |cursor|
+            cursor.each do |posting|
+              postings << posting.to_hash
+            end
+            index_cursor = cursor
+          end
+          assert_predicate(index_cursor, :closed?)
+        end
+      end
+
+      assert_equal(expected_postings(:with_position => true),
+                   postings)
+    end
   end
 
   def test_enumerable
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index