--- trunk/Estraier.pm 2006/01/04 19:37:38 13 +++ trunk/Estraier.pm 2006/01/04 21:51:01 14 @@ -47,21 +47,65 @@ =head1 Search::Estraier::Document +This class implements Document which is collection of attributes +(key=value), vectors (also key value) display text and hidden text. + Document for HyperEstraier =head2 new +Create new document, empty or from draft. + my $doc = new Search::HyperEstraier::Document; + my $doc2 = new Search::HyperEstraier::Document( $draft ); =cut sub new { my $class = shift; - my $self = {@_}; + my $self = {}; bless($self, $class); $self->{id} = -1; + my $draft = shift; + + if ($draft) { + my $in_text = 0; + foreach my $line (split(/\n/, $draft)) { + + if ($in_text) { + if ($line =~ /^\t/) { + push @{ $self->{htexts} }, substr($line, 1); + } else { + push @{ $self->{dtexts} }, $line; + } + next; + } + + if ($line =~ m/^%VECTOR\t(.+)$/) { + my @fields = split(/\t/, $1); + for my $i ( 0 .. ($#fields - 1) ) { + $self->{kwords}->{ $fields[ $i ] } = $fields[ $i + 1 ]; + $i++; + } + next; + } elsif ($line =~ m/^%/) { + # What is this? comment? + #warn "$line\n"; + next; + } elsif ($line =~ m/^$/) { + $in_text = 1; + next; + } elsif ($line =~ m/^(.+)=(.+)$/) { + $self->{attrs}->{ $1 } = $2; + next; + } + + warn "draft ignored: $line\n"; + } + } + $self ? return $self : return undef; } @@ -241,7 +285,7 @@ sub delete { my $self = shift; - foreach my $data (qw/attrs dtexts stexts/) { + foreach my $data (qw/attrs dtexts stexts kwords/) { delete($self->{$data}); }