8 use Text::Unaccent 1.02; # 1.01 won't compile on my platform,
15 $config_file =~ s/\.pl$/.conf/;
16 die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);
20 use index_DBI; # there is no other, right now ;-)
22 my $index = new index_DBI(); # open index
28 # -m multiple directories
32 getopts('d:m:qs', \%opts);
36 #die "usage: $0 -d [database_dir] -m [database1,database2] " if (! %opts);
38 #print Dumper($config->{indexer});
41 Text::Iconv->raise_error(1); # Conversion errors raise exceptions
45 my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');
48 my $XML_CHARSET = 'UTF8';
56 my $add_xml = shift @_;
62 my $html = ""; # html formatted display output
64 my %field_usage; # counter for usage of each field
67 foreach my $field (keys %{$config->{indexer}}) {
69 $field_usage{$field}++;
72 my $display_data = "";
73 my $line_delimiter = "";
75 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
77 my $format = $x->{content};
78 my $delimiter = $x->{delimiter} || ' ';
80 # FIX: this is ugly, UGLY, cludge string is returned
81 # in UTF8 encoding , but as if source charset
82 # is ISO8859-1 and not some other. This break other
83 # character encodings, so we convert it first
85 $format = $xml_codepage->convert($format);
86 $delimiter = $xml_codepage->convert($delimiter) if ($delimiter);
88 my $isis_i = 0; # isis repeatable offset
90 my ($s,$d,$i) = (1,1,0); # swish, display default
91 $s = 0 if (lc($x->{type}) eq "display");
92 $d = 0 if (lc($x->{type}) eq "swish");
93 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
94 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";
96 $display_data .= $line_delimiter if ($display_data && $display_data !~ /$line_delimiter$/);
98 my ($swish,$display) = (1,1);
100 while ($swish || $display) {
101 ($swish,$display) = parse_format($format,$row,$isis_i++);
102 #print STDERR "s: $swish\nd: $display\n" if ($swish);
104 #print STDERR "swish: $swish<-- display: $display<--\n";
106 # filter="name" ; filter this field through
108 my $filter = $x->{filter};
110 require "filter/".$filter.".pm";
112 # type="swish" ; field for swish
115 print STDERR "using filter '$filter'\n";
117 $swish_data .= join(" ",&$filter($swish));
119 $swish_data .= $swish;
123 # type="display" ; field for display
124 if ($d && $display) {
127 $display_data .= join($delimiter,&$filter($display));
130 $display_data .= $delimiter.$display;
132 $display_data .= $display;
137 # type="index" ; insert into index
138 if ($i && $display) {
139 my $index_data = $index_codepage->convert($display) || $display;
142 foreach my $d (&$filter($index_data)) {
143 $index->insert($field, $d, $db_dir);
146 $index->insert($field, $index_data, $db_dir);
151 $line_delimiter = ' ';
153 $line_delimiter = '<br/>';
158 #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
162 $display_data =~ s/$line_delimiter$//;
164 $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
165 # FIX: this is removed and replaced by html tag.
166 #$xml .= xmlify($field."_display", $display_data);
168 if ($field eq "headline") {
169 $xml .= xmlify("headline", $display_data);
172 # find field name (signular, plural)
174 if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
175 $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
176 } elsif ($config->{indexer}->{$field}->{name_plural}) {
177 $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
178 } elsif ($config->{indexer}->{$field}->{name}) {
179 $field_name = $config->{indexer}->{$field}->{name}."#-#";
181 print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
184 $html .= $xml_codepage->convert($field_name);
185 # $html .= "-->".$field_name."<--";
187 $html .= $display_data."###\n";
191 my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
192 # remove extra spaces
193 $swish_data =~ s/ +/ /g;
194 $swish_data =~ s/ +$//g;
196 $swish_data = $i->convert($swish_data);
197 $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
198 #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
199 #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
205 # dump formatted output in <html>
207 $xml .= xmlify("html",$html);
211 #print STDERR "x: $xml\n";
212 $xml .= $add_xml if ($add_xml);
213 return "<xml>\n$xml</xml>\n";
219 ##########################################################################
221 my $cfg = new Config::IniFiles( -file => $config_file );
223 foreach my $database ($cfg->Sections) {
225 my $isis_db = $cfg -> val($database, 'isis_db');
226 my $type = $cfg -> val($database, 'type');
227 my $add_xml = $cfg -> val($database, 'xml');
229 # read configuration for this type
230 $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
231 $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET);
232 $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
233 $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET);
235 my $db = OpenIsis::open( $isis_db );
239 print STDERR "WARNING: can't open '$isis_db'\n";
243 my $max_rowid = OpenIsis::maxRowid( $db );
245 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
247 my $path = $database; # was $isis_db
251 # { my $row_id = 4514;
253 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
254 my $row = OpenIsis::read( $db, $row_id );
255 if ($row && $row->{mfn}) {
256 #print STDERR "mfn: ",$row->{mfn},"\n";
257 # output current process indicator
258 my $p = int($row->{mfn} * 100 / $max_rowid);
260 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
264 if (my $xml = isis2xml($row,$add_xml)) {
265 #print STDERR "--ret-->$xml\n";
266 print "Path-Name: $path#".int($row->{mfn})."\n";
267 print "Content-Length: ".(length($xml)+1)."\n";
268 print "Document-Type: XML\n\n$xml\n";
275 # call this to commit index
280 ##########################################################################
284 isis2xml.pl - read isis file and dump XML
288 This command will read ISIS data file using OpenIsis perl module and
289 create XML file for usage with I<SWISH-E>
290 indexer. Dispite it's name, this script B<isn't general xml generator>
291 from isis files (isis allready has something like that). Output of this
292 script is tailor-made for SWISH-E.
296 Dobrica Pavlinusic <dpavlin@rot13.org>
300 GNU Public License (GPL) v2 or later
304 SWISH-E web site at http://www.swish-e.org