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

Last change on this file since 36839 was 36839, checked in by kjdon, 19 months ago

added serviceRack attribute to <search name='xxx' orthogonal='true'> - if specified, then you can write the serviceRack directly into collectionConfig serviceRackList, instead of it auto generating one (named GS2+<search_name>+Search) into buildConfig

  • Property svn:keywords set to Author Date Id Revision
File size: 26.1 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
141}
142
143sub EndTag {
144 my ($expat, $element) = @_;
145}
146
147sub Text {
148 if (defined $currentLocation) {
149 #@ Handling block metadataList(numDocs, buildType)
150 if ($currentLocation =~ /$stringexp/) {
151 #print $currentLocation;
152 my $key = $nameMap->{$currentLocation};
153 $data->{$key} = $_;
154 undef $currentLocation;
155 }
156 elsif ($currentLocation =~ /$arrayexp/) {
157 #print $currentLocation;
158 my $key = $nameMap->{$currentLocation};
159 push(@{$data->{$key}},$_);
160 undef $currentLocation;
161 }
162
163 }
164}
165
166# This sub is for debugging purposes
167sub Display {
168
169 print "NumDocs = ".$data->{'numdocs'}."\n" if (defined $data->{'numdocs'});
170 print "BuildType = ".$data->{'buildtype'}."\n" if (defined $data->{'buildtype'});
171 print "OrthogonalBuildTypes = ".join(",",@{$data->{'orthogonalbuildtypes'}})."\n" if (defined $data->{'orthogonalbuildtypes'});
172 print "IndexMap = ". join(" ",@{$data->{'indexmap'}})."\n" if (defined $data->{'indexmap'});
173 print "IndexFieldMap = ". join(" ",@{$data->{'indexfieldmap'}})."\n" if (defined $data->{'indexfieldmap'});
174 print "IndexFields = ". join(" ",@{$data->{'indexfields'}})."\n" if (defined $data->{'indexfields'});
175
176}
177
178# is this actually used??
179sub Doctype {
180 my ($expat, $name, $sysid, $pubid, $internal) = @_;
181
182 die if ($name !~ /^buildConfig$/);
183}
184
185# This Char function overrides the one in XML::Parser::Stream to overcome a
186# problem where $expat->{Text} is treated as the return value, slowing
187# things down significantly in some cases.
188sub Char {
189 if ($]<5.008) {
190 use bytes; # Necessary to prevent encoding issues with XML::Parser 2.31+ and Perl 5.6
191 }
192 $_[0]->{'Text'} .= $_[1];
193 return undef;
194}
195
196
197
198sub write_line {
199 my ($filehandle, $line) = @_;
200 print $filehandle join ("", @$line), "\n";
201}
202
203sub search_and_retrieve_settings
204{
205 my ($buildcfg,$collectcfg) = @_;
206
207 my $settings = {};
208
209 if (defined $buildcfg->{"buildtype"}) {
210 $settings->{'buildtype'} = $buildcfg->{"buildtype"};
211 } else {
212 $settings->{'buildtype'} = "mgpp";
213 }
214 my $buildtype = $settings->{'buildtype'};
215
216 if (defined $collectcfg->{"orthogonalbuildtypes"}) {
217 # Note the use of collectcfg, not buildcfg
218 $settings->{'orthogonalbuildtypes'} = $collectcfg->{"orthogonalbuildtypes"};
219 } else {
220 $settings->{'orthogonalbuildtypes '}= [];
221 }
222 if (defined $collectcfg->{"orthogonalcustomservicerack"}) {
223 # Note the use of collectcfg, not buildcfg
224 $settings->{'orthogonalcustomservicerack'} = $collectcfg->{"orthogonalcustomservicerack"};
225 } else {
226 $settings->{'orthogonalcustomservicerack'}= {};
227 }
228
229 if (defined $buildcfg->{"numdocs"}) {
230 $settings->{'numdocs'} = $buildcfg->{"numdocs"};
231 }
232 else {
233 $settings->{'numdocs'} = 0;
234 }
235
236 my $service_type = "MGPP";
237 if ($buildtype eq "mg") {
238 $service_type = "MG";
239 } elsif ($buildtype eq "lucene") {
240 $service_type = "Lucene";
241 } elsif ($buildtype eq "solr") {
242 $service_type = "Solr";
243 }
244 $settings->{'service_type'} = $service_type;
245
246
247 if (defined $buildcfg->{"infodbtype"}) {
248 $settings->{'infodbtype'} = $buildcfg->{'infodbtype'};
249 }
250 else {
251 $settings->{'infodbtype'} = "gdbm";
252 }
253
254
255 #--
256 # indexes
257 #--
258
259 my $indexmap = {}; # maps index name to shortname
260 my $indexlist = []; # keeps the order for indexes
261 my $defaultindex = "";
262 my $maptype = ($buildtype eq "mg") ? "indexmap" : "indexfieldmap";
263
264 if (defined $buildcfg->{$maptype}) {
265 my $first = 1;
266 my $indexmap_t = $buildcfg->{$maptype};
267 foreach my $i (@$indexmap_t) {
268 my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
269 $indexmap->{$k} = $v;
270 push @$indexlist, $k;
271 if ($first) {
272 $defaultindex = $v;
273 $first = 0;
274 }
275 }
276 # now if the user has assigned a default index, we use it
277 if (defined $collectcfg->{"defaultindex"}) {
278 $defaultindex = $indexmap->{$collectcfg->{"defaultindex"}};
279 }
280 } else {
281 print STDERR "$maptype not defined\n";
282 }
283
284 $settings->{'num_indexes'} = $buildcfg->{'num_indexes'};
285 $settings->{'defaultindex'} = $defaultindex;
286 $settings->{'indexmap'} = $indexmap;
287 $settings->{'indexlist'} = $indexlist;
288
289 #--
290 # default lang
291 #--
292 $settings->{'default_lang'} = "";
293 $settings->{'default_lang_short'} = "";
294
295 if (defined $buildcfg->{"languagemap"}) {
296 my $langmap_t = $buildcfg->{"languagemap"};
297 if ((defined $langmap_t) && (scalar(@$langmap_t)>=1)) {
298 my $l = $langmap_t->[0];
299 my ($k, $v) = $l =~ m/^(.*)\-\>(.*)$/;
300 $settings->{'default_lang'} = $k; #name
301 $settings->{'default_lang_short'} = $v; #short name
302 }
303
304 # now if the user has assigned a default language (as "en", "ru" etc.)
305 if (defined $collectcfg->{"defaultlanguage"}) {
306 $settings->{'default_lang'} = $collectcfg->{"defaultlanguage"};
307 # what about default_lang_short ?? ####
308 }
309 }
310
311 # default subcol
312 $settings->{'default_subcol'} = "";
313 if (defined $buildcfg->{'subcollectionmap'}) {
314 my $subcolmap_t = $buildcfg->{'subcollectionmap'};
315 if ((defined $subcolmap_t) && (scalar(@$subcolmap_t)>=1)) {
316 my $l = $subcolmap_t->[0];
317 my ($k, $v) = $l =~ m/^(.*)\-\>(.*)$/;
318
319 $settings->{'default_subcol'} = $v;
320 }
321 }
322
323
324 #--
325 # indexstem
326 #--
327 if (defined $buildcfg->{'indexstem'}) {
328 $settings->{'indexstem'} = $buildcfg->{'indexstem'};
329 }
330
331 #--
332 # levelList
333 #--
334
335 my $levelmap = {};
336 my $levellist = [];
337 my $default_search_level = "Doc";
338 my $default_retrieve_level = "Doc";
339 my $default_db_level = "Doc";
340
341 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
342 if (defined $buildcfg->{'levelmap'}) {
343 my $first = 1;
344
345 my $levelmap_t = $buildcfg->{'levelmap'};
346 foreach my $l (@$levelmap_t) {
347 my ($key, $val) = $l =~ /^(.*)\-\>(.*)$/;
348 $levelmap->{$key} = $val;
349 push @$levellist, $key;
350 if ($first) {
351 # let default search level follow the first level in the level list
352 $default_search_level = $val;
353 # retrieve/database levels may get modified later if text level is defined
354 $default_retrieve_level = $val;
355 $default_db_level = $val;
356 $first = 0;
357 }
358 }
359 }
360 # the default level assigned by the user is no longer ignored [Shaoqun], but the retrievel level stays the same.
361 if (defined $collectcfg->{"defaultlevel"}) {
362 $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
363 # $default_retrieve_level = $default_search_level;
364 }
365
366 if (defined $buildcfg->{'textlevel'}) {
367 # let the retrieve/database levels always follow the textlevel
368 $default_retrieve_level = $buildcfg->{'textlevel'};
369 $default_db_level = $buildcfg->{'textlevel'};
370
371 }
372 }
373 $settings->{'levelmap'} = $levelmap;
374 $settings->{'levellist'} = $levellist;
375 $settings->{'default_search_level'} = $default_search_level if $default_search_level;
376 $settings->{'default_retrieve_level'} = $default_retrieve_level;
377 $settings->{'default_db_level'} = $default_db_level;
378
379 # sort field list
380 ######
381
382 my $sortmap = {}; # maps index name to shortname
383 my $sortlist = []; # keeps the order for indexes
384 my $defaultsort = "";
385
386 if (defined ($buildcfg->{"indexsortfieldmap"})) {
387 my $first = 1;
388
389 my $sortmap_t = $buildcfg->{"indexsortfieldmap"};
390 foreach my $s (@$sortmap_t) {
391 my ($k, $v) = $s =~ /^(.*)\-\>(.*)$/;
392 $sortmap->{$k} = $v;
393 $sortmap->{$v} = $k;
394 if ($first) {
395 $defaultsort = $v;
396 $first = 0;
397 }
398 }
399 }
400 if (defined ($buildcfg->{"indexsortfields"})) {
401 $sortlist = $buildcfg->{"indexsortfields"};
402 }
403
404 if (defined $collectcfg->{"defaultsort"}) {
405 $defaultsort = $sortmap->{$collectcfg->{"defaultsort"}};
406 }
407 $settings->{'sortlist'} = $sortlist;
408 $settings->{'sortmap'} = $sortmap;
409 $settings->{'defaultsort'} = $defaultsort;
410
411 # facet field list
412 ######
413
414 my $facetmap = {}; # maps index name to shortname
415 my $facetlist = []; # keeps the order for indexes
416
417 if (defined ($buildcfg->{"indexfacetfieldmap"})) {
418 my $facetmap_t = $buildcfg->{"indexfacetfieldmap"};
419 foreach my $s (@$facetmap_t) {
420 my ($k, $v) = $s =~ /^(.*)\-\>(.*)$/;
421 $facetmap->{$v} = $k;
422 }
423 }
424 if (defined ($buildcfg->{"indexfacetfields"})) {
425 $facetlist = $buildcfg->{"indexfacetfields"};
426 }
427
428 $settings->{'facetlist'} = $facetlist;
429 $settings->{'facetmap'} = $facetmap;
430
431
432 return $settings;
433}
434
435
436sub write_search_servicerack
437{
438 my ($buildcfg,$settings) = @_;
439
440 my $buildtype = $settings->{'buildtype'};
441 my $infodbtype = $settings->{'infodbtype'};
442 my $service_type = $settings->{'service_type'};
443
444 # there's no searching and therefore no search services if there are no indexes
445 return if($settings->{'num_indexes'} <= 0);
446
447 # do the search service
448 &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Search\">"]);
449 if (defined $buildcfg->{'indexstem'}) {
450 my $indexstem = $buildcfg->{'indexstem'};
451 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
452 }
453 if (defined $buildcfg->{'infodbtype'}) {
454 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
455 }
456
457 #indexes
458 my $indexmap = $settings->{'indexmap'};
459 my $indexlist = $settings->{'indexlist'};
460 my $defaultindex = $settings->{'defaultindex'};
461
462 #for each index in indexList, write them out
463 &write_line('COLCFG', ["<indexList>"]);
464 foreach my $i (@$indexlist) {
465 my $index = $indexmap->{$i};
466 &write_line('COLCFG', ["<index name=\"", $i, "\" ", "shortname=\"", $index, "\" />"]);
467 }
468 &write_line('COLCFG', ["</indexList>"]);
469
470
471 #$defaultindex = "ZZ" if (!$defaultindex); # index allfields by default
472 if ($defaultindex) {
473 &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
474 }
475
476
477 # do indexOptionList
478 if ($buildtype eq "mg" || $buildtype eq "mgpp") {
479 &write_line('COLCFG', ["<indexOptionList>"]);
480 my $stemindexes = 3; # default is stem and casefold
481 if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
482 $stemindexes = $buildcfg->{'stemindexes'};
483 }
484 &write_line('COLCFG', ["<indexOption name=\"stemIndexes\" value=\"", $stemindexes, "\" />"]);
485
486 my $maxnumeric = 4; # default
487 if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
488 $maxnumeric = $buildcfg->{'maxnumeric'};
489 }
490 &write_line('COLCFG', ["<indexOption name=\"maxnumeric\" value=\"", $maxnumeric, "\" />"]);
491 &write_line('COLCFG', ["</indexOptionList>"]);
492 }
493
494 #--
495 # levelList
496 #--
497 my $levelmap = $settings->{'levelmap'};
498 my $levellist = $settings->{'levellist'};
499 my $default_search_level = $settings->{'default_search_level'};
500 my $default_retrieve_level = $settings->{'default_retrieve_level'};
501 my $default_db_level = $settings->{'default_db_level'};
502
503 #for each level in levelList, write them out
504 if ($buildtype ne "mg") {
505 &write_line('COLCFG', ["<levelList>"]);
506 foreach my $lv (@$levellist) {
507 my $level = $levelmap->{$lv};
508 &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
509 }
510 &write_line('COLCFG', ["</levelList>"]);
511 }
512 # add in defaultLevel as the same level as indexLevelList, making the reading job easier
513 if ($buildtype eq "lucene" || $buildtype eq "mgpp" || $buildtype eq "solr") {
514 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
515 }
516 if ($buildtype eq "lucene" || $buildtype eq "mgpp" || $buildtype eq "solr") {
517 &write_line('COLCFG', ["<defaultDBLevel shortname=\"", $default_db_level, "\" />"]);
518 }
519
520 # do sort list
521 if ($buildtype eq "lucene" || $buildtype eq "solr") {
522 my $sortlist = $settings->{'sortlist'};
523 my $sortmap = $settings->{'sortmap'};
524 &write_line('COLCFG', ["<sortList>"]);
525 foreach my $sf (@$sortlist) {
526 my $sortf;
527 if ($sf eq "rank" || $sf eq "none") {
528 $sortf = $sf;
529 } else {
530 $sortf = $sortmap->{$sf};
531 }
532 &write_line('COLCFG', ["<sort name=\"", $sortf, "\" shortname=\"", $sf, "\" />"]);
533
534 }
535 &write_line('COLCFG', ["</sortList>"]);
536 &write_line('COLCFG', ["<defaultSort shortname=\"", $settings->{'defaultsort'}, "\" />"]);
537 }
538
539 # do facet list
540 if ($buildtype eq "solr") {
541 &write_line('COLCFG', ["<facetList>"]);
542 my $facetlist = $settings->{'facetlist'};
543 my $facetmap = $settings->{'facetmap'};
544 foreach my $ff (@$facetlist) {
545 my $facetf = $facetmap->{$ff};
546 &write_line('COLCFG', ["<facet name=\"", $facetf, "\" shortname=\"", $ff, "\" />"]);
547 }
548 &write_line('COLCFG', ["</facetList>"]);
549 }
550 # do searchTypeList
551 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
552 &write_line('COLCFG', ["<searchTypeList>"]);
553
554 if (defined $buildcfg->{"searchtype"}) {
555 my $searchtype_t = $buildcfg->{"searchtype"};
556 foreach my $s (@$searchtype_t) {
557 &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
558 }
559 } else {
560 &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
561 &write_line('COLCFG', ["<searchType name=\"form\" />"]);
562 }
563 &write_line('COLCFG', ["</searchTypeList>"]);
564 }
565
566 # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
567 my $default_lang = $settings->{'default_lang'};
568 my $default_lang_short = $settings->{'default_lang_short'};
569 if (defined $buildcfg->{"languagemap"}) {
570 &write_line('COLCFG', ["<indexLanguageList>"]);
571
572 my $langmap_t = $buildcfg->{"languagemap"};
573 foreach my $l (@$langmap_t) {
574 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
575
576 &write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
577 }
578
579 &write_line('COLCFG', ["</indexLanguageList>"]);
580
581 &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
582 }
583
584 # do indexSubcollectionList
585 my $default_subcol = $settings->{'default_subcol'};
586
587 if (defined $buildcfg->{'subcollectionmap'}) {
588 &write_line('COLCFG', ["<indexSubcollectionList>"]);
589 my $subcolmap = {};
590 my @subcollist = ();
591
592 my $subcolmap_t = $buildcfg->{'subcollectionmap'};
593 foreach my $l (@$subcolmap_t) {
594 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
595 $subcolmap->{$k} = $v;
596 push @subcollist, $k;
597 }
598
599 foreach my $sl (@subcollist) {
600 my $subcol = $subcolmap->{$sl};
601 &write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
602 }
603
604 &write_line('COLCFG', ["</indexSubcollectionList>"]);
605 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
606 }
607
608 # close off search service
609 &write_line('COLCFG', ["</serviceRack>"]);
610
611}
612
613
614sub write_orthogonalsearch_serviceracks
615{
616 my ($buildcfg,$settings) = @_;
617
618 #return if($settings->{'num_indexes'} <= 0); # no search if no indexes
619
620 my $infodbtype = $settings->{'infodbtype'};
621
622 my $orthogonalbuildtypes = $settings->{'orthogonalbuildtypes'};
623
624 #if a custom service rack has been specified, then we don't output anything here
625 my $orthogonalcustomservicerack = $settings->{'orthogonalcustomservicerack'};
626
627 foreach my $obt (@$orthogonalbuildtypes) {
628 if (!defined $orthogonalcustomservicerack->{$obt}) {
629 $obt =~ s/^(.)/\u$1/; # capitialize initial letter
630 $obt =~ s/-(.)/\u$1/g; # change any hyphenated words to cap next letter
631
632 &write_line('COLCFG', ["<serviceRack name=\"GS2", $obt, "Search\">"]);
633
634 &write_line('COLCFG',["<databaseType name=\"",$infodbtype,"\" />"]);
635 &write_line('COLCFG', ["</serviceRack>"]);
636 print STDERR "Outputting orthogonal service rack to buildConfig, derived name = GS2".$obt. "Search\n";
637 } else {
638 print STDERR "Orthogonal search specified a serviceRack: ".$orthogonalcustomservicerack->{$obt}.", make sure you have specified that in your collectionConfig.xml serviceRackList\n";
639 }
640
641 }
642}
643
644
645
646sub write_retrieve_servicerack
647{
648 my ($buildcfg,$settings) = @_;
649
650 my $buildtype = $settings->{'buildtype'};
651 my $infodbtype = $settings->{'infodbtype'};
652
653 my $service_type = $settings->{'service_type'};
654
655 # do the retrieve service
656 &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
657
658 # do default index
659 if (defined $buildcfg->{"languagemap"}) {
660 my $default_lang = $settings->{'default_lang'};
661 &write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
662 }
663 if (defined $buildcfg->{'subcollectionmap'}) {
664 my $default_subcol = $settings->{'default_subcol'};
665 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
666 }
667 if ($buildtype eq "mg") {
668 my $defaultindex = $settings->{'defaultindex'};
669 &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
670 }
671
672 if (defined $buildcfg->{'indexstem'}) {
673 my $indexstem = $buildcfg->{'indexstem'};
674 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
675 }
676 if ($buildtype eq "mgpp" || $buildtype eq "lucene" || $buildtype eq "solr") {
677 my $default_retrieve_level = $settings->{'default_retrieve_level'};
678 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
679 }
680 if (defined $buildcfg->{'infodbtype'}) {
681 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
682 }
683
684 &write_line('COLCFG', ["</serviceRack>"]);
685
686}
687
688
689# Create the buildConfig.xml file for a specific collection
690sub write_cfg_file {
691 # this sub is called in make_auxiliary_files() in basebuilder.pm
692 # the received args: $buildoutfile - destination file: buildConfig.xml
693 # $buildcfg - all build options,
694 # $collectcfg - contents of collectionConfig.xml read in by read_cfg_file sub in buildConfigxml.pm.
695 my ($buildoutfile, $buildcfg, $collectcfg) = @_;
696 my $line = [];
697
698 if (!open (COLCFG, ">$buildoutfile")) {
699 print STDERR "buildConfigxml::write_cfg_file couldn't write the build config file $buildoutfile\n";
700 die;
701 }
702
703 my $settings = search_and_retrieve_settings($buildcfg,$collectcfg);
704
705 my $buildtype = $settings->{'buildtype'};
706 my $orthogonalbuildtypes = $settings->{'orthogonalbuildtypes'};
707 my $numdocs = $settings->{'numdocs'};
708
709 &write_line('COLCFG', ["<buildConfig xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">"]);
710
711 # output building metadata to build config file
712 &write_line('COLCFG', ["<metadataList>"]);
713 &write_line('COLCFG', ["<metadata name=\"numDocs\">", $numdocs, "</metadata>"]);
714 &write_line('COLCFG', ["<metadata name=\"buildType\">", $buildtype, "</metadata>"]);
715 foreach my $obt (@$orthogonalbuildtypes) {
716 &write_line('COLCFG', ["<metadata name=\"orthogonalBuildTypes\">", $obt, "</metadata>"]);
717 }
718
719 if (defined $buildcfg->{'indexstem'}) {
720 &write_line('COLCFG', ["<metadata name=\"indexStem\">", $buildcfg->{"indexstem"}, "</metadata>"]);
721 }
722 if (defined $buildcfg->{'infodbtype'}) {
723 &write_line('COLCFG', ["<metadata name=\"infodbType\">", $buildcfg->{"infodbtype"}, "</metadata>"]);
724 }
725 if (defined $buildcfg->{'builddate'}) {
726 &write_line('COLCFG', ["<metadata name=\"buildDate\">", $buildcfg->{"builddate"}, "</metadata>"]);
727 }
728 if (defined $buildcfg->{'earliestdatestamp'}) {
729 &write_line('COLCFG', ["<metadata name=\"earliestDatestamp\">", $buildcfg->{"earliestdatestamp"}, "</metadata>"]);
730 }
731
732 &write_line('COLCFG', ["</metadataList>"]);
733
734 # output serviceRackList
735 &write_line('COLCFG', ["<serviceRackList>"]);
736
737 write_search_servicerack($buildcfg,$settings);
738
739 # add in orthogonalbuildtypes
740 write_orthogonalsearch_serviceracks($buildcfg,$settings);
741
742 write_retrieve_servicerack($buildcfg,$settings);
743
744 # do the browse service
745 my $count = 1;
746 my $phind = 0;
747 my $started_classifiers = 0;
748
749 my $classifiers = $collectcfg->{"classify"};
750 foreach my $cl (@$classifiers) {
751 my $name = "CL$count";
752 $count++;
753 my ($classname) = @$cl[0];
754 if ($classname =~ /^phind$/i) {
755 $phind=1;
756 #should add it into coll config classifiers
757 next;
758 }
759
760 if (not $started_classifiers) {
761 &write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
762 if (defined $buildcfg->{'indexstem'}) {
763 my $indexstem = $buildcfg->{'indexstem'};
764 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
765 }
766 if (defined $buildcfg->{'infodbtype'}) {
767 my $infodbtype = $buildcfg->{'infodbtype'};
768 &write_line('COLCFG', ["<databaseType name=\"", $infodbtype, "\" />"]);
769 }
770 &write_line('COLCFG', ["<classifierList>"]);
771 $started_classifiers = 1;
772 }
773 my $content = ''; #use buttonname first, then metadata
774 my $hfilename = '';
775 my $metadataname = '';
776 if ($classname eq "DateList") {
777 $content = "Date";
778 } else {
779 for (my $j=0; $j<scalar(@$cl); $j++) {
780 my $arg = @$cl[$j];
781 if ($classname eq "Hierarchy")
782 {
783 if ($arg eq "-hfile")
784 {
785 $hfilename = @$cl[$j+1];
786 }
787 elsif ($arg eq "-metadata")
788 {
789 $metadataname = @$cl[$j+1];
790 }
791 }
792 if ($arg eq "-buttonname"){
793 $content = @$cl[$j+1];
794 last;
795 } elsif ($arg eq "-metadata") {
796 $content = @$cl[$j+1];
797 }
798
799 }
800 }
801 if ($classname eq "Hierarchy")
802 {
803 &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" metadata=\"", $metadataname, "\" hfile=\"", $hfilename, "\" />"]);
804 } else
805 {
806 &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
807 }
808 }
809 if ($started_classifiers) {
810 # end the classifiers
811 &write_line('COLCFG', ["</classifierList>"]);
812 # close off the Browse service
813 &write_line('COLCFG', ["</serviceRack>"]);
814 }
815
816 # the phind classifier is a separate service
817 if ($phind) {
818 # if phind classifier
819 &write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
820 }
821
822
823 &write_line('COLCFG', ["</serviceRackList>"]);
824 &write_line('COLCFG', ["</buildConfig>"]);
825
826 close (COLCFG);
827 }
828
829
830#########################################################
831
8321;
Note: See TracBrowser for help on using the repository browser.