Changeset 337 for trunk/gsdl/src/recpt/queryaction.cpp
- Timestamp:
- 1999-07-02T10:48:46+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/queryaction.cpp
r298 r337 12 12 /* 13 13 $Log$ 14 Revision 1.9 1999/07/01 22:48:46 sjboddie 15 had a go at getting a query result format string working 16 14 17 Revision 1.8 1999/06/27 22:02:11 sjboddie 15 18 author is added to queryresults if there is one … … 309 312 } 310 313 314 // returns false if formatstring has errors 315 bool queryaction::parse_formatstring (const text_t &formatstring, text_tarray &formatarray, 316 text_tmap &metamap, text_tarray &metadata, bool &getParents) { 317 318 formatarray.erase (formatarray.begin(), formatarray.end()); 319 metadata.erase (metadata.begin(), metadata.end()); 320 getParents = false; 321 322 text_t::const_iterator here = formatstring.begin(); 323 text_t::const_iterator end = formatstring.end(); 324 325 int metacount = 0; 326 text_t text; 327 while (here != end) { 328 329 if (*here == '\\') 330 text.push_back (*(++here)); 331 332 else if (*here == '<') { 333 if (!text.empty()) formatarray.push_back (text); 334 text.clear(); 335 text_t meta; 336 here ++; 337 while (*here != '>') { 338 if (here == end) return false; 339 meta.push_back (*here); 340 here ++; 341 } 342 parse_meta (meta, metacount, formatarray, metadata, getParents, metamap); 343 344 } else 345 text.push_back (*here); 346 347 here ++; 348 } 349 if (!text.empty()) formatarray.push_back (text); 350 351 return true; 352 } 353 354 void queryaction::get_parent_options (const text_t &instring, text_t &options, 355 text_t &meta) { 356 357 options.clear(); 358 meta.clear(); 359 bool inquotes = false; 360 bool foundcolon = false; 361 text_t::const_iterator here = instring.begin()+6; 362 text_t::const_iterator end = instring.end(); 363 while (here != end) { 364 if (*here == '(') inquotes = true; 365 else if (*here == ')') inquotes = false; 366 else if (*here == ':' && !inquotes) foundcolon = true; 367 else if (foundcolon) meta.push_back (*here); 368 else options.push_back (*here); 369 here ++; 370 } 371 } 372 373 void queryaction::parse_meta (const text_t &meta, int &count, text_tarray &formatarray, 374 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 375 376 if (meta == "link" || meta == "/link") formatarray.push_back ("<" + meta + ">"); 377 else { 378 text_t met = meta; 379 380 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 381 getParents = true; 382 text_t ops; 383 get_parent_options (meta, ops, met); 384 } 385 text_tmap::const_iterator it; 386 if ((it = metamap.find(met)) != metamap.end()) 387 formatarray.push_back(meta); 388 else { 389 metamap[met] = count; 390 metadata.push_back (met); 391 formatarray.push_back (meta); 392 count ++; 393 } 394 } 395 } 396 397 void queryaction::output_results (const ResultDocInfo_tarray &results, const text_tarray &formatarray, 398 const text_tmap &metamap, displayclass &disp, outconvertclass &outconvert, 399 ostream &textout) { 400 401 ResultDocInfo_tarray::const_iterator this_doc = results.begin(); 402 ResultDocInfo_tarray::const_iterator end_doc = results.end(); 403 text_tmap::const_iterator it; 404 405 textout << "<table cellspacing=4>\n"; 406 while (this_doc != end_doc) { 407 textout << "<tr>\n"; 408 409 text_tarray::const_iterator this_format = formatarray.begin(); 410 text_tarray::const_iterator end_format = formatarray.end(); 411 412 while (this_format != end_format) { 413 414 if (*this_format == "<link>") 415 textout << outconvert << disp << "<a href=\"_httpdocument_&cl=search&d=" + (*this_doc).OID + "\">"; 416 else if (*this_format == "</link>") 417 textout << "</a>"; 418 else if ((it = metamap.find(*this_format)) != metamap.end()) 419 textout << outconvert << disp 420 << (*this_doc).metadata[(*it).second.getint()].values.back(); 421 else if ((*this_format).size() > 7 && 422 (substr ((*this_format).begin(), (*this_format).begin()+6) == "parent")) { 423 text_t options, meta; 424 get_parent_options (*this_format, options, meta); 425 if ((it = metamap.find(meta)) != metamap.end()) { 426 int metanum = (*it).second.getint(); 427 if (options.empty()) { 428 // no options - we just want the immediate parent 429 int num = (*this_doc).metadata[metanum].values.size(); 430 if (num > 1) 431 textout << outconvert << disp 432 << (*this_doc).metadata[metanum].values[num-2]; 433 } else if (options == "top") { 434 // want the top parent 435 if ((*this_doc).metadata[metanum].values.size() > 1) 436 textout << outconvert << disp 437 << (*this_doc).metadata[metanum].values[0]; 438 } else { 439 // the 'all' option 440 if (substr (options.begin(), options.begin()+3) != "all") 441 // bad format or unknown option 442 textout << outconvert << disp << *this_format; 443 else { 444 text_t::const_iterator fquote = findchar (options.begin(), options.end(), '\''); 445 text_t separator = substr (fquote+1, findchar (fquote+1, options.end(), '\'')); 446 text_tarray::const_iterator here = (*this_doc).metadata[metanum].values.begin(); 447 // the last metadata value is for the current OID (i.e. it's not a parent) 448 text_tarray::const_iterator end = ((*this_doc).metadata[metanum].values.end()) - 1; 449 bool first = true; 450 while (here != end) { 451 if (!first) textout << outconvert << disp << separator; 452 textout << outconvert << disp << *here; 453 first = false; 454 here ++; 455 } 456 } 457 } 458 } else { 459 // Didn't get any metadata by this name, maybe 460 // it's just plain text that happened to match (oops!!) 461 textout << outconvert << disp << *this_format; 462 } 463 } else 464 textout << outconvert << disp << *this_format; 465 466 this_format ++; 467 468 } 469 textout << "</tr>\n"; 470 this_doc ++; 471 } 472 473 textout << "</table>\n"; 474 } 475 311 476 bool queryaction::do_action (cgiargsclass &args, recptproto *collectproto, 312 477 displayclass &disp, outconvertclass &outconvert, 313 478 ostream &textout, ostream &logout) { 479 480 // if we have no format string see if the collection server has one 481 if (formatstring.empty()) { 482 ColInfoResponse_t collectinfo; 483 comerror_t err; 484 collectproto->get_collectinfo (args["c"], collectinfo, err, logout); 485 if (err == noError) { 486 text_tmap::const_iterator result = collectinfo.format.find("result"); 487 if (result != collectinfo.format.end()) 488 formatstring = (*result).second; 489 } 490 } 491 // if we still don't have a format string use the default 492 if (formatstring.empty()) 493 formatstring = "\\<td valign=top nowrap\\><link>_icontext_</link>\\</td\\>\\<td\\><Title>\\</td\\>"; 314 494 315 495 if (collectproto == NULL) { … … 320 500 } else { 321 501 502 FilterRequest_t request; 503 FilterResponse_t response; 322 504 text_t quotedstring; 323 FilterResponse_t response; 324 505 text_tarray formatarray; 506 text_tmap metamap; 507 parse_formatstring (formatstring, formatarray, metamap, 508 request.fields, request.getParents); 509 325 510 // do the query 326 FilterRequest_t request;327 511 request.filterResultOptions = FROID | FRmetadata | FRtermFreq; 328 request.fields.push_back ("Title");329 request.fields.push_back ("Creator");330 request.getParents = true;512 // request.fields.push_back ("Title"); 513 // request.fields.push_back ("Creator"); 514 // request.getParents = true; 331 515 if (!do_query (request, args, collectproto, quotedstring, response, logout)) 332 516 return false; … … 337 521 // output the header 338 522 textout << outconvert << disp << "_query:header_\n_query:content_"; 339 340 // output results 341 ResultDocInfo_tarray::const_iterator this_doc = response.docInfo.begin(); 342 ResultDocInfo_tarray::const_iterator end_doc = response.docInfo.end(); 343 344 textout << "<table cellspacing=4>\n"; 345 while (this_doc != end_doc) { 346 347 text_t link = "<a href=\"_httpdocument_&cl=search&d=" + (*this_doc).OID + "\">"; 348 349 text_t title; 350 text_tarray::const_iterator this_title = (*this_doc).metadata[0].values.begin(); 351 text_tarray::const_iterator end_title = (*this_doc).metadata[0].values.end(); 352 while (this_title != end_title) { 353 if ((this_title + 1) == end_title) 354 title += link + *this_title + "</a>"; 355 else 356 title += *this_title + ": "; 357 this_title ++; 358 } 359 360 text_t creator; 361 bool first = true; 362 text_tarray::const_iterator this_creator = (*this_doc).metadata[1].values.begin(); 363 text_tarray::const_iterator end_creator = (*this_doc).metadata[1].values.end(); 364 while (this_creator != end_creator) { 365 if ((*this_creator).empty()) {this_creator ++; continue;} 366 if (first) creator += " by " + *this_creator; 367 else creator += " and " + *this_creator; 368 first = false; 369 this_creator ++; 370 } 371 372 textout << outconvert << disp << "<tr><td valign=top nowrap>" << link 373 << "_icontext_</a></td><td>" << title << creator << "</td></tr>\n"; 374 375 this_doc ++; 376 } 377 textout << "</table>\n"; 523 524 output_results (response.docInfo, formatarray, metamap, disp, outconvert, textout); 525 378 526 379 527 // output the footer
Note:
See TracChangeset
for help on using the changeset viewer.