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
43 #my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');
44 #my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
47 my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');
55 my $add_xml = shift @_;
61 my $html = ""; # html formatted display output
63 my %field_usage; # counter for usage of each field
65 foreach my $field (keys %{$config->{indexer}}) {
67 $field_usage{$field}++;
70 my $display_data = "";
72 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
74 my $format = $x->{content};
75 my ($s,$d,$i) = (1,1,0); # swish, display default
76 $s = 0 if (lc($x->{type}) eq "display");
77 $d = 0 if (lc($x->{type}) eq "swish");
78 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
79 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";
81 # FIX: this is ugly, UGLY, cludge string is returned
82 # in UTF8 encoding , but as if source charset
83 # is ISO8859-1 and not some other. This break other
84 # character encodings, so we convert it first
86 $format = $cludge_codepage->convert($format);
88 my ($swish,$display) = parse_format($format,$row);
89 #print STDERR "s: $swish\nd: $display\n" if ($swish);
91 #print STDERR "swish: $swish<-- display: $display<--\n";
93 # filter="name" ; filter this field through
97 $filter = "filter/".$x->{filter}.".pm";
100 # type="swish" ; field for swish
103 $swish_data .= join(" ",&filter($swish));
105 $swish_data .= $swish if ($s && $swish);
109 # type="display" ; field for display
110 if ($d && $display) {
112 $display_data .= join(" ",&filter($display));
114 $display_data .= $display;
118 # type="index" ; insert into index
119 if ($i && $display) {
120 my $index_data = $index_codepage->convert($display) || $display;
122 foreach my $d (&filter($index_data)) {
123 $index->insert($field, $d, $db_dir);
126 $index->insert($field, $index_data, $db_dir);
132 #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
134 $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
135 # FIX: this is removed and replaced by html tag.
136 #$xml .= xmlify($field."_display", $display_data);
138 if ($field eq "headline") {
139 $xml .= xmlify("headline", $display_data);
142 # find field name (signular, plural)
144 if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
145 $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
146 } elsif ($config->{indexer}->{$field}->{name_plural}) {
147 $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
148 } elsif ($config->{indexer}->{$field}->{name}) {
149 $field_name = $config->{indexer}->{$field}->{name}."#-#";
151 print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
154 $html .= $xml_codepage->convert($field_name);
156 $html .= $display_data."###\n";
160 my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
161 # remove extra spaces
162 $swish_data =~ s/ +/ /g;
163 $swish_data =~ s/ +$//g;
165 $swish_data = $i->convert($swish_data);
166 $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
167 #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
168 #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
174 # dump formatted output in <html>
176 $xml .= xmlify("html",$html);
180 #print STDERR "x: $xml\n";
181 $xml .= $add_xml if ($add_xml);
182 return "<xml>\n$xml</xml>\n";
188 ##########################################################################
190 my $cfg = new Config::IniFiles( -file => $config_file );
192 foreach my $database ($cfg->Sections) {
194 my $isis_db = $cfg -> val($database, 'isis_db');
195 my $type = $cfg -> val($database, 'type');
196 my $add_xml = $cfg -> val($database, 'xml');
198 # read configuration for this type
199 $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
200 $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');
201 $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
202 $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),'UTF8');
204 my $db = OpenIsis::open( $isis_db );
208 print STDERR "WARNING: can't open '$isis_db'\n";
212 my $max_rowid = OpenIsis::maxRowid( $db );
214 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
216 my $path = $database; # was $isis_db
220 # { my $row_id = 4514;
222 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
223 my $row = OpenIsis::read( $db, $row_id );
224 if ($row && $row->{mfn}) {
225 #print STDERR "mfn: ",$row->{mfn},"\n";
226 # output current process indicator
227 my $p = int($row->{mfn} * 100 / $max_rowid);
229 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
233 if (my $xml = isis2xml($row,$add_xml)) {
234 #print STDERR "--ret-->$xml\n";
235 print "Path-Name: $path#".int($row->{mfn})."\n";
236 print "Content-Length: ".(length($xml)+1)."\n";
237 print "Document-Type: XML\n\n$xml\n";
244 # call this to commit index
249 ##########################################################################
253 isis2xml.pl - read isis file and dump XML
257 This command will read ISIS data file using OpenIsis perl module and
258 create XML file for usage with I<SWISH-E>
259 indexer. Dispite it's name, this script B<isn't general xml generator>
260 from isis files (isis allready has something like that). Output of this
261 script is tailor-made for SWISH-E.
265 Dobrica Pavlinusic <dpavlin@rot13.org>
269 GNU Public License (GPL) v2 or later
273 SWISH-E web site at http://www.swish-e.org