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->logdie("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 |
|
|
147 |
# filter all tags which have type defined |
# filter all tags which have type defined |
148 |
my @tags = grep { |
my @tags = grep { |
149 |
defined( $args->{'ds'}->{$_}->{$type} ) |
ref($args->{'ds'}->{$_}) eq 'HASH' && defined( $args->{'ds'}->{$_}->{$type} ) |
150 |
} keys %{ $args->{'ds'} }; |
} keys %{ $args->{'ds'} }; |
151 |
|
|
152 |
$log->debug("tags = ", join(",", @tags)); |
$log->debug("tags = ", join(",", @tags)); |
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->logdie("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->logdie("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->logdie("can't add document $uri to index"); |
178 |
|
|
179 |
return 1; |
return 1; |
180 |
} |
} |