NAME

Senna::Index - Interface to Senna's Index

SYNOPSIS

  use Senna::Index;
  # Export SEN_INDEX_* constants
  use Senna::Index qw(:flags);

  my $index = Senna::Index->open($path);
  # or
  my $index = Senna::Index->create($path, $flags, $n_segment, $encoding);

  $index->close();
  $index->put($key, $value);
  $index->del($key, $value);
  $index->replace($key, $old_value, $new_value);

  my $cursor = $index->search($query);
  while (my $result = $cursor->fetch_next()) {
     $result->key();
     $result->score();
  }

  while ($cursor->next) { # or $cursor->rewind
     my $key = $cursor->key;
     my $score = $cursor->score;
  }

  $index->remove();

DESCRIPTION

Senna::Index is an interface to the index struct in Senna (http://dev.razil.jp/projects/senna).

METHODS

create($path[, $key_size, $flags, $n_segment, $encoding)

Creates a new senna index in a file specified by $path.

$key_size specifies the key size of the index. Currently Senna::Index only supports

  SEN_VARCHAR_KEY
  SEN_INT_KEY

default is SEN_VARCHAR_KEY.

$flags is a bit mask, which can be a combination of

  SEN_INDEX_NORMALIZE
  SEN_INDEX_NGRAM
  SEN_INDEX_SPLIT_ALPHA
  SEN_INDEX_SPLIT_DIGIT
  SEN_INDEX_SPLIT_SYMBOL

$encoding can be one of

  SEN_ENC_DEFAULT
  SEN_ENC_NONE
  SEN_ENC_EUCJP
  SEN_ENC_UTF8
  SEN_ENC_SJIS

These constants are available from Senna::Index. See CONSTANTS.

Note that senna actually creates several files for a given index. Given an index filename "senna", it will create the following files:

  senna.SEN
  senna.SEN.i
  senna.SEN.i.c
  senna.SEN.l

Refer to the senna documentation for details.

open($path)

Opens an existing senna index file.

close

Closes the current senna index files. Returns true on success, false otherwise.

put($key, $value)

Adds a new entry into the senna index file. Returns true on success, false otherwise.

del($key, $value)

Removes an existing entry from the senna index file. Returns true on success, false otherwise. Note that you need to give the previous value of the key for the index to correctly recoginize the changes.

replace($key, $oldval, $newval)

Replaces the index that $key is pointing to from $oldval to $newval. Note that you need to give the previous value of the key for the index to correctly recoginize the changes.

remove()

Removes the index file opened in the current index.

filename(), keys_size(), flags(), initial_n_segments(), encoding()

Retrieves the index's filename, key_size, flags, initial_n_segments, encoding, respectively

CONSTANTS

Constants can are available by importing them:

  use Senna::Index qw(:key_size);
  use Senna::Index qw(:flags);
  use Senna::Index qw(:encoding);
  use Senna::Index qw(:all);

:key_size exports SEN_VARCHAR_KEY and SEN_INT_KEY.

:flags exports SEN_INDEX_NORMALIZE, SEN_INDEX_NGRAM, SEN_INDEX_SPLIT_ALPHA, SEN_INDEX_SPLIT_DIGIT, SEN_INDEX_SPLIT_SYMBOL.

:encoding exports SEN_ENC_DEFAULT, SEN_ENC_NONE, SEN_ENC_EUCJP, SEN_ENC_UTF8, SEN_ENC_SJIS.

AUTHOR

Copyright (C) 2005 by Daisuke Maki <dmaki@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

Development funded by Brazil Ltd. <http://dev.razil.jp/projects/senna/>

SEE ALSO

http://dev.razil.jp/projects/senna - Senna Development Homepage