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
66 # sort subrouting using order="" attribute
68 return 0 if (! $config->{indexer}->{$a}->{order});
69 return 0 if (! $config->{indexer}->{$b}->{order});
71 return $config->{indexer}->{$a}->{order} <=>
72 $config->{indexer}->{$b}->{order} ;
75 foreach my $field (sort by_order keys %{$config->{indexer}}) {
77 $field_usage{$field}++;
80 my $display_data = "";
81 my $line_delimiter = "";
83 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
85 my $format = $x->{content};
86 my $delimiter = $x->{delimiter} || ' ';
88 # FIX: this is ugly, UGLY, cludge string is returned
89 # in UTF8 encoding , but as if source charset
90 # is ISO8859-1 and not some other. This break other
91 # character encodings, so we convert it first
93 $format = $xml_codepage->convert($format);
94 $delimiter = $xml_codepage->convert($delimiter) if ($delimiter);
96 my $isis_i = 0; # isis repeatable offset
98 my ($s,$d,$i) = (1,1,0); # swish, display default
99 $s = 0 if (lc($x->{type}) eq "display");
100 $d = 0 if (lc($x->{type}) eq "swish");
101 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
102 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";
104 $display_data .= $line_delimiter if ($display_data && $display_data !~ /$line_delimiter$/);
106 my ($swish,$display) = (1,1);
108 while ($swish || $display) {
109 ($swish,$display) = parse_format($format,$row,$isis_i++);
110 #print STDERR "s: $swish\nd: $display\n" if ($swish);
112 #print STDERR "swish: $swish<-- display: $display<--\n";
114 # filter="name" ; filter this field through
116 my $filter = $x->{filter};
118 require "filter/".$filter.".pm";
120 # type="swish" ; field for swish
123 #print STDERR "using filter '$filter'\n";
125 $swish_data .= join(" ",&$filter($swish));
127 $swish_data .= $swish;
131 # type="display" ; field for display
132 if ($d && $display) {
135 $display_data .= join($delimiter,&$filter($display));
138 $display_data .= $delimiter.$display;
140 $display_data .= $display;
145 # type="index" ; insert into index
146 if ($i && $display) {
147 my $index_data = $index_codepage->convert($display) || $display;
150 foreach my $d (&$filter($index_data)) {
151 $index->insert($field, $d, $db_dir);
154 $index->insert($field, $index_data, $db_dir);
159 $line_delimiter = ' ';
161 $line_delimiter = '<br/>';
166 #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
170 $display_data =~ s/$line_delimiter$//;
172 $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
173 # FIX: this is removed and replaced by html tag.
174 #$xml .= xmlify($field."_display", $display_data);
176 if ($field eq "headline") {
177 $xml .= xmlify("headline", $display_data);
180 # find field name (signular, plural)
182 if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
183 $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
184 } elsif ($config->{indexer}->{$field}->{name_plural}) {
185 $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
186 } elsif ($config->{indexer}->{$field}->{name}) {
187 $field_name = $config->{indexer}->{$field}->{name}."#-#";
189 print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
192 $html .= $xml_codepage->convert($field_name);
193 # $html .= "-->".$field_name."<--";
195 $html .= $display_data."###\n";
199 my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
200 # remove extra spaces
201 $swish_data =~ s/ +/ /g;
202 $swish_data =~ s/ +$//g;
204 $swish_data = $i->convert($swish_data);
205 $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
206 #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
207 #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
213 # dump formatted output in <html>
215 $xml .= xmlify("html",$html);
219 #print STDERR "x: $xml\n";
220 $xml .= $add_xml if ($add_xml);
221 return "<xml>\n$xml</xml>\n";
227 ##########################################################################
229 my $cfg = new Config::IniFiles( -file => $config_file );
231 foreach my $database ($cfg->Sections) {
233 my $isis_db = $cfg -> val($database, 'isis_db');
234 my $type = $cfg -> val($database, 'type');
235 my $add_xml = $cfg -> val($database, 'xml');
237 # read configuration for this type
238 $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
239 $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET);
240 $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
241 $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET);
243 my $db = OpenIsis::open( $isis_db );
247 print STDERR "WARNING: can't open '$isis_db'\n";
251 my $max_rowid = OpenIsis::maxRowid( $db );
253 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
255 my $path = $database; # was $isis_db
259 # { my $row_id = 4514;
261 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
262 my $row = OpenIsis::read( $db, $row_id );
263 if ($row && $row->{mfn}) {
264 #print STDERR "mfn: ",$row->{mfn},"\n";
265 # output current process indicator
266 my $p = int($row->{mfn} * 100 / $max_rowid);
268 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
272 if (my $xml = isis2xml($row,$add_xml)) {
273 #print STDERR "--ret-->$xml\n";
274 print "Path-Name: $path#".int($row->{mfn})."\n";
275 print "Content-Length: ".(length($xml)+1)."\n";
276 print "Document-Type: XML\n\n$xml\n";
283 # call this to commit index
288 ##########################################################################
292 isis2xml.pl - read isis file and dump XML
296 This command will read ISIS data file using OpenIsis perl module and
297 create XML file for usage with I<SWISH-E>
298 indexer. Dispite it's name, this script B<isn't general xml generator>
299 from isis files (isis allready has something like that). Output of this
300 script is tailor-made for SWISH-E.
304 Dobrica Pavlinusic <dpavlin@rot13.org>
308 GNU Public License (GPL) v2 or later
312 SWISH-E web site at http://www.swish-e.org