/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Wed Jan 4 13:11:43 2006 UTC revision 7 by dpavlin, Wed Jan 4 14:57:27 2006 UTC
# Line 43  implementation. It also includes methods Line 43  implementation. It also includes methods
43    
44  package Search::Estraier::Document;  package Search::Estraier::Document;
45    
46    use Carp qw/confess/;
47    
48  =head1 Search::Estraier::Document  =head1 Search::Estraier::Document
49    
50  Document for HyperEstraier  Document for HyperEstraier
# Line 58  sub new { Line 60  sub new {
60          my $self = {@_};          my $self = {@_};
61          bless($self, $class);          bless($self, $class);
62    
63            $self->{id} = -1;
64    
65          $self ? return $self : return undef;          $self ? return $self : return undef;
66  }  }
67    
68    
69  =head2 add_attr  =head2 add_attr
70    
71    Add an attribute.
72    
73    $doc->add_attr( name => 'value' );    $doc->add_attr( name => 'value' );
74    
75    B<FIXME>: delete attribute using
76    
77      $doc->add_attr( name => undef );
78    
79  =cut  =cut
80    
81  sub add_attr {  sub add_attr {
# Line 72  sub add_attr { Line 83  sub add_attr {
83          my $attrs = {@_};          my $attrs = {@_};
84    
85          while (my ($name, $value) = each %{ $attrs }) {          while (my ($name, $value) = each %{ $attrs }) {
86                  $name =~ s/\s\s+/ /gs;                  push @{ $self->{attrs}->{_s($name)} }, _s($value);
                 $value =~ s/\s\s+/ /gs;  
                 push @{$self->{$name}}, $value;  
87          }          }
88  }  }
89    
90    
91    =head2 add_text
92    
93    Add a sentence of text.
94    
95      $doc->add_text('this is example text to display');
96    
97    =cut
98    
99    sub add_text {
100            my $self = shift;
101            my $text = shift;
102            return unless defined($text);
103    
104            push @{ $self->{dtexts} }, _s($text);
105    }
106    
107    
108    =head2 add_hidden_text
109    
110    Add a hidden sentence.
111    
112      $doc->add_hidden_text('this is example text just for search');
113    
114    =cut
115    
116    sub add_hidden_text {
117            my $self = shift;
118            my $text = shift;
119            return unless defined($text);
120    
121            push @{ $self->{htexts} }, _s($text);
122    }
123    
124    =head2 id
125    
126    Get the ID number of document. If the object has never been registred, C<-1> is returned.
127    
128      print $doc->id;
129    
130    =cut
131    
132    sub id {
133            my $self = shift;
134            return $self->{id};
135    }
136    
137    =head2 attr_names
138    
139    Get a list of attribute names of a document object.
140    
141      my @attrs = $doc->attr_names;
142    
143    =cut
144    
145    sub attr_names {
146            my $self = shift;
147            confess "attr_names return array, not scalar" if (! wantarray);
148            return sort keys %{ $self->{attrs} };
149    }
150    
151    =head2 dump_draft
152    
153      print $doc->dump_draft;
154    
155    =cut
156    
157    sub dump_draft {
158    }
159    
160    =head2 delete
161    
162    Empty document object
163    
164      $doc->delete;
165    
166    =cut
167    
168    sub delete {
169            my $self = shift;
170    
171            foreach my $data (qw/attrs dtexts stexts/) {
172                    delete($self->{$data});
173            }
174    
175            return 1;
176    }
177    
178    
179    =head2 _s
180    
181    Remove multiple whitespaces from string, as well as whitespaces at beginning or end
182    
183     my $text = _s(" this  is a text  ");
184     $text = 'this is a text';
185    
186    =cut
187    
188    sub _s {
189            my $text = shift || return;
190            $text =~ s/\s\s+/ /gs;
191            $text =~ s/^\s+//;
192            $text =~ s/\s+$//;
193            return $text;
194    }
195    
196    
197    
198  package Search::Estraier::Master;  package Search::Estraier::Master;
199    

Legend:
Removed from v.2  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26