null+****@clear*****
null+****@clear*****
2010年 11月 18日 (木) 20:27:00 JST
Daijiro MORI 2010-11-18 11:27:00 +0000 (Thu, 18 Nov 2010) New Revision: b6eebc8101c9388fac6bf31ed6c3551e14c331d8 Log: Modified behavior of buffer_new(). Try GRN_CURSOR_PREFIX and then try GRN_CURSOR_ASCENDING unless corresponding records found. Modified files: lib/ii.c Modified: lib/ii.c (+14 -5) =================================================================== --- lib/ii.c 2010-11-18 06:02:15 +0000 (02f675a) +++ lib/ii.c 2010-11-18 11:27:00 +0000 (148d166) @@ -3300,11 +3300,20 @@ buffer_new(grn_ctx *ctx, grn_ii *ii, int size, uint32_t *pos, // const char *key = _grn_table_key(ctx, ii->lexicon, id, &key_size); int key_size = grn_table_get_key(ctx, ii->lexicon, id, key, GRN_TABLE_MAX_KEY_SIZE); uint32_t *a, lseg = NOT_ASSIGNED, pseg = NOT_ASSIGNED; - grn_table_cursor *tc = (ii->lexicon->header.type == GRN_TABLE_PAT_KEY) - ? grn_table_cursor_open(ctx, ii->lexicon, NULL, 0, key, key_size, 0, -1, - GRN_CURSOR_PREFIX) - : grn_table_cursor_open(ctx, ii->lexicon, NULL, 0, NULL, 0, 0, -1, - GRN_CURSOR_ASCENDING); + grn_table_cursor *tc = NULL; + if (ii->lexicon->header.type == GRN_TABLE_PAT_KEY) { + if ((tc = grn_table_cursor_open(ctx, ii->lexicon, NULL, 0, key, key_size, 0, -1, + GRN_CURSOR_PREFIX))) { + if (!((grn_pat_cursor *)tc)->sp) { + grn_table_cursor_close(ctx, tc); + tc = NULL; + } + } + } + if (!tc) { + tc = grn_table_cursor_open(ctx, ii->lexicon, NULL, 0, NULL, 0, 0, -1, + GRN_CURSOR_ASCENDING); + } if (tc) { while (lseg == NOT_ASSIGNED && (tid = grn_table_cursor_next(ctx, tc))) { if ((a = array_at(ctx, ii, tid))) {