43 |
|
|
44 |
package Search::Estraier::Document; |
package Search::Estraier::Document; |
45 |
|
|
46 |
use Carp qw/confess/; |
use Carp qw/croak confess/; |
47 |
|
|
48 |
=head1 Search::Estraier::Document |
=head1 Search::Estraier::Document |
49 |
|
|
72 |
|
|
73 |
$doc->add_attr( name => 'value' ); |
$doc->add_attr( name => 'value' ); |
74 |
|
|
75 |
B<FIXME>: delete attribute using |
Delete attribute using |
76 |
|
|
77 |
$doc->add_attr( name => undef ); |
$doc->add_attr( name => undef ); |
78 |
|
|
83 |
my $attrs = {@_}; |
my $attrs = {@_}; |
84 |
|
|
85 |
while (my ($name, $value) = each %{ $attrs }) { |
while (my ($name, $value) = each %{ $attrs }) { |
86 |
$self->{attrs}->{_s($name)} = _s($value); |
if (! defined($value)) { |
87 |
|
delete( $self->{attrs}->{_s($name)} ); |
88 |
|
} else { |
89 |
|
$self->{attrs}->{_s($name)} = _s($value); |
90 |
|
} |
91 |
} |
} |
92 |
|
|
93 |
return 1; |
return 1; |
142 |
|
|
143 |
=head2 attr_names |
=head2 attr_names |
144 |
|
|
145 |
Get a list of attribute names of a document object. |
Returns array with attribute names from document object. |
146 |
|
|
147 |
my @attrs = $doc->attr_names; |
my @attrs = $doc->attr_names; |
148 |
|
|
150 |
|
|
151 |
sub attr_names { |
sub attr_names { |
152 |
my $self = shift; |
my $self = shift; |
153 |
confess "attr_names return array, not scalar" if (! wantarray); |
croak "attr_names return array, not scalar" if (! wantarray); |
154 |
return sort keys %{ $self->{attrs} }; |
return sort keys %{ $self->{attrs} }; |
155 |
} |
} |
156 |
|
|
157 |
|
|
158 |
=head2 attr |
=head2 attr |
159 |
|
|
160 |
Get the value of an attribute. |
Returns value of an attribute. |
161 |
|
|
162 |
my $value = $doc->attr( 'attribute' ); |
my $value = $doc->attr( 'attribute' ); |
163 |
|
|
170 |
return $self->{'attrs'}->{ $name }; |
return $self->{'attrs'}->{ $name }; |
171 |
} |
} |
172 |
|
|
173 |
|
|
174 |
|
=head2 texts |
175 |
|
|
176 |
|
Returns array with text sentences. |
177 |
|
|
178 |
|
my @texts = $doc->texts; |
179 |
|
|
180 |
|
=cut |
181 |
|
|
182 |
|
sub texts { |
183 |
|
my $self = shift; |
184 |
|
confess "texts return array, not scalar" if (! wantarray); |
185 |
|
return @{ $self->{dtexts} }; |
186 |
|
} |
187 |
|
|
188 |
|
=head2 cat_texts |
189 |
|
|
190 |
|
Return whole text as single scalar. |
191 |
|
|
192 |
|
my $text = $doc->cat_texts; |
193 |
|
|
194 |
|
=cut |
195 |
|
|
196 |
|
sub cat_texts { |
197 |
|
my $self = shift; |
198 |
|
return join(' ',@{ $self->{dtexts} }); |
199 |
|
} |
200 |
|
|
201 |
=head2 dump_draft |
=head2 dump_draft |
202 |
|
|
203 |
|
Dump draft data from document object. |
204 |
|
|
205 |
print $doc->dump_draft; |
print $doc->dump_draft; |
206 |
|
|
207 |
=cut |
=cut |
208 |
|
|
209 |
sub dump_draft { |
sub dump_draft { |
210 |
|
my $self = shift; |
211 |
|
my $draft; |
212 |
|
|
213 |
|
foreach my $attr_name (sort keys %{ $self->{attrs} }) { |
214 |
|
$draft .= $attr_name . '=' . $self->{attrs}->{$attr_name} . "\n"; |
215 |
|
} |
216 |
|
|
217 |
|
if ($self->{kwords}) { |
218 |
|
$draft .= '%%VECTOR'; |
219 |
|
while (my ($key, $value) = each %{ $self->{kwords} }) { |
220 |
|
$draft .= "\t$key\t$value"; |
221 |
|
} |
222 |
|
$draft .= "\n"; |
223 |
|
} |
224 |
|
|
225 |
|
$draft .= "\n"; |
226 |
|
|
227 |
|
$draft .= join("\n", @{ $self->{dtexts} }) . "\n"; |
228 |
|
$draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n"; |
229 |
|
|
230 |
|
return $draft; |
231 |
} |
} |
232 |
|
|
233 |
=head2 delete |
=head2 delete |
245 |
delete($self->{$data}); |
delete($self->{$data}); |
246 |
} |
} |
247 |
|
|
248 |
|
$self->{id} = -1; |
249 |
|
|
250 |
return 1; |
return 1; |
251 |
} |
} |
252 |
|
|