47 |
|
|
48 |
=head1 Search::Estraier::Document |
=head1 Search::Estraier::Document |
49 |
|
|
50 |
|
This class implements Document which is collection of attributes |
51 |
|
(key=value), vectors (also key value) display text and hidden text. |
52 |
|
|
53 |
Document for HyperEstraier |
Document for HyperEstraier |
54 |
|
|
55 |
=head2 new |
=head2 new |
56 |
|
|
57 |
|
Create new document, empty or from draft. |
58 |
|
|
59 |
my $doc = new Search::HyperEstraier::Document; |
my $doc = new Search::HyperEstraier::Document; |
60 |
|
my $doc2 = new Search::HyperEstraier::Document( $draft ); |
61 |
|
|
62 |
=cut |
=cut |
63 |
|
|
64 |
sub new { |
sub new { |
65 |
my $class = shift; |
my $class = shift; |
66 |
my $self = {@_}; |
my $self = {}; |
67 |
bless($self, $class); |
bless($self, $class); |
68 |
|
|
69 |
$self->{id} = -1; |
$self->{id} = -1; |
70 |
|
|
71 |
|
my $draft = shift; |
72 |
|
|
73 |
|
if ($draft) { |
74 |
|
my $in_text = 0; |
75 |
|
foreach my $line (split(/\n/, $draft)) { |
76 |
|
|
77 |
|
if ($in_text) { |
78 |
|
if ($line =~ /^\t/) { |
79 |
|
push @{ $self->{htexts} }, substr($line, 1); |
80 |
|
} else { |
81 |
|
push @{ $self->{dtexts} }, $line; |
82 |
|
} |
83 |
|
next; |
84 |
|
} |
85 |
|
|
86 |
|
if ($line =~ m/^%VECTOR\t(.+)$/) { |
87 |
|
my @fields = split(/\t/, $1); |
88 |
|
for my $i ( 0 .. ($#fields - 1) ) { |
89 |
|
$self->{kwords}->{ $fields[ $i ] } = $fields[ $i + 1 ]; |
90 |
|
$i++; |
91 |
|
} |
92 |
|
next; |
93 |
|
} elsif ($line =~ m/^%/) { |
94 |
|
# What is this? comment? |
95 |
|
#warn "$line\n"; |
96 |
|
next; |
97 |
|
} elsif ($line =~ m/^$/) { |
98 |
|
$in_text = 1; |
99 |
|
next; |
100 |
|
} elsif ($line =~ m/^(.+)=(.+)$/) { |
101 |
|
$self->{attrs}->{ $1 } = $2; |
102 |
|
next; |
103 |
|
} |
104 |
|
|
105 |
|
warn "draft ignored: $line\n"; |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
110 |
} |
} |
111 |
|
|
285 |
sub delete { |
sub delete { |
286 |
my $self = shift; |
my $self = shift; |
287 |
|
|
288 |
foreach my $data (qw/attrs dtexts stexts/) { |
foreach my $data (qw/attrs dtexts stexts kwords/) { |
289 |
delete($self->{$data}); |
delete($self->{$data}); |
290 |
} |
} |
291 |
|
|