/********************************************************************** * * collectserver.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: collectserver.cpp 191 1999-03-08 05:07:42Z rjmcnab $ * *********************************************************************/ /* $Log$ Revision 1.3 1999/03/08 05:07:42 rjmcnab Made some alterations to fit with the changes to the comtypes. Added the "filteroptdefault" configuration option to alter default filter options. Revision 1.2 1999/03/03 23:28:29 sjboddie Provided stub functions for the protocol Revision 1.1 1999/02/21 22:32:56 rjmcnab Initial revision. */ #include "collectserver.h" #include collectserver::collectserver () { configinfo.collection = "null"; // set up the QueryFilter information FilterDescript_t &queryfilter = filterinfo.filterOptions["QueryFilter"]; queryfilter.filterName = "QueryFilter"; // -- onePerQuery StartResults integer FilterOption_t &qfopt1 = queryfilter.filterOptions["StartResults"]; qfopt1.name = "StartResults"; qfopt1.type = FilterOption_t::integert; qfopt1.repeatable = FilterOption_t::onePerQuery; qfopt1.defaultValue = 1; qfopt1.validValues.push_back ("1"); qfopt1.validValues.push_back ("500"); // -- onePerQuery EndResults integer FilterOption_t &qfopt2 = queryfilter.filterOptions["EndResults"]; qfopt2.name = "EndResults"; qfopt2.type = FilterOption_t::integert; qfopt2.repeatable = FilterOption_t::onePerQuery; qfopt2.defaultValue = 20; qfopt2.validValues.push_back ("1"); qfopt2.validValues.push_back ("500"); // -- onePerQuery QueryType enumerated (boolean, ranked) FilterOption_t &qfopt3 = queryfilter.filterOptions["QueryType"]; qfopt3.name = "QueryType"; qfopt3.type = FilterOption_t::enumeratedt; qfopt3.repeatable = FilterOption_t::onePerQuery; qfopt3.defaultValue = "boolean"; qfopt3.validValues.push_back ("boolean"); qfopt3.validValues.push_back ("ranked"); // -- onePerTerm Term string ??? FilterOption_t &qfopt3b = queryfilter.filterOptions["Term"]; qfopt3b.name = "Term"; qfopt3b.type = FilterOption_t::stringt; qfopt3b.repeatable = FilterOption_t::onePerTerm; qfopt3b.defaultValue = ""; // -- onePerTerm Casefold boolean FilterOption_t &qfopt4 = queryfilter.filterOptions["Casefold"]; qfopt4.name = "Casefold"; qfopt4.type = FilterOption_t::booleant; qfopt4.repeatable = FilterOption_t::onePerTerm; qfopt4.defaultValue = "on"; qfopt4.validValues.push_back ("on"); qfopt4.validValues.push_back ("off"); // -- onePerTerm Stem boolean FilterOption_t &qfopt5 = queryfilter.filterOptions["Stem"]; qfopt5.name = "Stem"; qfopt5.type = FilterOption_t::booleant; qfopt5.repeatable = FilterOption_t::onePerTerm; qfopt5.defaultValue = "on"; qfopt5.validValues.push_back ("on"); qfopt5.validValues.push_back ("off"); // -- onePerTerm Index enumerated FilterOption_t &qfopt6 = queryfilter.filterOptions["Index"]; qfopt6.name = "Index"; qfopt6.type = FilterOption_t::enumeratedt; qfopt6.repeatable = FilterOption_t::onePerTerm; qfopt6.defaultValue = ""; // -- onePerTerm Subcollection enumerated FilterOption_t &qfopt7 = queryfilter.filterOptions["Subcollection"]; qfopt7.name = "Subcollection"; qfopt7.type = FilterOption_t::enumeratedt; qfopt7.repeatable = FilterOption_t::onePerTerm; qfopt7.defaultValue = ""; // set up the BrowseFilter information FilterDescript_t &browsefilter = filterinfo.filterOptions["BrowseFilter"]; browsefilter.filterName = "BrowseFilter"; // -- onePerQuery StartResults integer FilterOption_t &bfopt1 = browsefilter.filterOptions["StartResults"]; bfopt1.name = "StartResults"; bfopt1.type = FilterOption_t::integert; bfopt1.repeatable = FilterOption_t::onePerQuery; bfopt1.defaultValue = 1; bfopt1.validValues.push_back ("1"); bfopt1.validValues.push_back ("500"); // -- onePerQuery EndResults integer FilterOption_t &bfopt2 = browsefilter.filterOptions["EndResults"]; bfopt2.name = "EndResults"; bfopt2.type = FilterOption_t::integert; bfopt2.repeatable = FilterOption_t::onePerQuery; bfopt2.defaultValue = 20; bfopt2.validValues.push_back ("1"); bfopt2.validValues.push_back ("500"); // -- onePerQuery ParentNode string ("" will return the browsing available) FilterOption_t &bfopt3 = browsefilter.filterOptions["ParentNode"]; bfopt3.name = "ParentNode"; bfopt3.type = FilterOption_t::stringt; bfopt3.repeatable = FilterOption_t::onePerQuery; bfopt3.defaultValue = ""; } collectserver::~collectserver () { } // configure should be called for each line in the // configuration files to configure the collection server and everything // it contains. The configuration should take place just before initialisation. void collectserver::configure (const text_t &key, const text_tarray &cfgline) { if (key == "indexmap") configinfo.indexmap = cfgline; else if (key == "subcollectionmap") configinfo.subcollectionmap = cfgline; else if (key == "languagemap") configinfo.languagemap = cfgline; else if (cfgline.size() >= 1) { const text_t &value = cfgline[0]; if (key == "gsdlhome") configinfo.gsdlhome = value; else if (key == "collection") { configinfo.collection = value; collectinfo.shortInfo.name = value; } else if (key == "collectdir") configinfo.collectdir = value; else if (key == "host") collectinfo.shortInfo.host = value; else if (key == "port") collectinfo.shortInfo.port = value.getint(); else if (key == "public") { if (value == "true") collectinfo.isPublic = true; else collectinfo.isPublic = false; } else if (key == "beta") { if (value == "true") collectinfo.isBeta = true; else collectinfo.isBeta = false; } else if (key == "builddate") collectinfo.buildDate = value.getint(); else if (key == "languages") collectinfo.languages = cfgline; else if (key == "numdocs") collectinfo.numDocs = value.getint(); else if (key == "numwords") collectinfo.numWords = value.getint(); else if (key == "numbytes") collectinfo.numBytes = value.getint(); else if ((key == "filteroptdefault") && (cfgline.size() == 2)) { // set this default for each type of filter FilterDescript_tmap::iterator filteropthere = filterinfo.filterOptions.begin(); FilterDescript_tmap::iterator filteroptend = filterinfo.filterOptions.end(); while (filteropthere != filteroptend) { // see if this filter has an option with this name FilterOption_tmap &fotm = (*filteropthere).second.filterOptions; if (fotm.find(cfgline[0]) != fotm.end()) { (*(fotm.find(cfgline[0]))).second.defaultValue = cfgline[1]; } filteropthere++; } } } } void collectserver::configure (const text_t &key, const text_t &value) { text_tarray cfgline; cfgline.push_back (value); configure(key, cfgline); } bool collectserver::init (ostream &/*logout*/) { return true; } void collectserver::get_collectinfo (ColInfoResponse_t &reponse, comerror_t &err, ostream &/*logout*/) { reponse = collectinfo; err = noError; } void collectserver::get_filteroptions (InfoFilterOptionsResponse_t &response, comerror_t &err, ostream &/*logout*/) { err = noError; } void collectserver::filter (const FilterRequest_t &request, FilterResponse_t &response, comerror_t &err, ostream &/*logout*/) { if (request.filterName == "QueryFilter") { // return documents } else { } err = noError; } void collectserver::get_metadataoptions (MetadataInfoResponse_t &response, comerror_t &err, ostream &/*logout*/) { err = noError; } void collectserver::get_metadata (const MetadataRequest_t &request, MetadataResponse_t &response, comerror_t &err, ostream &/*logout*/) { err = noError; } // thecollectserver remains the property of the calling code but // should not be deleted until it is removed from this list. void collectservermapclass::addcollectserver (collectserver *thecollectserver) { // can't add a null collection server assert (thecollectserver != NULL); if (thecollectserver == NULL) return; // can't add an collection server with no collection name assert (!(thecollectserver->get_collection_name()).empty()); if ((thecollectserver->get_collection_name()).empty()) return; collectserverptr cptr; cptr.c = thecollectserver; collectserverptrs[thecollectserver->get_collection_name()] = cptr; } // getcollectserver will return NULL if the collectserver could not be found collectserver *collectservermapclass::getcollectserver (const text_t &collection) { // can't find a collection with no name assert (!collection.empty()); if (collection.empty()) return NULL; iterator here = collectserverptrs.find (collection); if (here == collectserverptrs.end()) return NULL; return (*here).second.c; }