Changeset 928 for trunk/gsdl/src/recpt/queryaction.cpp
- Timestamp:
- 2000-02-16T11:53:52+13:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/queryaction.cpp
r865 r928 28 28 /* 29 29 $Log$ 30 Revision 1.34 2000/02/15 22:53:52 kjm18 31 search history stuff added. 32 30 33 Revision 1.33 2000/01/24 22:57:59 sjboddie 31 34 fixed bug in cross-collection searching, tidied up a bit … … 151 154 #include "cgiutils.h" 152 155 #include "OIDtools.h" 156 //#include "infodbclass.h" 157 #include "fileutil.h" 158 #include "text_t.h" 159 #include "historydb.h" 153 160 154 161 void colinfo_t::clear () { … … 347 354 arg_ainfo.savedarginfo = cgiarginfo::must; 348 355 argsinfo.addarginfo (NULL, arg_ainfo); 356 357 // "hd" history display - search history only displayed when 358 // this var set. 359 arg_ainfo.shortname = "hd"; 360 arg_ainfo.longname = "history display"; 361 arg_ainfo.multiplechar = false; 362 arg_ainfo.defaultstatus = cgiarginfo::weak; 363 arg_ainfo.argdefault = "0"; 364 arg_ainfo.savedarginfo = cgiarginfo::must; 365 argsinfo.addarginfo (NULL, arg_ainfo); 366 367 368 // "hs" save - set to 1 in query form, so only save when submit 369 // query 370 // 0 = no save 1 = save 371 arg_ainfo.shortname = "hs"; 372 arg_ainfo.longname = "history save"; 373 arg_ainfo.multiplechar = false; 374 arg_ainfo.defaultstatus = cgiarginfo::weak; 375 arg_ainfo.argdefault = "0"; 376 arg_ainfo.savedarginfo = cgiarginfo::mustnot; 377 argsinfo.addarginfo (NULL, arg_ainfo); 378 379 380 // "hcl" compress the list (show only the last 5) 381 // 0 = expand, 1 = compress 382 383 arg_ainfo.shortname = "hcl"; 384 arg_ainfo.longname = "history compress list"; 385 arg_ainfo.multiplechar = false; 386 arg_ainfo.defaultstatus = cgiarginfo::weak; 387 arg_ainfo.argdefault = "1"; 388 arg_ainfo.savedarginfo = cgiarginfo::must; 389 argsinfo.addarginfo (NULL, arg_ainfo); 390 391 349 392 350 393 } … … 407 450 cgiarginfo *rinfo = argsinfo.getarginfo ("r"); 408 451 if (rinfo != NULL) args["r"] = rinfo->argdefault; 452 } 453 //check hd argument 454 int arg_hd = args.getintarg("hd"); 455 if (arg_hd !=0 && arg_hd !=1) { 456 logout << "Warning: \"hd\" argument out of range (" << arg_hd << ")\n"; 457 cgiarginfo *hdinfo = argsinfo.getarginfo ("hd"); 458 if (hdinfo != NULL) args["hd"] = hdinfo->argdefault; 459 } 460 //check hs argument 461 int arg_hs = args.getintarg("hs"); 462 if (arg_hs !=0 && arg_hs !=1) { 463 logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n"; 464 cgiarginfo *hsinfo = argsinfo.getarginfo ("hs"); 465 if (hsinfo != NULL) args["hs"] = hsinfo->argdefault; 466 } 467 468 // chech hcl argument 469 int arg_hcl = args.getintarg("hcl"); 470 if (arg_hcl !=0 && arg_hcl !=1) { 471 logout << "Warning: \"hcl\" argument out of range (" << arg_hcl << ")\n"; 472 cgiarginfo *hclinfo = argsinfo.getarginfo ("hcl"); 473 if (hclinfo != NULL) args["hcl"] = hclinfo->argdefault; 409 474 } 410 475 … … 505 570 // _cq2selection the selection box for combining two queries 506 571 507 572 508 573 // can't do anything if collectproto is null (i.e. no collection was specified) 509 574 recptproto *collectproto = protos->getrecptproto (args["c"], logout); … … 539 604 it = response.filterOptions.find ("CombineQuery"); 540 605 if (it != end) set_option_macro ("cq2", args["cq2"], (*it).second, disp); 541 } 606 607 // define_history_macros(disp, args, protos, logout); 608 } 609 } // define external macros 610 611 void queryaction::define_history_macros(displayclass &disp, cgiargsclass &args, 612 recptprotolistclass *protos, ostream &logout) { 613 614 // defines the following macros 615 616 // _searchhistorylist_ 617 618 text_t historylist; 619 int arghd = args.getintarg("hd"); 620 if (arghd != 1) { 621 historylist=""; 622 } 623 else { 624 historylist = "<!-- Search History List -->\n"; 625 626 text_t userid = args["z"]; 627 text_tarray entries; 628 if (get_history_info(userid, entries)) { 629 int count = 1; 630 text_tarray::iterator here = entries.begin(); 631 text_tarray::iterator end = entries.end(); 632 int size=(int)entries.size(); 633 if (args["hcl"]==1&&size>5) { // compress the list 634 here = end-5; 635 count=size-4; 636 } 637 historylist += "<table align=center width=500 border=0>\n"; 638 historylist += "<tr><td width=300 align=center>"; 639 historylist += "<a href=\"_httpclearhistory_\">Clear History</a></td>\n"; 640 641 if (size>5&&args["hcl"]==1) { //compress the list, show the expand button 642 643 historylist += "<td><a href=\"_gwcgi_?e=_compressedoptions_&a=q&hcl=0\">Expand</a></td>\n"; 644 } 645 else if (size >5 && args["hcl"]==0) { // expand the list, show contract button 646 historylist += "<td><a href=\"_gwcgi_?e=_compressedoptions_&a=q&hcl=1\">Contract</a></td>\n"; 647 } 648 historylist += "</table>\n"; 649 historylist += " <table align=center width=500 border=1> \n <tr><th colspan=4 align=center>"; 650 historylist += "Search History </th></tr>\n"; 651 historylist += "<tr><th width=40>#</th>\n<th width=340>Query</th>\n"; 652 historylist += "<th width=60>Results</th><th width=60>View</th></tr>\n"; 653 654 while (here !=end ) { 655 text_t c; 656 text_t query; 657 text_t q = "q"; 658 text_t numdocs; 659 text_t cgiargs; 660 text_t userinfo; 661 split_saved_query(*here,c, numdocs, cgiargs); 662 parse_saved_args(cgiargs, q, query); // get query string out 663 decode_cgi_arg(query); // un cgisafe it 664 665 format_user_info(cgiargs, userinfo, protos, logout); 666 667 historylist += "<tr> <td width=40 align=center>"+c+"</td>\n"; 668 historylist += "<td width=340 align=left>"+query+"</td><td width=60 align=center>"+numdocs+"</td>\n"; 669 historylist += "<td width=60 align=center><a href=\"_gwcgi_?e=_compressedoptions_&"; 670 historylist += *here+"\"><img name=\"display\" src=\"/gsdl/images/display.gif\" width=\"60\" "; 671 historylist += "height=\"20\" border=\"0\" alt=\"" + userinfo +"\"></a></td></tr>\n"; 672 here++; 673 count++; 674 } 675 historylist+="</table>\n\n"; 676 677 } // if 678 else { 679 historylist += "Search history not available\n"; 680 } 681 historylist += "<p><! ---- end of history list ----->\n"; 682 } // else display list 683 disp.setmacro("searchhistorylist", "query", historylist); 684 685 } // define history macros 686 687 void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos, 688 displayclass &disp, outconvertclass &outconvert, 689 ostream &textout, ostream &logout) { 690 691 ColInfoResponse_t cinfo; 692 comerror_t err; 693 InfoFilterOptionsResponse_t fresponse; 694 InfoFilterOptionsRequest_t frequest; 695 frequest.filterName = "QueryFilter"; 696 697 text_t &index = args["h"]; 698 text_t &subcollection = args["j"]; 699 text_t &language = args["n"]; 700 701 text_tset collections; 702 text_t arg_cc = args["cc"]; 703 decode_cgi_arg (arg_cc); 704 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections); 705 706 textout << outconvert << disp << "_query:header_\n" 707 << "<center>_navigationbar_</center><br>\n" 708 << "<form name=QueryForm method=get action=\"_gwcgi_\">\n" 709 << "<input type=hidden name=a value=\"q\">\n" 710 << "<input type=hidden name=e value=\"_compressedoptions_\">\n" 711 << "<input type=hidden name=ccp value=\"1\">\n" 712 << "<center><table width=_pagewidth_><tr valign=top>\n" 713 << "<td>Select collections to search for \"" << args["q"] 714 << "\" <i>(index=" << index << " subcollection=" << subcollection 715 << " language=" << language << ")</i></td>\n" 716 << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n" 717 << "</tr></table></center>\n" 718 << "<center><table width=_pagewidth_>\n" 719 << "<tr><td>\n"; 720 721 recptprotolistclass::iterator rprotolist_here = protos->begin(); 722 recptprotolistclass::iterator rprotolist_end = protos->end(); 723 while (rprotolist_here != rprotolist_end) { 724 if ((*rprotolist_here).p != NULL) { 725 726 text_tarray collist; 727 (*rprotolist_here).p->get_collection_list (collist, err, logout); 728 if (err == noError) { 729 text_tarray::iterator collist_here = collist.begin(); 730 text_tarray::iterator collist_end = collist.end(); 731 while (collist_here != collist_end) { 732 733 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout); 734 // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) { 735 if (err == noError && (cinfo.buildDate > 0)) { 736 737 (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout); 738 if (err == noError) { 739 740 FilterOption_tmap::const_iterator it; 741 FilterOption_tmap::const_iterator end = fresponse.filterOptions.end(); 742 if (!index.empty()) { 743 it = fresponse.filterOptions.find ("Index"); 744 if (it == end) {collist_here ++; continue;} 745 text_tarray::const_iterator there = (*it).second.validValues.begin(); 746 text_tarray::const_iterator tend = (*it).second.validValues.end(); 747 while (there != tend) { 748 if (*there == index) break; 749 there ++; 750 } 751 if (there == tend) {collist_here++; continue;} 752 } 753 if (!subcollection.empty()) { 754 it = fresponse.filterOptions.find ("Subcollection"); 755 if (it == end) {collist_here++; continue;} 756 text_tarray::const_iterator there = (*it).second.validValues.begin(); 757 text_tarray::const_iterator tend = (*it).second.validValues.end(); 758 while (there != tend) { 759 if (*there == subcollection) break; 760 there ++; 761 } 762 if (there == tend) {collist_here++; continue;} 763 } 764 if (!language.empty()) { 765 it = fresponse.filterOptions.find ("Language"); 766 if (it == end) {collist_here++; continue;} 767 text_tarray::const_iterator there = (*it).second.validValues.begin(); 768 text_tarray::const_iterator tend = (*it).second.validValues.end(); 769 while (there != tend) { 770 if (*there == language) break; 771 there ++; 772 } 773 if (there == tend) {collist_here++; continue;} 774 } 775 776 // we've got a matching collection 777 textout << "<input type=checkbox"; 778 779 text_tset::const_iterator t = collections.find (*collist_here); 780 if (t != collections.end()) textout << " checked"; 781 782 textout << outconvert 783 << " name=cc value=\"" << *collist_here << "\">"; 784 785 if (!cinfo.collectionmeta["collectionname"].empty()) 786 textout << outconvert << disp << cinfo.collectionmeta["collectionname"]; 787 else 788 textout << outconvert << *collist_here; 789 790 textout << "<br>\n"; 791 792 } 793 } 794 collist_here ++; 795 } 796 } 797 } 798 rprotolist_here ++; 799 } 800 textout << outconvert << disp 801 << "</td></tr></table></center>\n" 802 << "</form>\n" 803 << "_query:footer_\n"; 804 542 805 } 543 806 … … 823 1086 request.filterResultOptions = FROID | FRmetadata | FRtermFreq; 824 1087 text_t formattedstring = args["q"]; 1088 if (!combine_query(args["z"], formattedstring)) { 1089 args["q"]=formattedstring; 1090 } 825 1091 format_querystring (formattedstring, args.getintarg("b")); 826 1092 set_queryfilter_options (request, formattedstring, args); … … 833 1099 return false; 834 1100 } 1101 835 1102 836 1103 define_query_macros (args, disp, response); 1104 1105 // save the query if appropriate 1106 if (!save_search_history(args, response)) 1107 logout << "save failed"; 1108 1109 define_history_macros(disp, args, protos, logout); 837 1110 838 1111 textout << outconvert << disp << "_query:header_\n" … … 859 1132 void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp, 860 1133 const FilterResponse_t &response) { 1134 861 1135 // set up _freqmsg_ and _quotedquery_ macros 862 1136 text_t freqmsg = "_textfreqmsg1_"; … … 920 1194 } 921 1195 922 923 1196 bool queryaction::save_search_history (cgiargsclass &args, const FilterResponse_t &response) 1197 { 1198 if (args["q"]=="") return true; // null query, dont save 1199 if (args["hs"]=="0") return true; // only save when submit query 1200 1201 // get userid 1202 text_t userid = args["z"]; 1203 1204 // the number of docs goes on the front of the query string 1205 int numdocs= response.numDocs; 1206 text_t query = text_t(numdocs); 1207 if (response.isApprox==MoreThan) { // there were more docs found 1208 query.push_back('+'); 1209 } 1210 query += "a=q"; 1211 query += "&c="+args["c"]; 1212 query += "&h="+args["h"]; 1213 query += "&t="+args["t"]; 1214 query += "&b="+args["b"]; 1215 query += "&j="+args["j"]; 1216 query += "&n="+args["n"]; 1217 query += "&s="+args["s"]; 1218 query += "&k="+args["k"]; 1219 1220 text_t qstring = args["q"]; 1221 text_t formattedquery =cgi_safe(qstring); 1222 query += "&q="+formattedquery; 1223 1224 if (set_history_info(userid, query)) return true; 1225 else return false; 1226 1227 1228 } 1229 1230 1231 1232 1233
Note:
See TracChangeset
for help on using the changeset viewer.