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 = "";
85 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
87 my $format = $x->{content};
88 my $delimiter = $x->{delimiter} || ' ';
90 # FIX: this is ugly, UGLY, cludge string is returned
91 # in UTF8 encoding , but as if source charset
92 # is ISO8859-1 and not some other. This break other
93 # character encodings, so we convert it first
95 $format = $xml_codepage->convert($format);
96 $delimiter = $xml_codepage->convert($delimiter) if ($delimiter);
98 my $isis_i = 0; # isis repeatable offset
100 my ($s,$d,$i) = (1,1,0); # swish, display default
101 $s = 0 if (lc($x->{type}) eq "display");
102 $d = 0 if (lc($x->{type}) eq "swish");
103 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
104 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";
106 # what will separate last line from this one?
107 if ($display_data && $x->{append} && $x->{append} eq "1") {
108 $line_delimiter = ' ';
109 } elsif ($display_data) {
110 $line_delimiter = '<br/>';
113 # init vars so that we go into while...
114 ($swish,$display) = (1,1);
116 while ($swish || $display) {
117 ($swish,$display) = parse_format($format,$row,$isis_i++);
118 #print STDERR "s: $swish\nd: $display\n" if ($swish);
120 #print STDERR "swish: $swish<-- display: $display<--\n";
122 # filter="name" ; filter this field through
124 my $filter = $x->{filter};
126 require "filter/".$filter.".pm";
128 # type="swish" ; field for swish
131 #print STDERR "using filter '$filter'\n";
133 $swish_data .= join(" ",&$filter($swish));
135 $swish_data .= $swish;
139 # type="display" ; field for display
140 if ($d && $display) {
141 if ($line_delimiter && $display_data) {
142 $display_data .= $line_delimiter;
143 undef $line_delimiter;
147 $display_data .= join($delimiter,&$filter($display));
150 $display_data .= $delimiter.$display;
152 $display_data .= $display;
157 # type="index" ; insert into index
158 if ($i && $display) {
159 my $index_data = $index_codepage->convert($display) || $display;
162 foreach my $d (&$filter($index_data)) {
163 $index->insert($field, $d, $db_dir);
166 $index->insert($field, $index_data, $db_dir);
173 #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
176 # $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
177 # FIX: this is removed and replaced by html tag.
178 #$xml .= xmlify($field."_display", $display_data);
180 if ($field eq "headline") {
181 $xml .= xmlify("headline", $display_data);
184 # find field name (signular, plural)
186 if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
187 $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
188 } elsif ($config->{indexer}->{$field}->{name_plural}) {
189 $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
190 } elsif ($config->{indexer}->{$field}->{name}) {
191 $field_name = $config->{indexer}->{$field}->{name}."#-#";
193 print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
196 $html .= $xml_codepage->convert($field_name);
198 $html .= $display_data."###\n";
202 my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
203 # remove extra spaces
204 $swish_data =~ s/ +/ /g;
205 $swish_data =~ s/ +$//g;
207 $swish_data = $i->convert($swish_data);
208 $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
209 #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
210 #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
216 # dump formatted output in <html>
218 $xml .= xmlify("html",$html);
222 #print STDERR "x: $xml\n";
223 $xml .= $add_xml if ($add_xml);
224 return "<xml>\n$xml</xml>\n";
230 ##########################################################################
232 my $cfg = new Config::IniFiles( -file => $config_file );
234 foreach my $database ($cfg->Sections) {
236 my $isis_db = $cfg -> val($database, 'isis_db');
237 my $type = $cfg -> val($database, 'type');
238 my $add_xml = $cfg -> val($database, 'xml');
240 # read configuration for this type
241 $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
242 $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET);
243 $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
244 $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET);
246 my $db = OpenIsis::open( $isis_db );
250 print STDERR "WARNING: can't open '$isis_db'\n";
254 my $max_rowid = OpenIsis::maxRowid( $db );
256 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
258 my $path = $database; # was $isis_db
262 # { my $row_id = 4514;
264 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
265 my $row = OpenIsis::read( $db, $row_id );
266 if ($row && $row->{mfn}) {
267 #print STDERR "mfn: ",$row->{mfn},"\n";
268 # output current process indicator
269 my $p = int($row->{mfn} * 100 / $max_rowid);
271 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
275 if (my $xml = isis2xml($row,$add_xml)) {
276 #print STDERR "--ret-->$xml\n";
277 use bytes; # as opposed to chars
278 print "Path-Name: $path#".int($row->{mfn})."\n";
279 print "Content-Length: ".(length($xml)+1)."\n";
280 print "Document-Type: XML\n\n$xml\n";
287 # call this to commit index
292 ##########################################################################
296 isis2xml.pl - read isis file and dump XML
300 This command will read ISIS data file using OpenIsis perl module and
301 create XML file for usage with I<SWISH-E>
302 indexer. Dispite it's name, this script B<isn't general xml generator>
303 from isis files (isis allready has something like that). Output of this
304 script is tailor-made for SWISH-E.
308 Dobrica Pavlinusic <dpavlin@rot13.org>
312 GNU Public License (GPL) v2 or later
316 SWISH-E web site at http://www.swish-e.org