Skip to content

Commit

Permalink
IndexColumn#open_cursor supports :with_position for term ID
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 25, 2017
1 parent ab47d52 commit d2b544e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
8 changes: 2 additions & 6 deletions ext/groonga/rb-grn-index-column.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions ext/groonga/rb-grn-inverted-index-cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -100,20 +98,15 @@ 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)) {
posting = grn_ii_cursor_next_pos(context, cursor);
break;
}
} else {
*/
posting = grn_ii_cursor_next(context, cursor);
/*
}
*/
if (!posting) {
return Qnil;
}
Expand Down
24 changes: 22 additions & 2 deletions test/test-index-cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ def test_table_cursor
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
Expand All @@ -58,6 +59,25 @@ def test_term_id
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
Expand Down

0 comments on commit d2b544e

Please sign in to comment.