source: main/trunk/greenstone2/perllib/buildConfigxml.pm

Last change on this file was 38951, checked in by anupama, 2 days ago

Removing the temporary GS3 runtime Service class GsdlCollageBrowse.java and changes in buildConfigxml.pm and header.xsl needed to work with this that were added in order to get the GsdlCollageApplet to run in some manner and get some idea as to how it was to work/look. Since we've got it working the ideal way, these no longer used temporary changes are no longer necessary.

  • Property svn:keywords set to Author Date Id Revision
File size: 26.7 KB
Line 
1###########################################################################
2#
3# buildConfigxml.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# reads in buildConfig.xml
27# Note, only implemented the bits that are currently used, eg by incremental
28# build code.
29# The resulting data is not a full representation on buildConfig.xml.
30
31package buildConfigxml;
32
33use strict;
34no strict 'refs';
35no strict 'subs';
36
37use XMLParser;
38
39
40# A mapping hash to resolve name discrepancy between gs2 and gs3.
41my $nameMap = {"numDocs" => "numdocs",
42 "buildType" => "buildtype",
43 "orthogonalBuildTypes" => "orthogonalbuildtypes"
44 };
45
46
47# A hash structure which is returned by sub read_cfg_file.
48my $data = {};
49
50# use those unique attribute values to locate the text within the elements
51my $currentLocation = "";
52my $stringexp = q/^(buildType|numDocs)$/;
53my $arrayexp = q/^(orthogonalBuildTypes)$/;
54
55my $indexmap_name = "";
56my $haveindexfields = 0;
57
58# Reads in the model collection configuration file, collectionConfig.xml,
59# into a structure which complies with the one used by gs2 (i.e. one read
60# in by &cfgread::read_cfg_file).
61sub read_cfg_file {
62 my ($filename) = @_;
63 $data = {};
64 if ($filename !~ /buildConfig\.xml$/ || !-f $filename) {
65 return undef;
66 }
67
68 # Removed ProtocolEncoding (see MetadataXMLPlugin for details)
69
70 # create XML::Parser object for parsing metadata.xml files
71 my $parser = new XML::Parser('Style' => 'Stream',
72 'Pkg' => 'buildConfigxml',
73 'Handlers' => {'Char' => \&Char,
74 'Doctype' => \&Doctype
75 });
76
77 if (!open (COLCFG, $filename)) {
78 print STDERR "buildConfigxml::read_cfg_file couldn't read the cfg file $filename\n";
79 } else {
80
81 $parser->parsefile ($filename);# (COLCFG);
82 close (COLCFG);
83 }
84
85 #&Display;
86 return $data;
87}
88
89sub StartTag {
90# Those marked with #@ will not be executed at the same time when this sub is being called
91# so that if/elsif is used to avoid unnecessary tests
92 my ($expat, $element) = @_;
93
94 my $name = $_{'name'};
95 my $shortname = $_{'shortname'};
96
97
98 #@ handling block metadataList
99 if (defined $name && (($name =~ m/$stringexp/) || ($name =~ m/$arrayexp/))) {
100 $currentLocation = $name;
101 # the value will be retrieved later in Text sub
102 }
103
104 #@ handle indexes - store indexmap (mg) or indexfields and indexfieldmap (mgpp/lucene/solr)
105 elsif ($element =~ /^indexList$/) {
106 # set up the data arrays
107 # this assumes that the build type has been read already, which is
108 # currently the order we save the file in.
109 if ($data->{'buildtype'} eq "mg") {
110 $indexmap_name = "indexmap";
111 if (!defined $data->{"indexmap"}) {
112 $data->{"indexmap"} = [];
113 }
114 }
115 else {
116 # mgpp, lucene or solr
117 $indexmap_name = "indexfieldmap";
118 $haveindexfields = 1;
119 if (!defined $data->{"indexfieldmap"}) {
120 $data->{"indexfieldmap"} = [];
121 }
122 if (!defined $data->{"indexfields"}) {
123 $data->{"indexfields"} = [];
124 }
125
126 }
127
128 }
129
130 elsif ($element =~ /index/) {
131 # store each index in the map
132 if (defined $name && defined $shortname) {
133 push @{$data->{$indexmap_name}}, "$name->$shortname";
134 if ($haveindexfields) {
135 push @{$data->{'indexfields'}}, $name;
136 }
137 }
138 }
139
140 elsif ($element =~ /solrcoreList/) {
141 if (!defined $data->{'solrcores'}) {
142 $data->{"solrcores"} = [];
143 }
144 }
145 elsif ($element =~ /solrcore/) {
146 # store each core in the list
147 if (defined $name) {
148 push @{$data->{'solrcores'}}, $name;
149 }
150 }
151}
152
153sub EndTag {
154 my ($expat, $element) = @_;
155}
156
157sub Text {
158 if (defined $currentLocation) {
159 #@ Handling block metadataList(numDocs, buildType)
160 if ($currentLocation =~ /$stringexp/) {
161 #print $currentLocation;
162 my $key = $nameMap->{$currentLocation};
163 $data->{$key} = $_;
164 undef $currentLocation;
165 }
166 elsif ($currentLocation =~ /$arrayexp/) {
167 #print $currentLocation;
168 my $key = $nameMap->{$currentLocation};
169 push(@{$data->{$key}},$_);
170 undef $currentLocation;
171 }
172
173 }
174}
175
176# This sub is for debugging purposes
177sub Display {
178
179 print "NumDocs = ".$data->{'numdocs'}."\n" if (defined $data->{'numdocs'});
180 print "BuildType = ".$data->{'buildtype'}."\n" if (defined $data->{'buildtype'});
181 print "OrthogonalBuildTypes = ".join(",",@{$data->{'orthogonalbuildtypes'}})."\n" if (defined $data->{'orthogonalbuildtypes'});
182 print "IndexMap = ". join(" ",@{$data->{'indexmap'}})."\n" if (defined $data->{'indexmap'});
183 print "IndexFieldMap = ". join(" ",@{$data->{'indexfieldmap'}})."\n" if (defined $data->{'indexfieldmap'});
184 print "IndexFields = ". join(" ",@{$data->{'indexfields'}})."\n" if (defined $data->{'indexfields'});
185
186}
187
188# is this actually used??
189sub Doctype {
190 my ($expat, $name, $sysid, $pubid, $internal) = @_;
191
192 die if ($name !~ /^buildConfig$/);
193}
194
195# This Char function overrides the one in XML::Parser::Stream to overcome a
196# problem where $expat->{Text} is treated as the return value, slowing
197# things down significantly in some cases.
198sub Char {
199 if ($]<5.008) {
200 use bytes; # Necessary to prevent encoding issues with XML::Parser 2.31+ and Perl 5.6
201 }
202 $_[0]->{'Text'} .= $_[1];
203 return undef;
204}
205
206
207
208sub write_line {
209 my ($filehandle, $line) = @_;
210 print $filehandle join ("", @$line), "\n";
211}
212
213sub search_and_retrieve_settings
214{
215 my ($buildcfg,$collectcfg) = @_;
216
217 my $settings = {};
218
219 if (defined $buildcfg->{"buildtype"}) {
220 $settings->{'buildtype'} = $buildcfg->{"buildtype"};
221 } else {
222 $settings->{'buildtype'} = "mgpp";
223 }
224 my $buildtype = $settings->{'buildtype'};
225
226 if (defined $collectcfg->{"orthogonalbuildtypes"}) {
227 # Note the use of collectcfg, not buildcfg
228 $settings->{'orthogonalbuildtypes'} = $collectcfg->{"orthogonalbuildtypes"};
229 } else {
230 $settings->{'orthogonalbuildtypes '}= [];
231 }
232 if (defined $collectcfg->{"orthogonalcustomservicerack"}) {
233 # Note the use of collectcfg, not buildcfg
234 $settings->{'orthogonalcustomservicerack'} = $collectcfg->{"orthogonalcustomservicerack"};
235 } else {
236 $settings->{'orthogonalcustomservicerack'}= {};
237 }
238
239 if (defined $buildcfg->{"numdocs"}) {
240 $settings->{'numdocs'} = $buildcfg->{"numdocs"};
241 }
242 else {
243 $settings->{'numdocs'} = 0;
244 }
245
246 my $service_type = "MGPP";
247 if ($buildtype eq "mg") {
248 $service_type = "MG";
249 } elsif ($buildtype eq "lucene") {
250 $service_type = "Lucene";
251 } elsif ($buildtype eq "solr") {
252 $service_type = "Solr";
253 }
254 $settings->{'service_type'} = $service_type;
255
256
257 if (defined $buildcfg->{"infodbtype"}) {
258 $settings->{'infodbtype'} = $buildcfg->{'infodbtype'};
259 }
260 else {
261 $settings->{'infodbtype'} = "gdbm";
262 }
263
264
265 #--
266 # indexes
267 #--
268
269 my $indexmap = {}; # maps index name to shortname
270 my $indexlist = []; # keeps the order for indexes
271 my $defaultindex = "";
272 my $maptype = ($buildtype eq "mg") ? "indexmap" : "indexfieldmap";
273
274 if (defined $buildcfg->{$maptype}) {
275 my $first = 1;
276 my $indexmap_t = $buildcfg->{$maptype};
277 foreach my $i (@$indexmap_t) {
278 my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
279 $indexmap->{$k} = $v;
280 push @$indexlist, $k;
281 if ($first) {
282 $defaultindex = $v;
283 $first = 0;
284 }
285 }
286 # now if the user has assigned a default index, we use it
287 if (defined $collectcfg->{"defaultindex"}) {
288 $defaultindex = $indexmap->{$collectcfg->{"defaultindex"}};
289 }
290 } else {
291 print STDERR "$maptype not defined\n";
292 }
293
294 $settings->{'num_indexes'} = $buildcfg->{'num_indexes'};
295 $settings->{'defaultindex'} = $defaultindex;
296 $settings->{'indexmap'} = $indexmap;
297 $settings->{'indexlist'} = $indexlist;
298
299 #--
300 # default lang
301 #--
302 $settings->{'default_lang'} = "";
303 $settings->{'default_lang_short'} = "";
304
305 if (defined $buildcfg->{"languagemap"}) {
306 my $langmap_t = $buildcfg->{"languagemap"};
307 if ((defined $langmap_t) && (scalar(@$langmap_t)>=1)) {
308 my $l = $langmap_t->[0];
309 my ($k, $v) = $l =~ m/^(.*)\-\>(.*)$/;
310 $settings->{'default_lang'} = $k; #name
311 $settings->{'default_lang_short'} = $v; #short name
312 }
313
314 # now if the user has assigned a default language (as "en", "ru" etc.)
315 if (defined $collectcfg->{"defaultlanguage"}) {
316 $settings->{'default_lang'} = $collectcfg->{"defaultlanguage"};
317 # what about default_lang_short ?? ####
318 }
319 }
320
321 # default subcol
322 $settings->{'default_subcol'} = "";
323 if (defined $buildcfg->{'subcollectionmap'}) {
324 my $subcolmap_t = $buildcfg->{'subcollectionmap'};
325 if ((defined $subcolmap_t) && (scalar(@$subcolmap_t)>=1)) {
326 my $l = $subcolmap_t->[0];
327 my ($k, $v) = $l =~ m/^(.*)\-\>(.*)$/;
328
329 $settings->{'default_subcol'} = $v;
330 }
331 }
332
333
334 #--
335 # indexstem
336 #--
337 if (defined $buildcfg->{'indexstem'}) {
338 $settings->{'indexstem'} = $buildcfg->{'indexstem'};
339 }
340
341 #--
342 # levelList
343 #--
344
345 my $levelmap = {};
346 my $levellist = [];
347 my $default_search_level = "Doc";
348 my $default_retrieve_level = "Doc";
349 my $default_db_level = "Doc";
350
351 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
352 if (defined $buildcfg->{'levelmap'}) {
353 my $first = 1;
354
355 my $levelmap_t = $buildcfg->{'levelmap'};
356 foreach my $l (@$levelmap_t) {
357 my ($key, $val) = $l =~ /^(.*)\-\>(.*)$/;
358 $levelmap->{$key} = $val;
359 push @$levellist, $key;
360 if ($first) {
361 # let default search level follow the first level in the level list
362 $default_search_level = $val;
363 # retrieve/database levels may get modified later if text level is defined
364 $default_retrieve_level = $val;
365 $default_db_level = $val;
366 $first = 0;
367 }
368 }
369 }
370 # the default level assigned by the user is no longer ignored [Shaoqun], but the retrievel level stays the same.
371 if (defined $collectcfg->{"defaultlevel"}) {
372 $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
373 # $default_retrieve_level = $default_search_level;
374 }
375
376 if (defined $buildcfg->{'textlevel'}) {
377 # let the retrieve/database levels always follow the textlevel
378 $default_retrieve_level = $buildcfg->{'textlevel'};
379 $default_db_level = $buildcfg->{'textlevel'};
380
381 }
382 }
383 $settings->{'levelmap'} = $levelmap;
384 $settings->{'levellist'} = $levellist;
385 $settings->{'default_search_level'} = $default_search_level if $default_search_level;
386 $settings->{'default_retrieve_level'} = $default_retrieve_level;
387 $settings->{'default_db_level'} = $default_db_level;
388
389 # sort field list
390 ######
391
392 my $sortmap = {}; # maps index name to shortname
393 my $sortlist = []; # keeps the order for indexes
394 my $defaultsort = "";
395
396 if (defined ($buildcfg->{"indexsortfieldmap"})) {
397 my $first = 1;
398
399 my $sortmap_t = $buildcfg->{"indexsortfieldmap"};
400 foreach my $s (@$sortmap_t) {
401 my ($k, $v) = $s =~ /^(.*)\-\>(.*)$/;
402 $sortmap->{$k} = $v;
403 $sortmap->{$v} = $k;
404 if ($first) {
405 $defaultsort = $v;
406 $first = 0;
407 }
408 }
409 }
410 if (defined ($buildcfg->{"indexsortfields"})) {
411 $sortlist = $buildcfg->{"indexsortfields"};
412 }
413
414 if (defined $collectcfg->{"defaultsort"}) {
415 $defaultsort = $sortmap->{$collectcfg->{"defaultsort"}};
416 }
417 $settings->{'sortlist'} = $sortlist;
418 $settings->{'sortmap'} = $sortmap;
419 $settings->{'defaultsort'} = $defaultsort;
420
421 # facet field list
422 ######
423
424 my $facetmap = {}; # maps index name to shortname
425 my $facetlist = []; # keeps the order for indexes
426
427 if (defined ($buildcfg->{"indexfacetfieldmap"})) {
428 my $facetmap_t = $buildcfg->{"indexfacetfieldmap"};
429 foreach my $s (@$facetmap_t) {
430 my ($k, $v) = $s =~ /^(.*)\-\>(.*)$/;
431 $facetmap->{$v} = $k;
432 }
433 }
434 if (defined ($buildcfg->{"indexfacetfields"})) {
435 $facetlist = $buildcfg->{"indexfacetfields"};
436 }
437
438 $settings->{'facetlist'} = $facetlist;
439 $settings->{'facetmap'} = $facetmap;
440
441
442 return $settings;
443}
444
445
446sub write_search_servicerack
447{
448 my ($buildcfg,$settings) = @_;
449
450 my $buildtype = $settings->{'buildtype'};
451 my $infodbtype = $settings->{'infodbtype'};
452 my $service_type = $settings->{'service_type'};
453
454 # there's no searching and therefore no search services if there are no indexes
455 return if($settings->{'num_indexes'} <= 0);
456
457 # do the search service
458 &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Search\">"]);
459 if (defined $buildcfg->{'indexstem'}) {
460 my $indexstem = $buildcfg->{'indexstem'};
461 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
462 }
463 if (defined $buildcfg->{'infodbtype'}) {
464 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
465 }
466
467 #indexes
468 my $indexmap = $settings->{'indexmap'};
469 my $indexlist = $settings->{'indexlist'};
470 my $defaultindex = $settings->{'defaultindex'};
471
472 #for each index in indexList, write them out
473 &write_line('COLCFG', ["<indexList>"]);
474 foreach my $i (@$indexlist) {
475 my $index = $indexmap->{$i};
476 &write_line('COLCFG', ["<index name=\"", $i, "\" ", "shortname=\"", $index, "\" />"]);
477 }
478 &write_line('COLCFG', ["</indexList>"]);
479
480
481 #$defaultindex = "ZZ" if (!$defaultindex); # index allfields by default
482 if ($defaultindex) {
483 &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
484 }
485
486
487 # do indexOptionList
488 if ($buildtype eq "mg" || $buildtype eq "mgpp") {
489 &write_line('COLCFG', ["<indexOptionList>"]);
490 my $stemindexes = 3; # default is stem and casefold
491 if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
492 $stemindexes = $buildcfg->{'stemindexes'};
493 }
494 &write_line('COLCFG', ["<indexOption name=\"stemIndexes\" value=\"", $stemindexes, "\" />"]);
495
496 my $maxnumeric = 4; # default
497 if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
498 $maxnumeric = $buildcfg->{'maxnumeric'};
499 }
500 &write_line('COLCFG', ["<indexOption name=\"maxnumeric\" value=\"", $maxnumeric, "\" />"]);
501 &write_line('COLCFG', ["</indexOptionList>"]);
502 }
503
504 #--
505 # levelList
506 #--
507 my $levelmap = $settings->{'levelmap'};
508 my $levellist = $settings->{'levellist'};
509 my $default_search_level = $settings->{'default_search_level'};
510 my $default_retrieve_level = $settings->{'default_retrieve_level'};
511 my $default_db_level = $settings->{'default_db_level'};
512
513 #for each level in levelList, write them out
514 if ($buildtype ne "mg") {
515 &write_line('COLCFG', ["<levelList>"]);
516 foreach my $lv (@$levellist) {
517 my $level = $levelmap->{$lv};
518 &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
519 }
520 &write_line('COLCFG', ["</levelList>"]);
521 }
522 # add in defaultLevel as the same level as indexLevelList, making the reading job easier
523 if ($buildtype eq "lucene" || $buildtype eq "mgpp" || $buildtype eq "solr") {
524 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
525 }
526 if ($buildtype eq "lucene" || $buildtype eq "mgpp" || $buildtype eq "solr") {
527 &write_line('COLCFG', ["<defaultDBLevel shortname=\"", $default_db_level, "\" />"]);
528 }
529
530 # do sort list
531 if ($buildtype eq "lucene" || $buildtype eq "solr") {
532 my $sortlist = $settings->{'sortlist'};
533 my $sortmap = $settings->{'sortmap'};
534 &write_line('COLCFG', ["<sortList>"]);
535 foreach my $sf (@$sortlist) {
536 my $sortf;
537 if ($sf eq "rank" || $sf eq "none") {
538 $sortf = $sf;
539 } else {
540 $sortf = $sortmap->{$sf};
541 }
542 &write_line('COLCFG', ["<sort name=\"", $sortf, "\" shortname=\"", $sf, "\" />"]);
543
544 }
545 &write_line('COLCFG', ["</sortList>"]);
546 &write_line('COLCFG', ["<defaultSort shortname=\"", $settings->{'defaultsort'}, "\" />"]);
547 }
548
549 # do facet list
550 if ($buildtype eq "solr") {
551 &write_line('COLCFG', ["<facetList>"]);
552 my $facetlist = $settings->{'facetlist'};
553 my $facetmap = $settings->{'facetmap'};
554 foreach my $ff (@$facetlist) {
555 my $facetf = $facetmap->{$ff};
556 &write_line('COLCFG', ["<facet name=\"", $facetf, "\" shortname=\"", $ff, "\" />"]);
557 }
558 &write_line('COLCFG', ["</facetList>"]);
559 }
560 # do searchTypeList
561 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
562 &write_line('COLCFG', ["<searchTypeList>"]);
563
564 if (defined $buildcfg->{"searchtype"}) {
565 my $searchtype_t = $buildcfg->{"searchtype"};
566 foreach my $s (@$searchtype_t) {
567 &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
568 }
569 } else {
570 &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
571 &write_line('COLCFG', ["<searchType name=\"form\" />"]);
572 }
573 &write_line('COLCFG', ["</searchTypeList>"]);
574 }
575
576 # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
577 my $default_lang = $settings->{'default_lang'};
578 my $default_lang_short = $settings->{'default_lang_short'};
579 if (defined $buildcfg->{"languagemap"}) {
580 &write_line('COLCFG', ["<indexLanguageList>"]);
581
582 my $langmap_t = $buildcfg->{"languagemap"};
583 foreach my $l (@$langmap_t) {
584 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
585
586 &write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
587 }
588
589 &write_line('COLCFG', ["</indexLanguageList>"]);
590
591 &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
592 }
593
594 # do indexSubcollectionList
595 my $default_subcol = $settings->{'default_subcol'};
596
597 if (defined $buildcfg->{'subcollectionmap'}) {
598 &write_line('COLCFG', ["<indexSubcollectionList>"]);
599 my $subcolmap = {};
600 my @subcollist = ();
601
602 my $subcolmap_t = $buildcfg->{'subcollectionmap'};
603 foreach my $l (@$subcolmap_t) {
604 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
605 $subcolmap->{$k} = $v;
606 push @subcollist, $k;
607 }
608
609 foreach my $sl (@subcollist) {
610 my $subcol = $subcolmap->{$sl};
611 &write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
612 }
613
614 &write_line('COLCFG', ["</indexSubcollectionList>"]);
615 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
616 }
617
618 # do solr core list
619 if ($buildtype eq "solr") {
620 &write_line('COLCFG', ["<solrcoreList>"]);
621
622 foreach my $core (@{$buildcfg->{'solrcores'}}) {
623 &write_line('COLCFG', ["<solrcore name=\"", $core, "\" />"]);
624 }
625 &write_line('COLCFG', ["</solrcoreList>"]);
626 }
627 # close off search service
628 &write_line('COLCFG', ["</serviceRack>"]);
629
630}
631
632
633sub write_orthogonalsearch_serviceracks
634{
635 my ($buildcfg,$settings) = @_;
636
637 #return if($settings->{'num_indexes'} <= 0); # no search if no indexes
638
639 my $infodbtype = $settings->{'infodbtype'};
640
641 my $orthogonalbuildtypes = $settings->{'orthogonalbuildtypes'};
642
643 #if a custom service rack has been specified, then we don't output anything here
644 my $orthogonalcustomservicerack = $settings->{'orthogonalcustomservicerack'};
645
646 foreach my $obt (@$orthogonalbuildtypes) {
647 if (!defined $orthogonalcustomservicerack->{$obt}) {
648 $obt =~ s/^(.)/\u$1/; # capitialize initial letter
649 $obt =~ s/-(.)/\u$1/g; # change any hyphenated words to cap next letter
650
651 &write_line('COLCFG', ["<serviceRack name=\"GS2", $obt, "Search\">"]);
652
653 &write_line('COLCFG',["<databaseType name=\"",$infodbtype,"\" />"]);
654 &write_line('COLCFG', ["</serviceRack>"]);
655 print STDERR "Outputting orthogonal service rack to buildConfig, derived name = GS2".$obt. "Search\n";
656 } else {
657 print STDERR "Orthogonal search specified a serviceRack: ".$orthogonalcustomservicerack->{$obt}.", make sure you have specified that in your collectionConfig.xml serviceRackList\n";
658 }
659
660 }
661}
662
663
664
665sub write_retrieve_servicerack
666{
667 my ($buildcfg,$settings) = @_;
668
669 my $buildtype = $settings->{'buildtype'};
670 my $infodbtype = $settings->{'infodbtype'};
671
672 my $service_type = $settings->{'service_type'};
673
674 # do the retrieve service
675 &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
676
677 # do default index
678 if (defined $buildcfg->{"languagemap"}) {
679 my $default_lang = $settings->{'default_lang'};
680 &write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
681 }
682 if (defined $buildcfg->{'subcollectionmap'}) {
683 my $default_subcol = $settings->{'default_subcol'};
684 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
685 }
686 if ($buildtype eq "mg") {
687 my $defaultindex = $settings->{'defaultindex'};
688 &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
689 }
690
691 if (defined $buildcfg->{'indexstem'}) {
692 my $indexstem = $buildcfg->{'indexstem'};
693 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
694 }
695 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
696 my $default_retrieve_level = $settings->{'default_retrieve_level'};
697 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
698 }
699 if (defined $buildcfg->{'infodbtype'}) {
700 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
701 }
702
703 &write_line('COLCFG', ["</serviceRack>"]);
704
705}
706
707
708# Create the buildConfig.xml file for a specific collection
709sub write_cfg_file {
710 # this sub is called in make_auxiliary_files() in basebuilder.pm
711 # the received args: $buildoutfile - destination file: buildConfig.xml
712 # $buildcfg - all build options,
713 # $collectcfg - contents of collectionConfig.xml read in by read_cfg_file sub in buildConfigxml.pm.
714 my ($buildoutfile, $buildcfg, $collectcfg) = @_;
715 my $line = [];
716
717 if (!open (COLCFG, ">$buildoutfile")) {
718 print STDERR "buildConfigxml::write_cfg_file couldn't write the build config file $buildoutfile\n";
719 die;
720 }
721
722 my $settings = search_and_retrieve_settings($buildcfg,$collectcfg);
723
724 my $buildtype = $settings->{'buildtype'};
725 my $orthogonalbuildtypes = $settings->{'orthogonalbuildtypes'};
726 my $numdocs = $settings->{'numdocs'};
727
728 &write_line('COLCFG', ["<buildConfig xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">"]);
729
730 # output building metadata to build config file
731 &write_line('COLCFG', ["<metadataList>"]);
732 &write_line('COLCFG', ["<metadata name=\"numDocs\">", $numdocs, "</metadata>"]);
733 &write_line('COLCFG', ["<metadata name=\"buildType\">", $buildtype, "</metadata>"]);
734 foreach my $obt (@$orthogonalbuildtypes) {
735 &write_line('COLCFG', ["<metadata name=\"orthogonalBuildTypes\">", $obt, "</metadata>"]);
736 }
737
738 if (defined $buildcfg->{'indexstem'}) {
739 &write_line('COLCFG', ["<metadata name=\"indexStem\">", $buildcfg->{"indexstem"}, "</metadata>"]);
740 }
741 if (defined $buildcfg->{'infodbtype'}) {
742 &write_line('COLCFG', ["<metadata name=\"infodbType\">", $buildcfg->{"infodbtype"}, "</metadata>"]);
743 }
744 if (defined $buildcfg->{'builddate'}) {
745 &write_line('COLCFG', ["<metadata name=\"buildDate\">", $buildcfg->{"builddate"}, "</metadata>"]);
746 }
747 if (defined $buildcfg->{'earliestdatestamp'}) {
748 &write_line('COLCFG', ["<metadata name=\"earliestDatestamp\">", $buildcfg->{"earliestdatestamp"}, "</metadata>"]);
749 }
750
751 &write_line('COLCFG', ["</metadataList>"]);
752
753 # output serviceRackList
754 &write_line('COLCFG', ["<serviceRackList>"]);
755
756 write_search_servicerack($buildcfg,$settings);
757
758 # add in orthogonalbuildtypes
759 write_orthogonalsearch_serviceracks($buildcfg,$settings);
760
761 write_retrieve_servicerack($buildcfg,$settings);
762
763 # do the browse service
764 my $count = 1;
765 my $phind = 0;
766 my $started_classifiers = 0;
767
768 my $classifiers = $collectcfg->{"classify"};
769 foreach my $cl (@$classifiers) {
770 my $name = "CL$count";
771 $count++;
772 my ($classname) = @$cl[0];
773 if ($classname =~ /^phind$/i) {
774 $phind=1;
775 #should add it into coll config classifiers
776 next;
777 }
778
779 if (not $started_classifiers) {
780 &write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
781 if (defined $buildcfg->{'indexstem'}) {
782 my $indexstem = $buildcfg->{'indexstem'};
783 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
784 }
785 if (defined $buildcfg->{'infodbtype'}) {
786 my $infodbtype = $buildcfg->{'infodbtype'};
787 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
788 }
789 &write_line('COLCFG', ["<classifierList>"]);
790 $started_classifiers = 1;
791 }
792 my $content = ''; #use buttonname first, then metadata
793 my $hfilename = '';
794 my $metadataname = '';
795 if ($classname eq "DateList") {
796 $content = "Date";
797 } else {
798 for (my $j=0; $j<scalar(@$cl); $j++) {
799 my $arg = @$cl[$j];
800 if ($classname eq "Hierarchy")
801 {
802 if ($arg eq "-hfile")
803 {
804 $hfilename = @$cl[$j+1];
805 }
806 elsif ($arg eq "-metadata")
807 {
808 $metadataname = @$cl[$j+1];
809 }
810 }
811 if ($arg eq "-buttonname"){
812 $content = @$cl[$j+1];
813 last;
814 } elsif ($arg eq "-metadata") {
815 $content = @$cl[$j+1];
816 }
817
818 }
819 }
820 if ($classname eq "Hierarchy")
821 {
822 &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" metadata=\"", $metadataname, "\" hfile=\"", $hfilename, "\" />"]);
823 } else
824 {
825 &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
826 }
827 }
828 if ($started_classifiers) {
829 # end the classifiers
830 &write_line('COLCFG', ["</classifierList>"]);
831 # close off the Browse service
832 &write_line('COLCFG', ["</serviceRack>"]);
833 }
834
835 # the phind classifier is a separate service
836 if ($phind) {
837 # if phind classifier
838 &write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
839 }
840
841
842 &write_line('COLCFG', ["</serviceRackList>"]);
843 &write_line('COLCFG', ["</buildConfig>"]);
844
845 close (COLCFG);
846}
847
848
849#########################################################
850
8511;
Note: See TracBrowser for help on using the repository browser.