[166] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * collectserver.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * PUT COPYRIGHT NOTICE HERE
|
---|
| 7 | *
|
---|
| 8 | * $Id: collectserver.cpp 191 1999-03-08 05:07:42Z rjmcnab $
|
---|
| 9 | *
|
---|
| 10 | *********************************************************************/
|
---|
| 11 |
|
---|
| 12 | /*
|
---|
| 13 | $Log$
|
---|
[191] | 14 | Revision 1.3 1999/03/08 05:07:42 rjmcnab
|
---|
| 15 | Made some alterations to fit with the changes to the comtypes. Added the
|
---|
| 16 | "filteroptdefault" configuration option to alter default filter options.
|
---|
| 17 |
|
---|
[186] | 18 | Revision 1.2 1999/03/03 23:28:29 sjboddie
|
---|
| 19 |
|
---|
| 20 | Provided stub functions for the protocol
|
---|
| 21 |
|
---|
[166] | 22 | Revision 1.1 1999/02/21 22:32:56 rjmcnab
|
---|
| 23 |
|
---|
| 24 | Initial revision.
|
---|
| 25 |
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #include "collectserver.h"
|
---|
| 30 | #include <assert.h>
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | collectserver::collectserver () {
|
---|
| 34 | configinfo.collection = "null";
|
---|
[191] | 35 |
|
---|
| 36 |
|
---|
| 37 | // set up the QueryFilter information
|
---|
| 38 | FilterDescript_t &queryfilter = filterinfo.filterOptions["QueryFilter"];
|
---|
| 39 | queryfilter.filterName = "QueryFilter";
|
---|
| 40 |
|
---|
| 41 | // -- onePerQuery StartResults integer
|
---|
| 42 | FilterOption_t &qfopt1 = queryfilter.filterOptions["StartResults"];
|
---|
| 43 | qfopt1.name = "StartResults";
|
---|
| 44 | qfopt1.type = FilterOption_t::integert;
|
---|
| 45 | qfopt1.repeatable = FilterOption_t::onePerQuery;
|
---|
| 46 | qfopt1.defaultValue = 1;
|
---|
| 47 | qfopt1.validValues.push_back ("1");
|
---|
| 48 | qfopt1.validValues.push_back ("500");
|
---|
| 49 |
|
---|
| 50 | // -- onePerQuery EndResults integer
|
---|
| 51 | FilterOption_t &qfopt2 = queryfilter.filterOptions["EndResults"];
|
---|
| 52 | qfopt2.name = "EndResults";
|
---|
| 53 | qfopt2.type = FilterOption_t::integert;
|
---|
| 54 | qfopt2.repeatable = FilterOption_t::onePerQuery;
|
---|
| 55 | qfopt2.defaultValue = 20;
|
---|
| 56 | qfopt2.validValues.push_back ("1");
|
---|
| 57 | qfopt2.validValues.push_back ("500");
|
---|
| 58 |
|
---|
| 59 | // -- onePerQuery QueryType enumerated (boolean, ranked)
|
---|
| 60 | FilterOption_t &qfopt3 = queryfilter.filterOptions["QueryType"];
|
---|
| 61 | qfopt3.name = "QueryType";
|
---|
| 62 | qfopt3.type = FilterOption_t::enumeratedt;
|
---|
| 63 | qfopt3.repeatable = FilterOption_t::onePerQuery;
|
---|
| 64 | qfopt3.defaultValue = "boolean";
|
---|
| 65 | qfopt3.validValues.push_back ("boolean");
|
---|
| 66 | qfopt3.validValues.push_back ("ranked");
|
---|
| 67 |
|
---|
| 68 | // -- onePerTerm Term string ???
|
---|
| 69 | FilterOption_t &qfopt3b = queryfilter.filterOptions["Term"];
|
---|
| 70 | qfopt3b.name = "Term";
|
---|
| 71 | qfopt3b.type = FilterOption_t::stringt;
|
---|
| 72 | qfopt3b.repeatable = FilterOption_t::onePerTerm;
|
---|
| 73 | qfopt3b.defaultValue = "";
|
---|
| 74 |
|
---|
| 75 | // -- onePerTerm Casefold boolean
|
---|
| 76 | FilterOption_t &qfopt4 = queryfilter.filterOptions["Casefold"];
|
---|
| 77 | qfopt4.name = "Casefold";
|
---|
| 78 | qfopt4.type = FilterOption_t::booleant;
|
---|
| 79 | qfopt4.repeatable = FilterOption_t::onePerTerm;
|
---|
| 80 | qfopt4.defaultValue = "on";
|
---|
| 81 | qfopt4.validValues.push_back ("on");
|
---|
| 82 | qfopt4.validValues.push_back ("off");
|
---|
| 83 |
|
---|
| 84 | // -- onePerTerm Stem boolean
|
---|
| 85 | FilterOption_t &qfopt5 = queryfilter.filterOptions["Stem"];
|
---|
| 86 | qfopt5.name = "Stem";
|
---|
| 87 | qfopt5.type = FilterOption_t::booleant;
|
---|
| 88 | qfopt5.repeatable = FilterOption_t::onePerTerm;
|
---|
| 89 | qfopt5.defaultValue = "on";
|
---|
| 90 | qfopt5.validValues.push_back ("on");
|
---|
| 91 | qfopt5.validValues.push_back ("off");
|
---|
| 92 |
|
---|
| 93 | // -- onePerTerm Index enumerated
|
---|
| 94 | FilterOption_t &qfopt6 = queryfilter.filterOptions["Index"];
|
---|
| 95 | qfopt6.name = "Index";
|
---|
| 96 | qfopt6.type = FilterOption_t::enumeratedt;
|
---|
| 97 | qfopt6.repeatable = FilterOption_t::onePerTerm;
|
---|
| 98 | qfopt6.defaultValue = "";
|
---|
| 99 |
|
---|
| 100 | // -- onePerTerm Subcollection enumerated
|
---|
| 101 | FilterOption_t &qfopt7 = queryfilter.filterOptions["Subcollection"];
|
---|
| 102 | qfopt7.name = "Subcollection";
|
---|
| 103 | qfopt7.type = FilterOption_t::enumeratedt;
|
---|
| 104 | qfopt7.repeatable = FilterOption_t::onePerTerm;
|
---|
| 105 | qfopt7.defaultValue = "";
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | // set up the BrowseFilter information
|
---|
| 109 | FilterDescript_t &browsefilter = filterinfo.filterOptions["BrowseFilter"];
|
---|
| 110 | browsefilter.filterName = "BrowseFilter";
|
---|
| 111 |
|
---|
| 112 | // -- onePerQuery StartResults integer
|
---|
| 113 | FilterOption_t &bfopt1 = browsefilter.filterOptions["StartResults"];
|
---|
| 114 | bfopt1.name = "StartResults";
|
---|
| 115 | bfopt1.type = FilterOption_t::integert;
|
---|
| 116 | bfopt1.repeatable = FilterOption_t::onePerQuery;
|
---|
| 117 | bfopt1.defaultValue = 1;
|
---|
| 118 | bfopt1.validValues.push_back ("1");
|
---|
| 119 | bfopt1.validValues.push_back ("500");
|
---|
| 120 |
|
---|
| 121 | // -- onePerQuery EndResults integer
|
---|
| 122 | FilterOption_t &bfopt2 = browsefilter.filterOptions["EndResults"];
|
---|
| 123 | bfopt2.name = "EndResults";
|
---|
| 124 | bfopt2.type = FilterOption_t::integert;
|
---|
| 125 | bfopt2.repeatable = FilterOption_t::onePerQuery;
|
---|
| 126 | bfopt2.defaultValue = 20;
|
---|
| 127 | bfopt2.validValues.push_back ("1");
|
---|
| 128 | bfopt2.validValues.push_back ("500");
|
---|
| 129 |
|
---|
| 130 | // -- onePerQuery ParentNode string ("" will return the browsing available)
|
---|
| 131 | FilterOption_t &bfopt3 = browsefilter.filterOptions["ParentNode"];
|
---|
| 132 | bfopt3.name = "ParentNode";
|
---|
| 133 | bfopt3.type = FilterOption_t::stringt;
|
---|
| 134 | bfopt3.repeatable = FilterOption_t::onePerQuery;
|
---|
| 135 | bfopt3.defaultValue = "";
|
---|
[166] | 136 | }
|
---|
| 137 |
|
---|
| 138 | collectserver::~collectserver () {
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | // configure should be called for each line in the
|
---|
| 142 | // configuration files to configure the collection server and everything
|
---|
| 143 | // it contains. The configuration should take place just before initialisation.
|
---|
| 144 | void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
[191] | 145 | if (key == "indexmap") configinfo.indexmap = cfgline;
|
---|
| 146 | else if (key == "subcollectionmap") configinfo.subcollectionmap = cfgline;
|
---|
| 147 | else if (key == "languagemap") configinfo.languagemap = cfgline;
|
---|
| 148 |
|
---|
| 149 | else if (cfgline.size() >= 1) {
|
---|
[166] | 150 | const text_t &value = cfgline[0];
|
---|
| 151 | if (key == "gsdlhome") configinfo.gsdlhome = value;
|
---|
| 152 | else if (key == "collection") {
|
---|
| 153 | configinfo.collection = value;
|
---|
| 154 | collectinfo.shortInfo.name = value;
|
---|
| 155 | } else if (key == "collectdir") configinfo.collectdir = value;
|
---|
| 156 | else if (key == "host") collectinfo.shortInfo.host = value;
|
---|
| 157 | else if (key == "port") collectinfo.shortInfo.port = value.getint();
|
---|
| 158 | else if (key == "public") {
|
---|
| 159 | if (value == "true") collectinfo.isPublic = true;
|
---|
| 160 | else collectinfo.isPublic = false;
|
---|
| 161 | } else if (key == "beta") {
|
---|
| 162 | if (value == "true") collectinfo.isBeta = true;
|
---|
| 163 | else collectinfo.isBeta = false;
|
---|
| 164 | } else if (key == "builddate") collectinfo.buildDate = value.getint();
|
---|
| 165 | else if (key == "languages") collectinfo.languages = cfgline;
|
---|
| 166 | else if (key == "numdocs") collectinfo.numDocs = value.getint();
|
---|
| 167 | else if (key == "numwords") collectinfo.numWords = value.getint();
|
---|
| 168 | else if (key == "numbytes") collectinfo.numBytes = value.getint();
|
---|
[191] | 169 |
|
---|
| 170 | else if ((key == "filteroptdefault") && (cfgline.size() == 2)) {
|
---|
| 171 | // set this default for each type of filter
|
---|
| 172 | FilterDescript_tmap::iterator filteropthere = filterinfo.filterOptions.begin();
|
---|
| 173 | FilterDescript_tmap::iterator filteroptend = filterinfo.filterOptions.end();
|
---|
| 174 |
|
---|
| 175 | while (filteropthere != filteroptend) {
|
---|
| 176 | // see if this filter has an option with this name
|
---|
| 177 | FilterOption_tmap &fotm = (*filteropthere).second.filterOptions;
|
---|
| 178 | if (fotm.find(cfgline[0]) != fotm.end()) {
|
---|
| 179 | (*(fotm.find(cfgline[0]))).second.defaultValue = cfgline[1];
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | filteropthere++;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
[166] | 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | void collectserver::configure (const text_t &key, const text_t &value) {
|
---|
| 189 | text_tarray cfgline;
|
---|
| 190 | cfgline.push_back (value);
|
---|
| 191 | configure(key, cfgline);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | bool collectserver::init (ostream &/*logout*/) {
|
---|
| 196 | return true;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
[186] | 200 | void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
|
---|
| 201 | comerror_t &err, ostream &/*logout*/) {
|
---|
| 202 | reponse = collectinfo;
|
---|
| 203 | err = noError;
|
---|
| 204 | }
|
---|
[166] | 205 |
|
---|
[186] | 206 | void collectserver::get_filteroptions (InfoFilterOptionsResponse_t &response,
|
---|
| 207 | comerror_t &err, ostream &/*logout*/) {
|
---|
[191] | 208 |
|
---|
[186] | 209 | err = noError;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | void collectserver::filter (const FilterRequest_t &request,
|
---|
| 213 | FilterResponse_t &response,
|
---|
| 214 | comerror_t &err, ostream &/*logout*/) {
|
---|
[191] | 215 | if (request.filterName == "QueryFilter") {
|
---|
| 216 | // return documents
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | } else {
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 |
|
---|
[186] | 224 | err = noError;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | void collectserver::get_metadataoptions (MetadataInfoResponse_t &response,
|
---|
| 228 | comerror_t &err, ostream &/*logout*/) {
|
---|
| 229 | err = noError;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | void collectserver::get_metadata (const MetadataRequest_t &request,
|
---|
| 233 | MetadataResponse_t &response,
|
---|
| 234 | comerror_t &err, ostream &/*logout*/) {
|
---|
| 235 | err = noError;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 |
|
---|
[166] | 241 | // thecollectserver remains the property of the calling code but
|
---|
| 242 | // should not be deleted until it is removed from this list.
|
---|
| 243 | void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
|
---|
| 244 | // can't add a null collection server
|
---|
| 245 | assert (thecollectserver != NULL);
|
---|
| 246 | if (thecollectserver == NULL) return;
|
---|
| 247 |
|
---|
| 248 | // can't add an collection server with no collection name
|
---|
| 249 | assert (!(thecollectserver->get_collection_name()).empty());
|
---|
| 250 | if ((thecollectserver->get_collection_name()).empty()) return;
|
---|
| 251 |
|
---|
| 252 | collectserverptr cptr;
|
---|
| 253 | cptr.c = thecollectserver;
|
---|
| 254 | collectserverptrs[thecollectserver->get_collection_name()] = cptr;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | // getcollectserver will return NULL if the collectserver could not be found
|
---|
| 258 | collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
|
---|
| 259 | // can't find a collection with no name
|
---|
| 260 | assert (!collection.empty());
|
---|
| 261 | if (collection.empty()) return NULL;
|
---|
| 262 |
|
---|
| 263 | iterator here = collectserverptrs.find (collection);
|
---|
| 264 | if (here == collectserverptrs.end()) return NULL;
|
---|
| 265 |
|
---|
| 266 | return (*here).second.c;
|
---|
| 267 | }
|
---|
| 268 |
|
---|