8 use Text::Unaccent 1.02; # 1.01 won't compile on my platform,
16 $config_file =~ s/\.pl$/.conf/;
17 die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);
21 use index_DBI; # there is no other, right now ;-)
28 # -m multiple directories
32 getopts('d:m:qs', \%opts);
34 my $path; # this is name of database
36 Text::Iconv->raise_error(1); # Conversion errors raise exceptions
38 # this is encoding of all files on disk, including import_xml/*.xml file and
39 # filter/*.pm files! It will be used to store strings in perl internally!
40 my $codepage = 'ISO-8859-2';
42 my $utf2cp = Text::Iconv->new('UTF-8',$codepage);
43 # this function will convert data from XML files to local encoding
45 return $utf2cp->convert($_[0]);
48 # decode isis import codepage
51 # outgoing xml must be in UTF-8
52 my $cp2utf = Text::Iconv->new($codepage,'UTF-8');
59 my $add_xml = shift @_;
65 my $html = ""; # html formatted display output
67 my %field_usage; # counter for usage of each field
69 # sort subrouting using order="" attribute
71 return 0 if (! $config->{indexer}->{$a}->{order});
72 return 0 if (! $config->{indexer}->{$b}->{order});
74 return $config->{indexer}->{$a}->{order} <=>
75 $config->{indexer}->{$b}->{order} ;
78 foreach my $field (sort by_order keys %{$config->{indexer}}) {
82 $field_usage{$field}++;
85 my $display_data = "";
90 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
92 my $format = x($x->{content});
93 my $delimiter = x($x->{delimiter}) || ' ';
95 my $isis_i = 0; # isis repeatable offset
97 my ($s,$d,$i) = (1,1,0); # swish, display default
98 $s = 0 if (lc($x->{type}) eq "display");
99 $d = 0 if (lc($x->{type}) eq "swish");
100 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
102 # what will separate last line from this one?
103 if ($display_data && $x->{append} && $x->{append} eq "1") {
104 $line_delimiter = ' ';
105 } elsif ($display_data) {
106 $line_delimiter = '<br/>';
109 # init vars so that we go into while...
110 ($swish,$display) = (1,1);
112 while ($swish || $display) {
113 ($swish,$display) = parse_format($format,$row,$isis_i++,$isis2cp);
115 # filter="name" ; filter this field through
117 my $filter = $x->{filter};
119 require "filter/".$filter.".pm";
121 # type="swish" ; field for swish
125 $swish_data .= join(" ",&$filter($swish));
127 $swish_data .= $swish;
131 # type="display" ; field for display
132 if ($d && $display) {
133 if ($line_delimiter && $display_data) {
134 $display_data .= $line_delimiter;
135 undef $line_delimiter;
139 $display_data .= join($delimiter,&$filter($display));
142 $display_data .= $delimiter.$display;
144 $display_data .= $display;
149 # type="index" ; insert into index
150 if ($i && $display) {
151 my $index_data = $display;
154 foreach my $d (&$filter($index_data)) {
155 $index->insert($field, $d, $path);
158 $index->insert($field, $index_data, $path);
167 if ($field eq "headline") {
168 $xml .= xmlify("headline", $display_data);
171 # find field name (signular, plural)
173 if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
174 $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
175 } elsif ($config->{indexer}->{$field}->{name_plural}) {
176 $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
177 } elsif ($config->{indexer}->{$field}->{name}) {
178 $field_name = $config->{indexer}->{$field}->{name}."#-#";
180 print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
183 $html .= x($field_name);
185 $html .= $display_data."###\n";
189 # remove extra spaces
190 $swish_data =~ s/ +/ /g;
191 $swish_data =~ s/ +$//g;
193 $xml .= xmlify($field."_swish", unac_string($codepage,$swish_data));
199 # dump formatted output in <html>
201 $xml .= xmlify("html",$html);
205 $xml .= $add_xml if ($add_xml);
206 return "<xml>\n$xml</xml>\n";
212 ##########################################################################
214 my $cfg = new Config::IniFiles( -file => $config_file );
217 $index = new index_DBI(
218 $cfg->val('global', 'dbi_dbd'),
219 $cfg->val('global', 'dbi_dsn'),
220 $cfg->val('global', 'dbi_user'),
221 $cfg->val('global', 'dbi_passwd') || '',
224 # delete [global] section to leave just databases sections
225 $cfg->DeleteSection('global');
227 foreach my $database ($cfg->Sections) {
229 my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!";
230 my $type = $cfg -> val($database, 'type') || die "$database doesn't have 'type' defined";
231 my $add_xml = $cfg -> val($database, 'xml'); # optional
233 $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
235 $isis2cp = Text::Iconv->new($config->{isis_codepage},$codepage);
237 my $db = OpenIsis::open( $isis_db );
241 print STDERR "WARNING: can't open '$isis_db'\n";
245 my $max_rowid = OpenIsis::maxRowid( $db );
247 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
249 my $path = $database; # was $isis_db
253 # { my $row_id = 4514;
255 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
256 my $row = OpenIsis::read( $db, $row_id );
257 if ($row && $row->{mfn}) {
258 # output current process indicator
259 my $p = int($row->{mfn} * 100 / $max_rowid);
261 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
265 my $swishpath = $path."#".int($row->{mfn});
267 if (my $xml = isis2xml($row,$add_xml)) {
268 $xml = $cp2utf->convert($xml);
269 use bytes; # as opposed to chars
270 print "Path-Name: $swishpath\n";
271 print "Content-Length: ".(length($xml)+1)."\n";
272 print "Document-Type: XML\n\n$xml\n";
279 # call this to commit index
284 ##########################################################################
288 isis2xml.pl - read isis file and dump XML
292 This command will read ISIS data file using OpenIsis perl module and
293 create XML file for usage with I<SWISH-E>
294 indexer. Dispite it's name, this script B<isn't general xml generator>
295 from isis files (isis allready has something like that). Output of this
296 script is tailor-made for SWISH-E.
300 Dobrica Pavlinusic <dpavlin@rot13.org>
304 GNU Public License (GPL) v2 or later
308 SWISH-E web site at http://www.swish-e.org