- Timestamp:
- 2017-02-08T18:31:18+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/colservr/browsefilter.cpp
r16310 r31387 26 26 #include "browsefilter.h" 27 27 #include "fileutil.h" 28 #include <assert.h> 28 29 29 30 30 31 browsefilterclass::browsefilterclass () { 31 32 db_ptr = NULL; 33 oaidb_ptr = NULL; 32 34 33 35 // -- onePerQuery StartResults integer … … 60 62 } 61 63 62 browsefilterclass::~browsefilterclass () { 63 } 64 browsefilterclass::~browsefilterclass () {} 64 65 65 66 void browsefilterclass::configure (const text_t &key, const text_tarray &cfgline) { … … 75 76 if (!filterclass::init(logout)) return false; 76 77 77 if (db_ptr == NULL ) {78 if (db_ptr == NULL || oaidb_ptr == NULL) { 78 79 // most likely a configuration problem 79 80 logout << text_t2ascii … … 93 94 } 94 95 96 oaidb_filename = resolve_oaidb_filename(oaidb_ptr->getfileextension()); 97 95 98 return true; 96 99 } … … 104 107 response.clear (); 105 108 err = noError; 106 if (db_ptr == NULL) {107 // most likely a configuration problem108 logout << text_t2ascii109 << "configuration error: browsefilter contains a null dbclass\n\n";110 err = configurationError;111 return;112 }113 114 // open the database115 db_ptr->setlogout(&logout);116 if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {117 // most likely a system problem (we have already checked that the database exists)118 logout << text_t2ascii119 << "system problem: open on database \""120 << db_filename << "\" failed\n\n";121 err = systemProblem;122 return;123 }124 109 125 110 // get the browse parameters … … 146 131 } 147 132 133 // if we're only working on oai, open oai_db, no need to work with index_db in browsefilter.cpp 134 // (but source.cpp uses both oai-inf.db and index.db to get metadata for OAI request) 135 // If we can't open the oai-inf db, this can be because it didn't exist in older versions of GS 136 // in that case, proceed as usual, using the index db. 137 if((request.filterResultOptions & FROAI)) { // OAI request 138 bool success = false; 139 140 if(parentnode == "oai") { // doing an OAI listidentifiers request 141 142 // open up the oai-inf db, if it exists, and return all IDs 143 // if it doesn't exist, proceed as usual 144 success = get_oaiinf_db_entries(response, err, logout); //adds any stuff in oai-inf db for the current OID to resultdoc.metadata 145 146 response.numDocs = response.docInfo.size(); 147 response.isApprox = Exact; 148 } 149 if (success) return; // oai request successfully completed with oai-inf.db, no need to open index_db 150 } 151 152 // Since we're here, it means we're not doing anything oai (or oai-inf.db did not exist/open) 153 // So we don't need to work with oai_db. Instead, work with index_db: 154 155 if (db_ptr == NULL) { 156 // most likely a configuration problem 157 logout << text_t2ascii 158 << "configuration error: browsefilter contains a null index dbclass\n\n"; 159 err = configurationError; 160 return; 161 } 162 163 // open the database 164 db_ptr->setlogout(&logout); 165 if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) { 166 // most likely a system problem (we have already checked that the database exists) 167 logout << text_t2ascii 168 << "system problem: open on database \"" 169 << db_filename << "\" failed\n\n"; 170 err = systemProblem; 171 return; 172 } 173 148 174 infodbclass info; 149 175 … … 158 184 (request.filterResultOptions & FRmetadata)) { 159 185 if (!db_ptr->getinfo(parentnode, info)) { 160 // didn't find the node 186 // didn't find the node in index db 161 187 logout << text_t2ascii 162 188 << "warning: lookup for node \"" << parentnode … … 308 334 response.isApprox = Exact; 309 335 } 336 337 bool browsefilterclass::get_oaiinf_db_entries(FilterResponse_t &response, 338 comerror_t &err, ostream &logout) 339 { 340 outconvertclass text_t2ascii; 341 342 //logout << text_t2ascii << "browsefilterclass::get_oaiinf_db_entries\n"; 343 344 // ONLY if we're doing any OAI stuff (FROAI will be set then) will we be here 345 // So next try to open the oai-inf db if it exists for this collection 346 347 348 if (!file_exists(oaidb_filename)) { // if the oaidb file doesn't even exist, let's not bother with oaidb 349 350 logout << text_t2ascii 351 << "warning: collection's oai-inf database \"" << oaidb_filename << "\" does not exist\n\n"; 352 return false; 353 354 } else { // let's try opening the oaidb file 355 oaidb_ptr->setlogout(&logout); 356 if (!oaidb_ptr->opendatabase (oaidb_filename, DB_READER, 100, false)) { 357 // most likely a system problem (we have already checked that the database exists just above) 358 logout << text_t2ascii 359 << "system problem: open on database \"" 360 << oaidb_filename << "\" failed\n\n"; 361 err = systemProblem; 362 return false; 363 } // now we've opened the oai-inf db file successfully 364 } 365 366 infodbclass oai_info; 367 ResultDocInfo_t resultdoc; 368 369 text_tarray keys = oaidb_ptr->getkeys(); 370 371 text_tarray::iterator key_here = keys.begin(); 372 text_tarray::iterator key_end = keys.end(); 373 while (key_here != key_end) { 374 375 resultdoc.OID = (*key_here); 376 377 if(!oaidb_ptr->getinfo(resultdoc.OID, oai_info)) { 378 logout << text_t2ascii 379 << "warning: lookup for node \"" << resultdoc.OID 380 << "\" in etc/oai-inf db failed for browsefilter.\n\n"; 381 } else { 382 //logout << text_t2ascii << "@@@@ found node \"" << resultdoc.OID << "\" in etc/oai-inf db.\n\n"; 383 384 resultdoc.metadata["oaiinf.status"].isRef = false; 385 resultdoc.metadata["oaiinf.status"].values.push_back(oai_info["status"]); 386 resultdoc.metadata["oaiinf.timestamp"].isRef = false; 387 resultdoc.metadata["oaiinf.timestamp"].values.push_back(oai_info["timestamp"]); 388 resultdoc.metadata["oaiinf.datestamp"].isRef = false; 389 resultdoc.metadata["oaiinf.datestamp"].values.push_back(oai_info["datestamp"]); 390 } 391 392 response.docInfo.push_back(resultdoc); 393 ++key_here; 394 395 } 396 397 // we're done with oai-inf db 398 399 oaidb_ptr->closedatabase(); // don't leave files open 400 401 return true; 402 }
Note:
See TracChangeset
for help on using the changeset viewer.