/********************************************************************** * * mgppsearch.cpp -- * Copyright (C) 1999-2002 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *********************************************************************/ #include "gsdlconf.h" #include "mgppsearch.h" #include "fileutil.h" #include "GSDLQueryParser.h" #include "MGQuery.h" #include "TextGet.h" #include "queryinfo.h" #include "gsdlunicode.h" text_t mgppsearchclass::getindexsuffix(const queryparamclass &qp) { return getindexsuffix(qp.collection, qp.index+qp.subcollection+qp.language); } text_t mgppsearchclass::getindexsuffix (const text_t &collection, const text_t &index) { text_t indexsuffix = "index"; indexsuffix = filename_cat (indexsuffix, index); if (indexstem.empty()) { // no index stem, use the coll name indexsuffix = filename_cat (indexsuffix, collection); } else { indexsuffix = filename_cat (indexsuffix, indexstem); } return indexsuffix; } //////////////////// // mgppsearch class // //////////////////// mgppsearchclass::mgppsearchclass () : searchclass() { textlevel = "Doc"; indexData = NULL; } mgppsearchclass::~mgppsearchclass () { if (cache != NULL) { delete cache; cache = NULL; } if (indexData !=NULL) { indexData->UnloadData(); delete indexData; indexData = NULL; } } void mgppsearchclass::set_text_level(const text_t &textlevel_arg) { textlevel = textlevel_arg; } void mgppsearchclass::set_indexstem(const text_t &stem) { indexstem = stem; } bool mgppsearchclass::search(const queryparamclass &queryparams, queryresultsclass &queryresult) { #ifdef __WIN32__ char basepath[]=""; #else char basepath[] = "/"; #endif char *indexname = (filename_cat(collectdir, getindexsuffix(queryparams))).getcstr(); // load index data if (indexData == NULL) { indexData = new IndexData(); } if (!indexData->LoadData (basepath, indexname)) { cerr<<"couldn't load index data\n"<LoadData (basepath, indexname)) { cerr<<"couldn't load index data\n"<,
, tags //clean up textdata.UnloadData (); delete []textname; return true; } // used to clear any cached databases for persistent versions of // Greenstone like the Windows local library void mgppsearchclass::unload_database () { if (indexData !=NULL) { indexData->UnloadData(); } }