root/lang/perl/Senna/trunk/lib/Senna/Index.pm @ 3915

Revision 3915, 3.0 kB (checked in by daisuke, 5 years ago)

add record type

  • Property svn:keywords set to Id
Line 
1# $Id$
2#
3# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4# All rights reserved.
5
6package Senna::Index;
7use strict;
8use warnings;
9use Senna::Index::Info;
10use Senna::Record;
11
12sub create
13{
14    my $class = shift;
15    my %args  = @_;
16
17    my @xs_args = map { $args{$_} }
18        qw(path key_size flags initial_n_segments encoding);
19    pop @xs_args while @xs_args && ! defined $xs_args[-1];
20    $class->XS_create(@xs_args);
21}
22
23sub open
24{
25    my $class = shift;
26    if (@_ == 1) {
27        if(ref $_[0] eq 'HASH') {
28            @_ = ($_[0]->{path});
29        }
30    } elsif (@_ > 1) {
31        my %args  = @_;
32        @_ = ($args{path});
33    }
34
35    $class->_XS_open(@_);
36}
37
38sub info
39{
40    my $self = shift;
41    if ( wantarray ) {
42        return $self->XS_info();
43    } else {
44        my %h;
45        my @fields = qw(key_size flags initial_n_segments encoding nrecords_keys file_size_keys nrecords_lexicon file_size_lexicon inv_seg_size inv_chunk_size);
46        @h{ @fields } = $self->XS_info();
47
48        return Senna::Index::Info->new(%h);
49    }
50}
51
52sub insert
53{
54    my $self = shift;
55    if (@_ == 1 && ref $_[0] eq 'HASH') {
56        @_ = ($_[0]->{key}, $_[0]->{value});
57    } elsif (@_ > 2) {
58        my %args = @_;
59        @_ = ($args{key}, $args{value});
60    }
61    $self->_XS_insert(@_);
62}
63
64sub select
65{
66    my $self = shift;
67    if (@_ == 1 && ref $_[0] eq 'HASH') {
68        @_ = map { $_[0]->{$_} } qw(query records op optarg);
69    } elsif (@_ > 1) {
70        my %args = @_;
71        @_ = @args{qw(query records op optarg)};
72    }
73
74    $self->_XS_select(@_);
75}
76
771;
78
79__END__
80
81=head1 NAME
82
83Senna::Index - Senna Index Object
84
85=head1 SYNOPSIS
86
87  use Senna;
88
89  my $index = Senna::Index->create();
90  my $index = Senna::Index->open($path);
91
92  $index->insert($key, $value);
93  $index->select($query);
94
95=head1 METHODS
96
97=head2 create
98
99=head2 open
100
101Opens an existing index.
102
103  my $index = Senna::Index->open($path);
104  my $index = Senna::Index->open({ path => $path });
105
106For backwards compatibility, if given more than one argument, open() assumes
107that you've been given a key value pair like so:
108
109  my $index = Senna::Index->open(path => $path);
110
111However, note that this form is DEPRECATED. Use the HASHREF form instead
112
113=head2 info
114
115In scalar context, returns a Senna::Index::Info object.
116
117  $info = $index->info;
118  $info->key_size();
119
120In list context, returns the same informtion as a list:
121
122  ($key_size, $flags, $initial_n_segments, $encoding, $nrecords_keys,
123    $file_size_keys, $nrecords_lexicon, $file_size_lexicon, $inv_seg_size,
124      $inv_chunk_size) = $index->info
125
126=head2 path
127
128Returns the path to the senna index.
129
130=head2 close
131
132=head2 remove
133
134=head2 update
135
136=head2 insert
137
138Inserts a new entry in the index.
139
140  $index->insert($key, $value);
141  $index->insert({ key => $key, value => $value });
142
143For backwards compatibility if given more than 2 arguments, insert() assumes
144that you've been given a key/value pair like so:
145
146  $index->insert(key => $key, value => $value);
147
148However, note that this form is DEPRECATED. Use the HASHREF form instead
149
150=cut
Note: See TracBrowser for help on using the browser.