[1860] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * collectset.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 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 |
|
---|
[15402] | 27 | #include "collectset.h"
|
---|
[1860] | 28 | #include "collectserver.h"
|
---|
[15402] | 29 | #include "colservrconfig.h"
|
---|
| 30 | #include "gsdlsitecfg.h"
|
---|
[16895] | 31 | #include "gsdltools.h"
|
---|
[15759] | 32 | #include "fileutil.h"
|
---|
[1860] | 33 | #include "filter.h"
|
---|
| 34 | #include "browsefilter.h"
|
---|
[15759] | 35 | #include "sqlbrowsefilter.h"
|
---|
[22050] | 36 | #include "sqlqueryfilter.h"
|
---|
[1860] | 37 | #include "queryfilter.h"
|
---|
[21324] | 38 |
|
---|
| 39 | #ifdef ENABLE_MG
|
---|
[1860] | 40 | #include "mgqueryfilter.h"
|
---|
[21324] | 41 | #include "mgsource.h"
|
---|
| 42 | #endif
|
---|
| 43 | #ifdef ENABLE_MGPP
|
---|
[1860] | 44 | #include "mgppqueryfilter.h"
|
---|
[21324] | 45 | #include "mgppsource.h"
|
---|
| 46 | #endif
|
---|
| 47 | #ifdef ENABLE_LUCENE
|
---|
[8028] | 48 | #include "lucenequeryfilter.h"
|
---|
[15592] | 49 | #include "lucenesource.h"
|
---|
[21324] | 50 | #endif
|
---|
[8032] | 51 |
|
---|
[1860] | 52 | #include <assert.h>
|
---|
| 53 |
|
---|
[21472] | 54 | #ifdef USE_GDBM
|
---|
| 55 | #include "gdbmclass.h"
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
| 58 | #ifdef USE_JDBM
|
---|
| 59 | #include "jdbmnaiveclass.h"
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
[15729] | 62 | #ifdef USE_SQLITE
|
---|
| 63 | #include "sqlitedbclass.h"
|
---|
| 64 | #endif
|
---|
[1860] | 65 |
|
---|
[17476] | 66 | #ifdef USE_MSSQL
|
---|
| 67 | #include "mssqldbclass.h"
|
---|
| 68 | #endif
|
---|
| 69 |
|
---|
[25235] | 70 | // @EXTENSION HEADERS@
|
---|
[17476] | 71 |
|
---|
[16312] | 72 | collectset::collectset (text_t& gsdlhome, text_t& collecthome)
|
---|
| 73 | {
|
---|
| 74 | // gsdlhome and collecthome will be set as a result of calling this function
|
---|
| 75 | // collecthome will default to "<gsdlhome>/collect" if not explicitly
|
---|
| 76 | // specified in config file
|
---|
[15729] | 77 |
|
---|
[1860] | 78 | text_tarray collections;
|
---|
| 79 |
|
---|
[21324] | 80 | #ifdef ENABLE_MG
|
---|
[19365] | 81 | mgsearch = NULL;
|
---|
[21324] | 82 | #endif
|
---|
| 83 | #ifdef ENABLE_MGPP
|
---|
[19365] | 84 | mgppsearch = NULL;
|
---|
[21324] | 85 | #endif
|
---|
| 86 | #ifdef ENABLE_LUCENE
|
---|
[19365] | 87 | lucenesearch = NULL;
|
---|
[21324] | 88 | #endif
|
---|
[19365] | 89 |
|
---|
[1860] | 90 | // get gsdlhome (if we fail the error will be picked up later -- in
|
---|
| 91 | // cgiwrapper)
|
---|
[15002] | 92 |
|
---|
[16312] | 93 | if (site_cfg_read (gsdlhome, collecthome, httpdomain, httpprefix)) {
|
---|
[7302] | 94 | if (!gsdlhome.empty() && directory_exists(gsdlhome)) {
|
---|
[16312] | 95 | if (read_dir (collecthome, collections)) {
|
---|
[1860] | 96 |
|
---|
[2344] | 97 | text_tarray::const_iterator thiscol = collections.begin();
|
---|
| 98 | text_tarray::const_iterator endcol = collections.end();
|
---|
[1860] | 99 |
|
---|
[2344] | 100 | while (thiscol != endcol) {
|
---|
| 101 | // ignore the modelcol
|
---|
| 102 | if (*thiscol == "modelcol") {
|
---|
[9620] | 103 | ++thiscol;
|
---|
[2344] | 104 | continue;
|
---|
| 105 | }
|
---|
[1860] | 106 |
|
---|
[16312] | 107 | this->add_collection (*thiscol, gsdlhome, collecthome);
|
---|
[1860] | 108 |
|
---|
[9620] | 109 | ++thiscol;
|
---|
[2344] | 110 | }
|
---|
[15002] | 111 |
|
---|
[16312] | 112 | this->add_all_collection_groups(gsdlhome, collecthome);
|
---|
[2344] | 113 | }
|
---|
| 114 | }
|
---|
[1860] | 115 | }
|
---|
[16895] | 116 |
|
---|
| 117 | set_gsdl_env_vars(gsdlhome);
|
---|
[1860] | 118 | }
|
---|
| 119 |
|
---|
[17989] | 120 |
|
---|
| 121 | collectset::collectset (text_t& httpprefix_arg)
|
---|
| 122 | {
|
---|
| 123 | httpprefix = httpprefix_arg;
|
---|
[19365] | 124 |
|
---|
[21324] | 125 | #ifdef ENABLE_MG
|
---|
[19365] | 126 | mgsearch = NULL;
|
---|
[21324] | 127 | #endif
|
---|
| 128 | #ifdef ENABLE_MGPP
|
---|
[19365] | 129 | mgppsearch = NULL;
|
---|
[21324] | 130 | #endif
|
---|
| 131 | #ifdef ENABLE_LUCENE
|
---|
[19365] | 132 | lucenesearch = NULL;
|
---|
[21324] | 133 | #endif
|
---|
[19365] | 134 |
|
---|
[17989] | 135 | }
|
---|
| 136 |
|
---|
[19365] | 137 | collectset::collectset ()
|
---|
| 138 | {
|
---|
[21324] | 139 | #ifdef ENABLE_MG
|
---|
[19365] | 140 | mgsearch = NULL;
|
---|
[21324] | 141 | #endif
|
---|
| 142 | #ifdef ENABLE_MGPP
|
---|
[19365] | 143 | mgppsearch = NULL;
|
---|
[21324] | 144 | #endif
|
---|
| 145 | #ifdef ENABLE_LUCENE
|
---|
[19365] | 146 | lucenesearch = NULL;
|
---|
[21324] | 147 | #endif
|
---|
[19365] | 148 | }
|
---|
[17989] | 149 |
|
---|
[1860] | 150 | collectset::~collectset () {
|
---|
| 151 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 152 | collectservermapclass::iterator end = cservers.end();
|
---|
| 153 |
|
---|
| 154 | while (here != end) {
|
---|
| 155 | if ((*here).second.c != NULL) {
|
---|
| 156 | delete (*here).second.c;
|
---|
| 157 | }
|
---|
[9620] | 158 | ++here;
|
---|
[1860] | 159 | }
|
---|
| 160 | cservers.clear();
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | bool collectset::init (ostream &logout) {
|
---|
| 164 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 165 | collectservermapclass::iterator end = cservers.end();
|
---|
| 166 |
|
---|
| 167 | while (here != end) {
|
---|
| 168 | assert ((*here).second.c != NULL);
|
---|
| 169 | if ((*here).second.c != NULL) {
|
---|
| 170 | const colservrconf &configinfo = (*here).second.c->get_configinfo ();
|
---|
| 171 |
|
---|
| 172 | // configure this collection server
|
---|
| 173 |
|
---|
| 174 | // note that we read build.cfg before collect.cfg so that the indexmaps
|
---|
| 175 | // are available to decode defaultindex, defaultsubcollection, and
|
---|
| 176 | // defaultlanguage
|
---|
[15002] | 177 |
|
---|
| 178 | bool failed_build_cfg = false;
|
---|
[1860] | 179 | if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
|
---|
[16312] | 180 | configinfo.collecthome, configinfo.collection)) {
|
---|
[15002] | 181 | failed_build_cfg = true;
|
---|
| 182 |
|
---|
[1860] | 183 | outconvertclass text_t2ascii;
|
---|
| 184 | logout << text_t2ascii
|
---|
[16312] | 185 | << "Warning: couldn't read build.cfg file for collection \""
|
---|
| 186 | << configinfo.collection << "\""
|
---|
| 187 | << " gsdlhome=\"" << configinfo.gsdlhome << "\"\n"
|
---|
| 188 | << " collecthome=\"" << configinfo.collecthome << "\"\n";
|
---|
[1860] | 189 | }
|
---|
| 190 |
|
---|
[15002] | 191 | bool failed_collect_cfg = false;
|
---|
[1860] | 192 | if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
|
---|
[16312] | 193 | configinfo.collecthome, configinfo.collection)) {
|
---|
[15002] | 194 | failed_collect_cfg = true;
|
---|
[1860] | 195 | outconvertclass text_t2ascii;
|
---|
| 196 | logout << text_t2ascii
|
---|
| 197 | << "Warning: couldn't read collect.cfg file for collection \""
|
---|
[16312] | 198 | << configinfo.collection << "\""
|
---|
| 199 | << " gsdlhome=\"" << configinfo.gsdlhome << "\"\n"
|
---|
| 200 | << " collecthome=\"" << configinfo.collecthome << "\"\n";
|
---|
[15002] | 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | bool is_colgroup = (*here).second.c->is_collection_group();
|
---|
| 205 |
|
---|
| 206 | if (failed_collect_cfg) {
|
---|
[9620] | 207 | ++here;
|
---|
[1860] | 208 | continue;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[15002] | 211 | if (failed_build_cfg && (!is_colgroup)) {
|
---|
| 212 | ++here;
|
---|
| 213 | continue;
|
---|
| 214 | }
|
---|
| 215 | // let a failed build.cfg through if its 'collect.cfg' marks it as 'collectgroup true'
|
---|
| 216 |
|
---|
[1860] | 217 | if (!(*here).second.c->init (logout)) return false;
|
---|
| 218 |
|
---|
| 219 | (*here).second.c->configure("httpdomain",httpdomain);
|
---|
| 220 | (*here).second.c->configure("httpprefix",httpprefix);
|
---|
| 221 | }
|
---|
[9620] | 222 | ++here;
|
---|
[1860] | 223 | }
|
---|
| 224 |
|
---|
| 225 | return true;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | collectservermapclass collectset::servers()
|
---|
| 229 | { return cservers;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[9030] | 232 |
|
---|
[16312] | 233 | void collectset::add_all_collections(const text_t &gsdlhome,
|
---|
| 234 | const text_t& collecthome)
|
---|
| 235 | {
|
---|
[9030] | 236 | text_tarray collections;
|
---|
| 237 |
|
---|
[16312] | 238 | if (read_dir(collecthome, collections)) {
|
---|
| 239 |
|
---|
[9030] | 240 | text_tarray::const_iterator thiscol = collections.begin();
|
---|
| 241 | text_tarray::const_iterator endcol = collections.end();
|
---|
| 242 |
|
---|
| 243 | while (thiscol != endcol) {
|
---|
| 244 |
|
---|
| 245 | // ignore the modelcol
|
---|
| 246 | if (*thiscol == "modelcol") {
|
---|
[9620] | 247 | ++thiscol;
|
---|
[9030] | 248 | continue;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[15421] | 251 | // create collection server for this collection
|
---|
[16312] | 252 | this->add_collection (*thiscol, gsdlhome, collecthome);
|
---|
[9030] | 253 |
|
---|
[9620] | 254 | ++thiscol;
|
---|
[9030] | 255 | }
|
---|
[15002] | 256 |
|
---|
[16312] | 257 | this->add_all_collection_groups(gsdlhome,collecthome);
|
---|
[9030] | 258 | }
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[21453] | 261 | bool collectset::collection_is_collect_group (const text_t& collect_dir)
|
---|
| 262 | {
|
---|
| 263 | text_t is_collect_group_str = "false";
|
---|
| 264 | text_t collect_cfg = filename_cat(collect_dir, "etc", "collect.cfg");
|
---|
| 265 |
|
---|
| 266 | if (file_exists(collect_cfg)) {
|
---|
| 267 | char *collect_cfgc = collect_cfg.getcstr();
|
---|
| 268 | ifstream confin(collect_cfgc);
|
---|
| 269 |
|
---|
| 270 | if (confin) {
|
---|
| 271 | text_tarray cfgline;
|
---|
| 272 |
|
---|
| 273 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
| 274 | if (cfgline.size() == 2) {
|
---|
| 275 | text_t key = cfgline[0];
|
---|
| 276 | cfgline.erase(cfgline.begin());
|
---|
| 277 | if (key == "collectgroup") {
|
---|
| 278 | is_collect_group_str = cfgline[0];
|
---|
| 279 | break;
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | confin.close();
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | delete []collect_cfgc;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | bool is_collect_group = (is_collect_group_str == "true") ? true : false;
|
---|
| 291 |
|
---|
| 292 | return is_collect_group;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 |
|
---|
[1860] | 296 | // add_collection sets up the collectionserver and calls
|
---|
| 297 | // add_collectserver
|
---|
[16312] | 298 | void collectset::add_collection (const text_t& collection,
|
---|
| 299 | const text_t& gsdlhome,
|
---|
| 300 | const text_t& collecthome)
|
---|
| 301 | {
|
---|
[8028] | 302 | // read config file to see if built with mg, mgpp, or lucene
|
---|
[1860] | 303 | text_t buildtype = "mg"; // mg is default
|
---|
[15729] | 304 | text_t infodbtype = "gdbm"; // gdbm is default
|
---|
[2545] | 305 |
|
---|
[21453] | 306 | this->remove_collection(collection);
|
---|
| 307 |
|
---|
[19806] | 308 | collectserver *cserver = NULL;
|
---|
| 309 |
|
---|
[16312] | 310 | text_t build_cfg = filename_cat(collecthome, collection, "index", "build.cfg");
|
---|
[19806] | 311 | if (file_exists (build_cfg)) {
|
---|
| 312 | char *build_cfgc = build_cfg.getcstr();
|
---|
| 313 | ifstream confin(build_cfgc);
|
---|
| 314 |
|
---|
| 315 | if (confin) {
|
---|
[21453] | 316 | text_tarray cfgline;
|
---|
| 317 |
|
---|
[19806] | 318 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
| 319 | if (cfgline.size() == 2) {
|
---|
[21453] | 320 | text_t key = cfgline[0];
|
---|
[19806] | 321 | cfgline.erase(cfgline.begin());
|
---|
| 322 | if (key == "buildtype") {
|
---|
| 323 | buildtype = cfgline[0];
|
---|
| 324 | }
|
---|
| 325 | if (key == "infodbtype") {
|
---|
| 326 | infodbtype = cfgline[0];
|
---|
| 327 | }
|
---|
[1860] | 328 | }
|
---|
| 329 | }
|
---|
[19806] | 330 | confin.close();
|
---|
[1860] | 331 | }
|
---|
[19806] | 332 | delete []build_cfgc;
|
---|
[1860] | 333 |
|
---|
[19806] | 334 | cserver = new collectserver();
|
---|
[1860] | 335 |
|
---|
[19806] | 336 | // Create a dbclass of the correct type
|
---|
| 337 | dbclass *db_ptr = NULL;
|
---|
[15729] | 338 |
|
---|
[19806] | 339 | if (infodbtype == "sqlite")
|
---|
| 340 | {
|
---|
[22050] | 341 | #ifdef USE_SQLITE
|
---|
[22067] | 342 | sqlitedbclass *sql_db_ptr = new sqlitedbclass(gsdlhome);
|
---|
[19806] | 343 | db_ptr = sql_db_ptr;
|
---|
[15759] | 344 |
|
---|
[19806] | 345 | // add a sql browse filter
|
---|
| 346 | sqlbrowsefilterclass *sqlbrowsefilter = new sqlbrowsefilterclass();
|
---|
| 347 | sqlbrowsefilter->set_sql_db_ptr(sql_db_ptr);
|
---|
| 348 | cserver->add_filter (sqlbrowsefilter);
|
---|
[22050] | 349 |
|
---|
| 350 | // add a sql query filter
|
---|
| 351 | sqlqueryfilterclass *sqlqueryfilter = new sqlqueryfilterclass();
|
---|
| 352 | sqlqueryfilter->set_sql_db_ptr(sql_db_ptr);
|
---|
| 353 | cserver->add_filter (sqlqueryfilter);
|
---|
| 354 |
|
---|
| 355 | #else
|
---|
| 356 | cerr << "Warning: infodbtype of 'sqlite' was not compiled in to " << endl;
|
---|
| 357 | cerr << " this installation of Greenstone";
|
---|
| 358 | #endif
|
---|
[19806] | 359 | }
|
---|
[17476] | 360 |
|
---|
[19806] | 361 | if (infodbtype == "mssql")
|
---|
| 362 | {
|
---|
[22050] | 363 | #ifdef USE_MSSQL
|
---|
[22067] | 364 | mssqldbclass *mssql_db_ptr = new mssqldbclass(gsdlhome);
|
---|
[19806] | 365 | db_ptr = mssql_db_ptr;
|
---|
[15729] | 366 |
|
---|
[19806] | 367 | // add a sql browse filter
|
---|
| 368 | sqlbrowsefilterclass *sqlbrowsefilter = new sqlbrowsefilterclass();
|
---|
| 369 | sqlbrowsefilter->set_sql_db_ptr(mssql_db_ptr);
|
---|
| 370 | cserver->add_filter (sqlbrowsefilter);
|
---|
[22050] | 371 | #else
|
---|
| 372 | cerr << "Warning: infodbtype of 'mssql' was not compiled in to " << endl;
|
---|
| 373 | cerr << " this installation of Greenstone";
|
---|
| 374 | #endif
|
---|
[19806] | 375 | }
|
---|
[21415] | 376 |
|
---|
| 377 | if (infodbtype == "jdbm") {
|
---|
| 378 |
|
---|
[22050] | 379 | #ifdef USE_JDBM
|
---|
[21415] | 380 | jdbmnaiveclass *jdbm_db_ptr = new jdbmnaiveclass(gsdlhome);
|
---|
| 381 | db_ptr = jdbm_db_ptr;
|
---|
[22050] | 382 | #else
|
---|
| 383 | cerr << "Warning: infodbtype of 'jdbm' was not compiled in to " << endl;
|
---|
| 384 | cerr << " this installation of Greenstone";
|
---|
| 385 | #endif
|
---|
[21415] | 386 | }
|
---|
[21472] | 387 |
|
---|
[25235] | 388 | // @EXTENSION DATASOURCES@
|
---|
| 389 |
|
---|
[19806] | 390 | // Use GDBM if the infodb type is empty or not one of the values above
|
---|
| 391 | if (db_ptr == NULL) {
|
---|
[21472] | 392 | #ifdef USE_GDBM
|
---|
[22067] | 393 | db_ptr = new gdbmclass(gsdlhome);
|
---|
[22050] | 394 | #else
|
---|
| 395 | cerr << "Warning: infodbtype of 'gdbm' was not compiled in to " << endl;
|
---|
| 396 | cerr << " this installation of Greenstone";
|
---|
[21472] | 397 | #endif
|
---|
[19806] | 398 | }
|
---|
[15729] | 399 |
|
---|
[19806] | 400 | // add a null filter
|
---|
| 401 | filterclass *filter = new filterclass ();
|
---|
| 402 | cserver->add_filter (filter);
|
---|
| 403 |
|
---|
| 404 | // add a browse filter
|
---|
| 405 | browsefilterclass *browsefilter = new browsefilterclass();
|
---|
| 406 | browsefilter->set_db_ptr(db_ptr);
|
---|
| 407 | cserver->add_filter (browsefilter);
|
---|
| 408 |
|
---|
| 409 | if (buildtype == "mg") {
|
---|
[21324] | 410 | #ifdef ENABLE_MG
|
---|
[19806] | 411 | mgsearch = new mgsearchclass();
|
---|
[1860] | 412 |
|
---|
[19806] | 413 | // add a query filter
|
---|
| 414 | mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
|
---|
| 415 | queryfilter->set_db_ptr(db_ptr);
|
---|
| 416 | queryfilter->set_textsearchptr (mgsearch);
|
---|
| 417 | cserver->add_filter (queryfilter);
|
---|
[1860] | 418 |
|
---|
[19806] | 419 | // add a mg source
|
---|
| 420 | mgsourceclass *mgsource = new mgsourceclass ();
|
---|
| 421 | mgsource->set_db_ptr(db_ptr);
|
---|
| 422 | mgsource->set_textsearchptr (mgsearch);
|
---|
| 423 | cserver->add_source (mgsource);
|
---|
[21324] | 424 | #else
|
---|
| 425 | cerr << "Error: buildtype " << buildtype << " not enabled." << endl;
|
---|
| 426 | #endif
|
---|
[19806] | 427 | }
|
---|
| 428 | else if (buildtype == "mgpp") {
|
---|
[21324] | 429 | #ifdef ENABLE_MGPP
|
---|
[19806] | 430 | mgppsearch = new mgppsearchclass();
|
---|
[1860] | 431 |
|
---|
[19806] | 432 | // add a query filter
|
---|
| 433 | mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
|
---|
| 434 | queryfilter->set_db_ptr(db_ptr);
|
---|
| 435 | queryfilter->set_textsearchptr (mgppsearch);
|
---|
| 436 | cserver->add_filter (queryfilter);
|
---|
[1860] | 437 |
|
---|
[21324] | 438 | // add a mgpp source
|
---|
| 439 | mgppsourceclass *mgppsource = new mgppsourceclass ();
|
---|
| 440 | mgppsource->set_db_ptr(db_ptr);
|
---|
| 441 | mgppsource->set_textsearchptr (mgppsearch);
|
---|
| 442 | cserver->add_source (mgppsource);
|
---|
| 443 | #else
|
---|
| 444 | cerr << "Error: buildtype " << buildtype << " not enabled." << endl;
|
---|
| 445 | #endif
|
---|
[19806] | 446 | }
|
---|
| 447 | else if (buildtype == "lucene") {
|
---|
[21324] | 448 | #ifdef ENABLE_LUCENE
|
---|
[19806] | 449 | lucenesearch = new lucenesearchclass();
|
---|
| 450 | lucenesearch->set_gsdlhome(gsdlhome);
|
---|
| 451 |
|
---|
| 452 | // add a query filter
|
---|
| 453 | lucenequeryfilterclass *queryfilter = new lucenequeryfilterclass();
|
---|
| 454 | queryfilter->set_db_ptr(db_ptr);
|
---|
| 455 | queryfilter->set_textsearchptr (lucenesearch);
|
---|
| 456 | cserver->add_filter (queryfilter);
|
---|
| 457 |
|
---|
| 458 | // add a lucene source
|
---|
| 459 | lucenesourceclass *lucenesource = new lucenesourceclass ();
|
---|
| 460 | lucenesource->set_db_ptr(db_ptr);
|
---|
| 461 | lucenesource->set_textsearchptr (lucenesearch);
|
---|
| 462 | cserver->add_source (lucenesource);
|
---|
[21324] | 463 | #else
|
---|
| 464 | cerr << "Error: buildtype " << buildtype << " not enabled." << endl;
|
---|
| 465 | #endif
|
---|
[19806] | 466 | }
|
---|
| 467 | else {
|
---|
[21324] | 468 | cerr << "Warning: unrecognized buildtype " << buildtype << endl;
|
---|
[19806] | 469 | }
|
---|
| 470 |
|
---|
[12246] | 471 | }
|
---|
[19806] | 472 | else {
|
---|
| 473 | // see if it is a collectgroup col
|
---|
[21453] | 474 | text_t this_collect_dir = filename_cat(collecthome, collection);
|
---|
| 475 | if (collection_is_collect_group(this_collect_dir)) {
|
---|
| 476 | // by this point we know we will need a cserver
|
---|
| 477 | cserver = new collectserver();
|
---|
[19806] | 478 | }
|
---|
[21453] | 479 | // else not a collect group, or there was no collect.cfg
|
---|
| 480 | // => leave cserver as NULL so it will not be added into cservers
|
---|
[1860] | 481 | }
|
---|
| 482 |
|
---|
[21453] | 483 | if (cserver != NULL) {
|
---|
| 484 | // inform collection server and everything it contains about its
|
---|
| 485 | // collection name
|
---|
| 486 | cserver->configure ("collection", collection);
|
---|
| 487 | cserver->configure ("gsdlhome", gsdlhome);
|
---|
| 488 | cserver->configure ("collecthome", collecthome);
|
---|
| 489 | cservers.addcollectserver (cserver);
|
---|
| 490 | }
|
---|
[1860] | 491 | }
|
---|
| 492 |
|
---|
[9030] | 493 | void collectset::remove_all_collections () {
|
---|
| 494 |
|
---|
[21324] | 495 | #ifdef ENABLE_MG
|
---|
[9030] | 496 | // first unload any cached mg databases
|
---|
| 497 | if (mgsearch != NULL) {
|
---|
| 498 | mgsearch->unload_database();
|
---|
| 499 | }
|
---|
[21324] | 500 | #endif
|
---|
[24758] | 501 | #ifdef ENABLE_MGPP
|
---|
| 502 | if (mgppsearch != NULL) {
|
---|
| 503 | mgppsearch->unload_database();
|
---|
| 504 | }
|
---|
| 505 | #endif
|
---|
| 506 | #ifdef ENABLE_LUCENE
|
---|
| 507 | if (lucenesearch != NULL) {
|
---|
| 508 | lucenesearch->unload_database();
|
---|
| 509 | }
|
---|
| 510 | #endif
|
---|
[9030] | 511 |
|
---|
| 512 | // now delete the collection server objects
|
---|
| 513 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 514 | collectservermapclass::iterator end = cservers.end();
|
---|
| 515 |
|
---|
| 516 | while (here != end) {
|
---|
| 517 | if ((*here).second.c != NULL) {
|
---|
| 518 | delete (*here).second.c;
|
---|
| 519 | }
|
---|
[9620] | 520 | ++here;
|
---|
[9030] | 521 | }
|
---|
[24757] | 522 | // since all collection server objects are deleted (which deleted their source objects
|
---|
| 523 | // which in turn deleted their search objects), we now NULL the local reference to the
|
---|
| 524 | // search objects. See the extensive comment for this in remove_collection(text_t).
|
---|
| 525 | #ifdef ENABLE_MG
|
---|
| 526 | if (mgsearch != NULL) {
|
---|
| 527 | mgsearch = NULL;
|
---|
| 528 | }
|
---|
| 529 | #endif
|
---|
| 530 | #ifdef ENABLE_MGPP
|
---|
| 531 | if (mgppsearch != NULL) {
|
---|
| 532 | mgppsearch = NULL;
|
---|
| 533 | }
|
---|
| 534 | #endif
|
---|
| 535 | #ifdef ENABLE_LUCENE
|
---|
| 536 | if (lucenesearch != NULL) {
|
---|
| 537 | lucenesearch = NULL;
|
---|
| 538 | }
|
---|
| 539 | #endif
|
---|
| 540 |
|
---|
[9030] | 541 | cservers.clear();
|
---|
| 542 | }
|
---|
| 543 |
|
---|
[15002] | 544 | void collectset::add_collection_group(const text_t& collection,
|
---|
[16312] | 545 | const text_t& gsdlhome,
|
---|
| 546 | const text_t& collecthome)
|
---|
[15002] | 547 | {
|
---|
| 548 | text_tarray group;
|
---|
[9030] | 549 |
|
---|
[16312] | 550 | text_t collect_group_dir = filename_cat (collecthome, collection);
|
---|
| 551 |
|
---|
[15002] | 552 | // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet
|
---|
[21453] | 553 | if (collection_is_collect_group(collect_group_dir)) {
|
---|
[15002] | 554 | if (read_dir (collect_group_dir, group)) {
|
---|
| 555 |
|
---|
| 556 | text_tarray::const_iterator thiscol = group.begin();
|
---|
| 557 | text_tarray::const_iterator endcol = group.end();
|
---|
| 558 |
|
---|
| 559 | while (thiscol != endcol) {
|
---|
[18978] | 560 | // ignore the etc directory
|
---|
[15002] | 561 | if (*thiscol == "etc") {
|
---|
| 562 | ++thiscol;
|
---|
| 563 | continue;
|
---|
| 564 | }
|
---|
| 565 |
|
---|
[18978] | 566 | //text_t group_col = filename_cat(collection,*thiscol);
|
---|
| 567 | // later we check for / in the name. When this is used in a path (via fileanme_cat) the / will be converted to \ on windows
|
---|
| 568 | text_t group_col = collection + "/" + *thiscol;
|
---|
[16312] | 569 | this->add_collection (group_col, gsdlhome, collecthome);
|
---|
[15002] | 570 |
|
---|
| 571 | ++thiscol;
|
---|
| 572 | }
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[16312] | 577 | void collectset::add_all_collection_groups (const text_t& gsdlhome,
|
---|
| 578 | const text_t& collecthome)
|
---|
[15002] | 579 |
|
---|
| 580 | {
|
---|
| 581 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 582 | collectservermapclass::iterator end = cservers.end();
|
---|
| 583 |
|
---|
| 584 | while (here != end) {
|
---|
| 585 | text_t collection = (*here).second.c->get_collection_name();
|
---|
[16312] | 586 | this->add_collection_group(collection,gsdlhome,collecthome);
|
---|
[15002] | 587 |
|
---|
| 588 | ++here;
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 |
|
---|
[1860] | 593 | // remove_collection deletes the collection server of collection.
|
---|
| 594 | // This only needs to be called if a collectionserver is to be
|
---|
| 595 | // removed while the library is running. The destructor function
|
---|
| 596 | // cleans up all collectservers when the program exits.
|
---|
[15002] | 597 | void collectset::remove_collection (const text_t &collection) {
|
---|
[2545] | 598 |
|
---|
[4340] | 599 | // do nothing if no collection server exists for this collection
|
---|
| 600 | if (cservers.getcollectserver(collection) == NULL) return;
|
---|
| 601 |
|
---|
[21324] | 602 | #ifdef ENABLE_MG
|
---|
[2545] | 603 | // first unload any cached mg databases - we may need to do something
|
---|
[8028] | 604 | // similar to this for mgpp and lucene too
|
---|
[2545] | 605 | if (mgsearch != NULL) {
|
---|
| 606 | mgsearch->unload_database();
|
---|
| 607 | }
|
---|
[21324] | 608 | #endif
|
---|
[24758] | 609 | #ifdef ENABLE_MGPP
|
---|
| 610 | if (mgppsearch != NULL) {
|
---|
| 611 | mgppsearch->unload_database();
|
---|
| 612 | }
|
---|
| 613 | #endif
|
---|
| 614 | #ifdef ENABLE_LUCENE
|
---|
| 615 | if (lucenesearch != NULL) {
|
---|
| 616 | lucenesearch->unload_database();
|
---|
| 617 | }
|
---|
| 618 | #endif
|
---|
[2545] | 619 |
|
---|
| 620 | // now delete the collection server object
|
---|
[1860] | 621 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 622 | collectservermapclass::iterator end = cservers.end();
|
---|
| 623 |
|
---|
| 624 | while (here != end) {
|
---|
| 625 | if ((*here).second.c != NULL && (*here).first == collection) {
|
---|
| 626 | delete (*here).second.c;
|
---|
[24757] | 627 |
|
---|
| 628 | // The above code deletes the collection server object for this collection, which then
|
---|
| 629 | // deletes the <indexer>source object, which then deletes the <indexer>search object.
|
---|
| 630 | // Since we have a reference to the <index>search object here, we have to set it to NULL
|
---|
| 631 | // at this point, because we test it against null-ness elsewhere in this code. (Without
|
---|
| 632 | // setting it to NULL, we end up with server crashing issues.)
|
---|
| 633 | // Ideally, we'd like to know that we are NULLing the pointer to the exact same object
|
---|
| 634 | // as was freed above, but we can't know that without complicated object access to make
|
---|
| 635 | // the necessary pointer comparison. Fortunately, this class maintains only one type of
|
---|
| 636 | // <index>search object (of a/any kind) at any time, so we can NULL this confidently now.
|
---|
| 637 | #ifdef ENABLE_MG
|
---|
| 638 | if (mgsearch != NULL) {
|
---|
| 639 | mgsearch = NULL;
|
---|
| 640 | }
|
---|
| 641 | #endif
|
---|
| 642 | #ifdef ENABLE_MGPP
|
---|
| 643 | if (mgppsearch != NULL) {
|
---|
| 644 | mgppsearch = NULL;
|
---|
| 645 | }
|
---|
| 646 | #endif
|
---|
| 647 | #ifdef ENABLE_LUCENE
|
---|
| 648 | if (lucenesearch != NULL) {
|
---|
| 649 | lucenesearch = NULL;
|
---|
| 650 | }
|
---|
| 651 | #endif
|
---|
| 652 |
|
---|
| 653 | // continue cleaning up the collection server
|
---|
| 654 | cservers.erase (here);
|
---|
| 655 |
|
---|
[1860] | 656 | return;
|
---|
[24757] | 657 | } // end if
|
---|
[9620] | 658 | ++here;
|
---|
[1860] | 659 | }
|
---|
[15002] | 660 | }
|
---|
| 661 |
|
---|
| 662 |
|
---|
| 663 | // remove_collection deletes the collection server of collection.
|
---|
| 664 | // This only needs to be called if a collectionserver is to be
|
---|
| 665 | // removed while the library is running. The destructor function
|
---|
| 666 | // cleans up all collectservers when the program exits.
|
---|
| 667 | void collectset::remove_collection (const text_t &collection, ostream &logout) {
|
---|
| 668 |
|
---|
| 669 | remove_collection(collection);
|
---|
| 670 |
|
---|
[1860] | 671 | outconvertclass text_t2ascii;
|
---|
[24757] | 672 | logout << text_t2ascii << "collectset::remove_collection: Removed collectserver for "
|
---|
[1860] | 673 | << collection << "\n";
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | void collectset::configure(const text_t &key, const text_tarray &cfgline)
|
---|
| 677 | {
|
---|
[16312] | 678 | if ((key == "collection") || (key == "collectdir")) return;
|
---|
[1860] | 679 |
|
---|
| 680 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 681 | collectservermapclass::iterator end = cservers.end();
|
---|
| 682 |
|
---|
| 683 | while (here != end) {
|
---|
| 684 | assert ((*here).second.c != NULL);
|
---|
| 685 | if ((*here).second.c != NULL) {
|
---|
| 686 | if (key == "collectinfo") {
|
---|
| 687 | if ((*here).first == cfgline[0]) {
|
---|
[16312] | 688 | if (cfgline.size()==3) {
|
---|
| 689 | (*here).second.c->configure ("gsdlhome", cfgline[1]);
|
---|
| 690 | (*here).second.c->configure ("gdbmhome", cfgline[2]);
|
---|
| 691 | }
|
---|
| 692 | else {
|
---|
| 693 | (*here).second.c->configure ("gsdlhome", cfgline[1]);
|
---|
| 694 | (*here).second.c->configure ("collecthome", cfgline[2]);
|
---|
| 695 | (*here).second.c->configure ("gdbmhome", cfgline[3]);
|
---|
| 696 | }
|
---|
[1860] | 697 | }
|
---|
| 698 | } else {
|
---|
| 699 | (*here).second.c->configure (key, cfgline);
|
---|
| 700 | }
|
---|
| 701 | }
|
---|
| 702 |
|
---|
[9620] | 703 | ++here;
|
---|
[1860] | 704 | }
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | void collectset::getCollectionList (text_tarray &collist)
|
---|
| 708 | {
|
---|
| 709 | collist.erase(collist.begin(),collist.end());
|
---|
| 710 |
|
---|
| 711 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 712 | collectservermapclass::iterator end = cservers.end();
|
---|
| 713 | while (here != end) {
|
---|
| 714 | assert ((*here).second.c != NULL);
|
---|
| 715 | if ((*here).second.c != NULL) {
|
---|
| 716 | collist.push_back ((*here).second.c->get_collection_name());
|
---|
| 717 | }
|
---|
[9620] | 718 | ++here;
|
---|
[1860] | 719 | }
|
---|
| 720 | }
|
---|
[16312] | 721 |
|
---|