Index: lib/Senna.pm
===================================================================
--- lib/Senna.pm	(revision 2)
+++ lib/Senna.pm	(working copy)
@@ -10,9 +10,17 @@
 
 our $VERSION = '0.01';
 
+require Exporter;
 require XSLoader;
 XSLoader::load('Senna', $VERSION);
-
+our @ISA = qw(Exporter);
+our @EXPORT = qw(
+    SEN_INDEX_NORMALIZE
+    SEN_INDEX_SPLIT_ALPHA
+    SEN_INDEX_SPLIT_DIGIT
+    SEN_INDEX_SPLIT_SYMBOL
+    SEN_INDEX_NGRAM
+);
 use Senna::Index;
 use Senna::Cursor;
 use Senna::Result;
@@ -32,8 +40,8 @@
   $index->open($file);
   my $cursor = $index->search($query);
 
-  while (my $result = $cursor->fetch_next) {
-      print $result->key, " score = ", $result->score, "\n";
+  while (my $key = $cursor->next) {
+      print $key, " score = ", $cursor->score, "\n";
   }
 
 =head1 AUTHOR
Index: Senna.xs
===================================================================
--- Senna.xs	(revision 2)
+++ Senna.xs	(working copy)
@@ -9,9 +9,8 @@
 
 #include "ppport.h"
 
-#include <senna/index.h>
+#include <senna/senna.h>
 
-#include "senna_perl.h"
 #define MAX_INDEX_PATH_LEN 512
 #define SENNA_MAX_KEY_LEN 8024
 
@@ -22,7 +21,7 @@
 typedef struct psenna_index SENNA_INDEX_STATE;
 
 struct psenna_cursor {
-    sen_index_result *cursor;
+    sen_records *cursor;
 };
 
 typedef struct psenna_cursor SENNA_CURSOR_STATE;
@@ -60,7 +59,6 @@
 static int
 magic_free_senna_index_state(pTHX_ SV *sv, MAGIC *mg)
 {
-fprintf(stderr, "magic_free\n");
     return 1;
 }
 
@@ -98,7 +96,6 @@
 static int
 magic_free_senna_cursor_state(pTHX_ SV *sv, MAGIC *mg)
 {
-fprintf(stderr, "cursor magic_free\n");
     return 1;
 }
 
@@ -108,7 +105,46 @@
 
 PROTOTYPES: ENABLE
 
+SV *
+SEN_INDEX_NORMALIZE()
+    CODE:
+       RETVAL = newSViv(SEN_INDEX_NORMALIZE);
+    OUTPUT:
+        RETVAL
 
+SV *
+SEN_INDEX_SPLIT_ALPHA()
+    CODE:
+       RETVAL = newSViv(SEN_INDEX_SPLIT_ALPHA);
+    OUTPUT:
+        RETVAL
+
+SV *
+SEN_INDEX_SPLIT_DIGIT()
+    CODE:
+       RETVAL = newSViv(SEN_INDEX_SPLIT_DIGIT);
+    OUTPUT:
+        RETVAL
+
+SV *
+SEN_INDEX_SPLIT_SYMBOL()
+    CODE:
+       RETVAL = newSViv(SEN_INDEX_SPLIT_SYMBOL);
+    OUTPUT:
+        RETVAL
+
+SV *
+SEN_INDEX_NGRAM()
+    CODE:
+       RETVAL = newSViv(SEN_INDEX_NGRAM);
+    OUTPUT:
+        RETVAL
+
+
+
+
+
+
 MODULE = Senna		PACKAGE = Senna::Index		
 
 PROTOTYPES: ENABLE
@@ -130,6 +166,7 @@
 
         Newz(1234, state, 1, SENNA_INDEX_STATE);
         state->index  = NULL;
+        sen_init();
 
         sv = newSViv(PTR2IV(state));
         sv_magic(sv, 0, '~', 0, 0);
@@ -141,14 +178,12 @@
         hv_store(hv, "_xs_state", 17, newRV_noinc(sv), 0);
 
 SV *
-_open_index(self, path, key_size, flags)
+_open_index(self, path, ...)
         SV *self;
         SV *path;
-        SV *key_size;
-        SV *flags;
     PREINIT:
         char        *index_path;
-        uint8_t      index_key_size;
+        uint8_t      index_n_segment;
         uint8_t      index_flags;
         SV          *sv;
         SENNA_INDEX_STATE *state = get_index_state_hv(self);
@@ -158,13 +193,23 @@
             croak("Not a reference to a hash");
         }
 
-        index_key_size = SvUV(key_size);
-        index_flags    = SvUV(flags);
         index_path     = SvPV_nolen(path);
-        state->index   = sen_index_open(index_path, index_key_size, index_flags);
+        if (items > 2) {
+            index_flags     = SvUV(ST(2));
+            index_n_segment = SvUV(ST(3));
+            state->index = sen_index_create(index_path, 0, index_flags,
+                                            index_n_segment, sen_enc_default);
+        }
+        else {
+            state->index = sen_index_open(index_path);
+        }
         if (state->index != NULL) {
             RETVAL = newSVuv((uint8_t) 1);
         }
+        else {
+            RETVAL = &PL_sv_undef;
+        }
+
     OUTPUT:
         RETVAL
 
@@ -216,7 +261,8 @@
         index_value = SvPV(value, len);
 
         state = get_index_state_hv(self);
-        RETVAL = newSVuv(sen_index_put(state->index, (void *) index_key, (uint8_t) index_value));
+        RETVAL = newSVuv(sen_index_upd(state->index, (const char *) index_key,
+                                       NULL, (const char *) index_value));
     OUTPUT:
         RETVAL
 
@@ -245,7 +291,7 @@
         index_value = SvPV(value, len);
 
         state = get_index_state_hv(self);
-        RETVAL = newSVuv(sen_index_del(state->index, (void *) index_key, (uint8_t) index_value));
+        RETVAL = newSVuv(sen_index_upd(state->index, (const char *) index_key, (const char *) index_value, NULL));
     OUTPUT:
         RETVAL
 
@@ -258,15 +304,16 @@
         HV *hv;
         HV *stash;
         SENNA_INDEX_STATE *state;
+        SENNA_CURSOR_STATE *srecords;
         char *index_query;
         STRLEN len;
-        char *result;
+        sen_records *result;
     CODE:
         dSP;
 
         state = get_index_state_hv(self);
         index_query = SvPV(query, len);
-        result = (char *) sen_index_search(state->index, index_query);
+        result = sen_index_sel(state->index, index_query);
 
         /* create an object Senna::Cursor by calling the constructor */
         ENTER;
@@ -288,6 +335,8 @@
         LEAVE;
 
         /* okay, now set the state->cursor variable */
+        srecords = get_cursor_state_hv(sv);
+        srecords->cursor = result;
 
         RETVAL = sv;
     OUTPUT:
@@ -329,14 +378,14 @@
 next(self)
         SV *self;
     PREINIT:
-        char *next;
+        const char *next;
         SENNA_CURSOR_STATE *state;
     CODE:
         RETVAL = &PL_sv_undef;
 
         state = get_cursor_state_hv(self);
-        if (next = sen_index_result_next(state->cursor)) {
-            RETVAL = newSVnv(1);
+        if (next = sen_records_next(state->cursor)) {
+            RETVAL = newSVpv(next, strlen(next));
         }
     OUTPUT:
         RETVAL
@@ -351,7 +400,7 @@
         RETVAL = &PL_sv_undef;
 
         state = get_cursor_state_hv(self);
-        sen_index_result_rewind(state->cursor);
+        sen_records_rewind(state->cursor);
         RETVAL = newSVnv(1);
     OUTPUT:
         RETVAL
@@ -365,7 +414,7 @@
         RETVAL = &PL_sv_undef;
 
         state = get_cursor_state_hv(self);
-        sen_index_result_close(state->cursor);
+        sen_records_close(state->cursor);
         RETVAL = newSVnv(1);
     OUTPUT:
         RETVAL
@@ -376,6 +425,7 @@
     PREINIT:
         SENNA_CURSOR_STATE *state;
     CODE:
-        RETVAL = newSVuv(send_index_result_curr_score(state->cursor));
+        state = get_cursor_state_hv(self);
+        RETVAL = newSVuv(sen_records_curr_score(state->cursor));
     OUTPUT:
         RETVAL
