91 |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
92 |
$log->info("using encoding $encoding"); |
$log->info("using encoding $encoding"); |
93 |
|
|
94 |
my $iconv = new Text::Iconv('iso-8859-2', 'utf-8'); |
$self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or |
95 |
|
$log->die("can't create conversion from $encoding to UTF-8"); |
96 |
|
|
97 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
98 |
} |
} |
99 |
|
|
100 |
|
|
101 |
=head2 add |
=head2 add |
102 |
|
|
103 |
Adds one entry to database. |
Adds one entry to database. |
140 |
$log->debug("creating $uri"); |
$log->debug("creating $uri"); |
141 |
|
|
142 |
my $doc = HyperEstraier::Document->new; |
my $doc = HyperEstraier::Document->new; |
143 |
$doc->add_attr('@uri', $uri); |
$doc->add_attr('@uri', $self->{'iconv'}->convert($uri) ); |
144 |
|
|
145 |
$log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); |
$log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); |
146 |
|
|
159 |
|
|
160 |
$log->logconfess("no values for $tag/$type") unless ($vals); |
$log->logconfess("no values for $tag/$type") unless ($vals); |
161 |
|
|
162 |
$doc->add_attr($tag, $vals); |
$vals = $self->{'iconv'}->convert( $vals ) or |
163 |
$doc->add_hidden_text($vals); |
$log->die("can't convert '$vals' to UTF-8"); |
164 |
|
|
165 |
|
$doc->add_attr( $tag, $vals ); |
166 |
|
$doc->add_hidden_text( $vals ); |
167 |
} |
} |
168 |
|
|
169 |
my $text = $args->{'text'}; |
my $text = $args->{'text'}; |
170 |
$doc->add_text( $text ) if ( $text ); |
if ( $text ) { |
171 |
|
$text = $self->{'iconv'}->convert( $text ) or |
172 |
|
$log->die("can't convert '$text' to UTF-8"); |
173 |
|
$doc->add_text( $text ); |
174 |
|
} |
175 |
|
|
176 |
$log->debug("adding ", sub { $doc->dump_draft } ); |
$log->debug("adding ", sub { $doc->dump_draft } ); |
177 |
$self->{'db'}->put_doc($doc) || $log->die("can't add document $uri to index"); |
$self->{'db'}->put_doc($doc) || $log->die("can't add document $uri to index"); |