1Lucy::Index::Segment(3pUms)er Contributed Perl DocumentatLiuocny::Index::Segment(3pm)
2
3
4

NAME

6       Lucy::Index::Segment - Warehouse for information about one segment of
7       an inverted index.
8

SYNOPSIS

10           # Index-time.
11           package MyDataWriter;
12           use base qw( Lucy::Index::DataWriter );
13
14           sub finish {
15               my $self     = shift;
16               my $segment  = $self->get_segment;
17               my $metadata = $self->SUPER::metadata();
18               $metadata->{foo} = $self->get_foo;
19               $segment->store_metadata(
20                   key       => 'my_component',
21                   metadata  => $metadata
22               );
23           }
24
25           # Search-time.
26           package MyDataReader;
27           use base qw( Lucy::Index::DataReader );
28
29           sub new {
30               my $self     = shift->SUPER::new(@_);
31               my $segment  = $self->get_segment;
32               my $metadata = $segment->fetch_metadata('my_component');
33               if ($metadata) {
34                   $self->set_foo( $metadata->{foo} );
35                   ...
36               }
37               return $self;
38           }
39

DESCRIPTION

41       Apache Lucy’s indexes are made up of individual “segments”, each of
42       which is is an independent inverted index.  On the file system, each
43       segment is a directory within the main index directory whose name
44       starts with “seg_”: “seg_2”, “seg_5a”, etc.
45
46       Each Segment object keeps track of information about an index segment:
47       its fields, document count, and so on.  The Segment object itself
48       writes one file, "segmeta.json"; besides storing info needed by Segment
49       itself, the “segmeta” file serves as a central repository for metadata
50       generated by other index components – relieving them of the burden of
51       storing metadata themselves.
52

METHODS

54   add_field
55           my $int = $segment->add_field($field);
56
57       Register a new field and assign it a field number.  If the field was
58       already known, nothing happens.
59
60field - Field name.
61
62       Returns: the field’s field number, which is a positive integer.
63
64   store_metadata
65           $segment->store_metadata(
66               key      => $key,       # required
67               metadata => $metadata,  # required
68           );
69
70       Store arbitrary information in the segment’s metadata hash, to be
71       serialized later.  Throws an error if "key" is used twice.
72
73key - String identifying an index component.
74
75metadata - JSON-izable data structure.
76
77   fetch_metadata
78           my $obj = $segment->fetch_metadata($key);
79
80       Fetch a value from the Segment’s metadata hash.
81
82   field_num
83           my $int = $segment->field_num($field);
84
85       Given a field name, return its field number for this segment (which may
86       differ from its number in other segments).  Return 0 (an invalid field
87       number) if the field name can’t be found.
88
89field - Field name.
90
91   field_name
92           my $string = $segment->field_name($field_num);
93
94       Given a field number, return the name of its field, or undef if the
95       field name can’t be found.
96
97   get_name
98           my $string = $segment->get_name();
99
100       Getter for the object’s seg name.
101
102   get_number
103           my $int = $segment->get_number();
104
105       Getter for the segment number.
106
107   set_count
108           $segment->set_count($count);
109
110       Setter for the object’s document count.
111
112   get_count
113           my $int = $segment->get_count();
114
115       Getter for the object’s document count.
116
117   compare_to
118           my $int = $segment->compare_to($other);
119
120       Compare by segment number.
121

INHERITANCE

123       Lucy::Index::Segment isa Clownfish::Obj.
124
125
126
127perl v5.38.0                      2023-07-20         Lucy::Index::Segment(3pm)
Impressum