- Timestamp:
- 2010-05-06T12:55:03+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp
r20601 r22046 38 38 #include <assert.h> 39 39 40 void colinfo_t::clear () { 41 formatlistptr = NULL; 42 browserptr = NULL; 43 } 44 45 void QueryResult_t::clear() { 46 doc.clear(); 47 collection.clear(); 48 } 49 50 queryaction::queryaction () { 51 52 recpt = NULL; 40 41 queryaction::queryaction () 42 : basequeryaction() 43 { 53 44 num_phrases = 0; 54 45 46 cgiarginfo arg_ainfo; 47 55 48 // this action uses cgi variable "a" 56 cgiarginfo arg_ainfo;57 49 arg_ainfo.shortname = "a"; 58 50 arg_ainfo.longname = "action"; … … 136 128 137 129 138 // "q"139 arg_ainfo.shortname = "q";140 arg_ainfo.longname = "query string";141 arg_ainfo.multiplechar = true;142 arg_ainfo.defaultstatus = cgiarginfo::weak;143 arg_ainfo.argdefault = g_EmptyText;144 arg_ainfo.savedarginfo = cgiarginfo::must;145 argsinfo.addarginfo (NULL, arg_ainfo);146 147 // "q2"148 arg_ainfo.shortname = "q2";149 arg_ainfo.longname = "query string for second query";150 arg_ainfo.multiplechar = true;151 arg_ainfo.defaultstatus = cgiarginfo::weak;152 arg_ainfo.argdefault = g_EmptyText;153 arg_ainfo.savedarginfo = cgiarginfo::must;154 argsinfo.addarginfo (NULL, arg_ainfo);155 156 // "cq2" ""=don't combine, "and", "or", "not"157 arg_ainfo.shortname = "cq2";158 arg_ainfo.longname = "combine queries";159 arg_ainfo.multiplechar = true;160 arg_ainfo.defaultstatus = cgiarginfo::weak;161 arg_ainfo.argdefault = g_EmptyText;162 arg_ainfo.savedarginfo = cgiarginfo::must;163 argsinfo.addarginfo (NULL, arg_ainfo);164 165 130 // "t" - 1 = ranked 0 = boolean 166 131 arg_ainfo.shortname = "t"; … … 226 191 argsinfo.addarginfo (NULL, arg_ainfo); 227 192 228 // "m"229 arg_ainfo.shortname = "m";230 arg_ainfo.longname = "maximum number of documents";231 arg_ainfo.multiplechar = true;232 arg_ainfo.defaultstatus = cgiarginfo::weak;233 arg_ainfo.argdefault = "50";234 arg_ainfo.savedarginfo = cgiarginfo::must;235 argsinfo.addarginfo (NULL, arg_ainfo);236 237 // "o"238 arg_ainfo.shortname = "o";239 arg_ainfo.longname = "hits per page";240 arg_ainfo.multiplechar = true;241 arg_ainfo.defaultstatus = cgiarginfo::weak;242 arg_ainfo.argdefault = "20";243 arg_ainfo.savedarginfo = cgiarginfo::must;244 argsinfo.addarginfo (NULL, arg_ainfo);245 246 // "r"247 arg_ainfo.shortname = "r";248 arg_ainfo.longname = "start results from";249 arg_ainfo.multiplechar = true;250 arg_ainfo.defaultstatus = cgiarginfo::weak;251 arg_ainfo.argdefault = "1";252 arg_ainfo.savedarginfo = cgiarginfo::must;253 argsinfo.addarginfo (NULL, arg_ainfo);254 193 255 194 // "ccs" … … 281 220 argsinfo.addarginfo (NULL, arg_ainfo); 282 221 283 // "hd" history display - search history only displayed when284 // this var set to something other than 0285 // this number of records is displayed286 arg_ainfo.shortname = "hd";287 arg_ainfo.longname = "history display";288 arg_ainfo.multiplechar = true;289 arg_ainfo.multiplevalue = false;290 arg_ainfo.defaultstatus = cgiarginfo::weak;291 arg_ainfo.argdefault = "0";292 arg_ainfo.savedarginfo = cgiarginfo::must;293 argsinfo.addarginfo (NULL, arg_ainfo);294 295 // "hs" save - set to 1 in query form, so only save when submit296 // query297 // 0 = no save 1 = save298 arg_ainfo.shortname = "hs";299 arg_ainfo.longname = "history save";300 arg_ainfo.multiplechar = false;301 arg_ainfo.defaultstatus = cgiarginfo::weak;302 arg_ainfo.argdefault = "0";303 arg_ainfo.savedarginfo = cgiarginfo::mustnot;304 argsinfo.addarginfo (NULL, arg_ainfo);305 222 306 223 // "g" - new arg for granularity, for mgpp collections … … 376 293 argsinfo.addarginfo (NULL, arg_ainfo); 377 294 378 // "fqn" - number of fields in the query form379 arg_ainfo.shortname = "fqn";380 arg_ainfo.longname = "form query num fields";381 arg_ainfo.multiplechar = true;382 arg_ainfo.defaultstatus = cgiarginfo::weak;383 arg_ainfo.argdefault = "4";384 arg_ainfo.savedarginfo = cgiarginfo::must;385 argsinfo.addarginfo (NULL, arg_ainfo);386 387 // "fqf" - the list of field names in the form query388 // - a comma separated list389 arg_ainfo.shortname = "fqf";390 arg_ainfo.longname = "form query fields";391 arg_ainfo.multiplechar = true;392 arg_ainfo.defaultstatus = cgiarginfo::weak;393 arg_ainfo.argdefault = g_EmptyText;394 arg_ainfo.savedarginfo = cgiarginfo::must;395 argsinfo.addarginfo (NULL, arg_ainfo);396 397 // "fqv" - the list of values in the form query398 // - a comma separated list399 arg_ainfo.shortname = "fqv";400 arg_ainfo.longname = "form query values";401 arg_ainfo.multiplechar = true;402 arg_ainfo.defaultstatus = cgiarginfo::weak;403 arg_ainfo.argdefault = g_EmptyText;404 arg_ainfo.savedarginfo = cgiarginfo::must;405 argsinfo.addarginfo (NULL, arg_ainfo);406 407 295 408 296 // "fqs" - the list of stemming options in the form query … … 427 315 argsinfo.addarginfo (NULL, arg_ainfo); 428 316 429 // "fqc" - the list of boolean operators in the form query430 // - a comma separated list431 arg_ainfo.shortname = "fqc";432 arg_ainfo.longname = "form query combines";433 arg_ainfo.multiplechar = true;434 arg_ainfo.defaultstatus = cgiarginfo::weak;435 arg_ainfo.argdefault = g_EmptyText;436 arg_ainfo.savedarginfo = cgiarginfo::must;437 argsinfo.addarginfo (NULL, arg_ainfo);438 439 // "fqa" - form query advanced - for "run query"440 arg_ainfo.shortname = "fqa";441 arg_ainfo.longname = "form query advanced query";442 arg_ainfo.multiplechar = false;443 arg_ainfo.defaultstatus = cgiarginfo::weak;444 arg_ainfo.argdefault = "0";445 arg_ainfo.savedarginfo = cgiarginfo::must;446 argsinfo.addarginfo (NULL, arg_ainfo);447 448 // "ifl" - I'm feeling lucky! (Go directly to a matching document)449 arg_ainfo.shortname = "ifl";450 arg_ainfo.longname = "i'm feeling lucky";451 arg_ainfo.multiplechar = false;452 arg_ainfo.defaultstatus = cgiarginfo::weak;453 arg_ainfo.argdefault = g_EmptyText;454 arg_ainfo.savedarginfo = cgiarginfo::mustnot;455 argsinfo.addarginfo (NULL, arg_ainfo);456 457 // "ifln" - I'm feeling lucky number (Go directly to the nth matching document)458 arg_ainfo.shortname = "ifln";459 arg_ainfo.longname = "i'm feeling lucky number";460 arg_ainfo.multiplechar = true;461 arg_ainfo.defaultstatus = cgiarginfo::weak;462 arg_ainfo.argdefault = "1";463 arg_ainfo.savedarginfo = cgiarginfo::mustnot;464 argsinfo.addarginfo (NULL, arg_ainfo);465 466 // "srn" - the next search result467 arg_ainfo.shortname = "srn";468 arg_ainfo.longname = "the next search result number";469 arg_ainfo.multiplechar = true;470 arg_ainfo.defaultstatus = cgiarginfo::weak;471 arg_ainfo.argdefault = "0";472 arg_ainfo.savedarginfo = cgiarginfo::must;473 argsinfo.addarginfo (NULL, arg_ainfo);474 475 // "srp" - the previous search result476 arg_ainfo.shortname = "srp";477 arg_ainfo.longname = "the previous search result number";478 arg_ainfo.multiplechar = true;479 arg_ainfo.defaultstatus = cgiarginfo::weak;480 arg_ainfo.argdefault = "0";481 arg_ainfo.savedarginfo = cgiarginfo::must;482 argsinfo.addarginfo (NULL, arg_ainfo);483 317 484 318 // "sf" - Sort field. Set to field to be used for sorting search reult 485 319 // set (only implemented for lucene collections at present). 486 arg_ainfo.shortname = "s f";487 arg_ainfo.longname = "s ort field";320 arg_ainfo.shortname = "sqlsf"; 321 arg_ainfo.longname = "sql sort field"; 488 322 arg_ainfo.multiplechar = true; 489 323 arg_ainfo.defaultstatus = cgiarginfo::weak; … … 492 326 argsinfo.addarginfo (NULL, arg_ainfo); 493 327 494 // "fuzziness" controls how closely the search terms must match 495 // 100 = exact match, 0 = very inexact match (only implemented for Lucene) 496 arg_ainfo.shortname = "fuzziness"; 497 arg_ainfo.longname = "Lucene fuzziness value"; 498 arg_ainfo.multiplechar = true; 499 arg_ainfo.defaultstatus = cgiarginfo::weak; 500 arg_ainfo.argdefault = g_EmptyText; 501 arg_ainfo.savedarginfo = cgiarginfo::must; 502 argsinfo.addarginfo (NULL, arg_ainfo); 328 329 } 330 331 queryaction::~queryaction () 332 { 503 333 } 504 334 505 335 void queryaction::configure (const text_t &key, const text_tarray &cfgline) { 506 action::configure (key, cfgline);336 basequeryaction::configure (key, cfgline); 507 337 } 508 338 509 339 bool queryaction::init (ostream &logout) { 510 return action::init (logout);340 return basequeryaction::init (logout); 511 341 } 512 342 513 343 bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 514 recptprotolistclass * /*protos*/, ostream &logout) {344 recptprotolistclass* protos, ostream &logout) { 515 345 516 346 // check t argument … … 538 368 } 539 369 540 // check m argument541 int arg_m = args.getintarg("m");542 if (arg_m < -1) {543 logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";544 cgiarginfo *minfo = argsinfo.getarginfo ("m");545 if (minfo != NULL) args["m"] = minfo->argdefault;546 }547 548 // check o argument549 int arg_o = args.getintarg("o");550 if (arg_o < -1) {551 logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";552 cgiarginfo *oinfo = argsinfo.getarginfo ("o");553 if (oinfo != NULL) args["o"] = oinfo->argdefault;554 }555 556 // check r argument557 int arg_r = args.getintarg("r");558 if (arg_r < 1) {559 logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";560 cgiarginfo *rinfo = argsinfo.getarginfo ("r");561 if (rinfo != NULL) args["r"] = rinfo->argdefault;562 }563 //check hd argument564 int arg_hd = args.getintarg("hd");565 if (arg_hd <0 ) {566 logout << "Warning: \"hd\" argument less than 0 (" << arg_hd << ")\n";567 cgiarginfo *hdinfo = argsinfo.getarginfo ("hd");568 if (hdinfo != NULL) args["hd"] = hdinfo->argdefault;569 }570 571 //check hs argument572 int arg_hs = args.getintarg("hs");573 if (arg_hs !=0 && arg_hs !=1) {574 logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n";575 cgiarginfo *hsinfo = argsinfo.getarginfo ("hs");576 if (hsinfo != NULL) args["hs"] = hsinfo->argdefault;577 }578 370 579 371 // check ct argument … … 617 409 } 618 410 619 return true; 620 } 621 622 void queryaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/, 623 response_t &response, text_t &response_data, 624 ostream &/*logout*/) { 625 // If this is an "I'm feeling lucky" request, we don't know the target location until later 626 if (!args["ifl"].empty()) { 627 response = undecided_location; 628 return; 629 } 630 631 response = content; 632 response_data = "text/html"; 411 return basequeryaction::check_cgiargs(argsinfo,args,protos,logout); 412 633 413 } 634 414 635 415 void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 636 416 recptprotolistclass * protos, 637 ostream &logout) { 638 639 // define_internal_macros sets the following macros: 640 641 // The following macros are set later (in define_query_macros) as they can't be set until 642 // the query has been done. 643 // _quotedquery_ the part of the query string that was quoted for post-processing 644 // _freqmsg_ the term frequency string 645 646 // _resultline_ the "x documents matched the query" string 647 648 // _prevfirst_ these are used when setting up the links to previous/next 649 // _prevlast_ pages of results (_thisfirst_ and _thislast_ are used to set 650 // _nextfirst_ the 'results x-x for query: xxxx' string in the title bar) 651 // _nextlast_ 652 // _thisfirst_ 653 // _thislast_ 654 655 656 define_form_macros(disp, args, protos, logout); 657 417 ostream &logout) 418 { 419 basequeryaction::define_internal_macros(disp,args,protos,logout); 420 658 421 define_query_interface(disp, args, protos, logout); 659 660 661 422 } 662 423 … … 693 454 } 694 455 695 696 // sets the selection box macros _hselection_, _jselection_, _nselection_ _gselection_, fqfselection_697 void queryaction::set_option_macro (const text_t ¯oname,698 text_t current_value,699 bool display_single,700 bool add_js_update,701 const FilterOption_t &option,702 displayclass &disp) {703 704 if (option.validValues.empty()) return;705 if (option.validValues.size() == 1) {706 if (display_single) {707 disp.setmacro (macroname + "selection", displayclass::defaultpackage, "_" + option.defaultValue + "_");708 }709 return;710 }711 if (option.validValues.size() < 2) return;712 713 text_t macrovalue = "<select name=\"" + macroname + "\"";714 if (add_js_update) {715 macrovalue += " onChange=\"update"+macroname+"();\"";716 }717 macrovalue += ">\n";718 719 if (current_value.empty()) current_value = option.defaultValue;720 721 text_tarray::const_iterator thisvalue = option.validValues.begin();722 text_tarray::const_iterator endvalue = option.validValues.end();723 724 while (thisvalue != endvalue) {725 macrovalue += "<option value=\"" + *thisvalue + "\"";726 if (*thisvalue == current_value)727 macrovalue += " selected";728 macrovalue += ">_" + *thisvalue + "_\n";729 ++thisvalue;730 }731 macrovalue += "</select>\n";732 disp.setmacro (macroname + "selection", displayclass::defaultpackage, macrovalue);733 }734 456 735 457 … … 832 554 } // define external macros 833 555 556 834 557 void queryaction::set_sfselection_macro(text_t current_value, 835 558 const FilterOption_t &option, … … 924 647 disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue); 925 648 } 649 926 650 void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args, 927 recptprotolistclass *protos, ostream &logout) { 651 recptprotolistclass *protos, 652 ostream &logout) 653 { 928 654 929 655 // defines the following macros … … 952 678 953 679 } 954 955 void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,956 recptprotolistclass *protos, ostream &logout) {957 958 // defines the following macros959 // _searchhistorylist_960 961 text_t historylist;962 int arghd = args.getintarg("hd");963 if (arghd == 0) {964 historylist="";965 }966 else {967 historylist = "<!-- Search History List -->\n";968 969 text_t userid = args["z"];970 text_tarray entries;971 if (get_history_info (userid, entries, dbhome, logout)) {972 int count = 1;973 text_tarray::iterator here = entries.begin();974 text_tarray::iterator end = entries.end();975 int numrecords=(int)entries.size();976 if (numrecords>arghd) { // only display some of them977 numrecords = arghd;978 }979 historylist += "<form action=\"_gwcgi_\" name=\"HistoryForm\"><table width=\"537\">\n";980 981 for (int i=0; i<numrecords;++i) {982 text_t query;983 text_t numdocs;984 text_t cgiargs;985 text_t userinfo;986 text_t escquery;987 split_saved_query(entries[i],numdocs,cgiargs);988 parse_saved_args(cgiargs, "q", query); // get query string out989 decode_cgi_arg(query); // un cgisafe it990 escquery = escape_quotes(query); // escape the quotes and newlines991 text_t histvalue = "histvalue";992 histvalue += i;993 disp.setmacro(histvalue, "query", escquery);994 format_user_info(cgiargs, userinfo, args, protos, logout);995 996 historylist += "<tr><td align=\"right\">_imagehistbutton_(";997 historylist += i;998 historylist += ")</td>\n";999 historylist += "<td><table border=\"1\" cellspacing=\"0\" ";1000 historylist += "cellpadding=\"0\"><tr><td width=\"365\" align=\"left\">"1001 + query1002 + "</td></tr></table></td><td width=\"110\" align=\"center\"><small>"1003 + numdocs;1004 if (numdocs == 1) historylist += " _texthresult_";1005 else historylist += " _texthresults_";1006 if (!userinfo.empty()) {1007 historylist += "<br>( "+userinfo+" )";1008 }1009 historylist += "</small></td>\n";1010 }1011 historylist+="</table></form>\n\n";1012 1013 } // if get history info1014 else {1015 historylist += "_textnohistory_";1016 }1017 historylist += "<! ---- end of history list ----->\n";1018 } // else display list1019 disp.setmacro("searchhistorylist", "query", historylist);1020 1021 } // define history macros1022 680 1023 681 void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos, … … 1153 811 } 1154 812 1155 1156 1157 813 if (args["ccs"] == "1") { 1158 814 if (!args["cc"].empty()) { … … 1177 833 return true; 1178 834 } 835 836 837 838 // request.filterResultOptions and request.fields (if required) should 839 // be set from the calling code 840 void queryaction::set_queryfilter_options (FilterRequest_t &request, 841 const text_t &querystring, 842 cgiargsclass &args) 843 { 844 set_fulltext_queryfilter_options(request,querystring,args); 845 } 846 847 848 849 void queryaction::set_queryfilter_options (FilterRequest_t &request, 850 const text_t &querystring1, 851 const text_t &querystring2, 852 cgiargsclass &args) 853 { 854 set_fulltext_queryfilter_options(request,querystring1,querystring2,args); 855 } 856 857 1179 858 1180 859 bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos, … … 1688 1367 } // args["qt"]=1 1689 1368 else { 1690 logout << "ERROR (query _action::get_formatted_query_string): querytype not defined\n";1369 logout << "ERROR (queryaction::get_formatted_query_string): querytype not defined\n"; 1691 1370 } 1692 1371 } … … 1700 1379 // and search_multiple_coll 1701 1380 void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp, 1702 int numdocs, isapprox isApprox) {1703 1704 // set up _resultline_ macro1705 text_t resline;1706 int maxdocs = args.getintarg("m"); 1381 int numdocs, isapprox isApprox) 1382 { 1383 // The following 'if' statatment is placed here to be keep the semantics 1384 // the same as the version before basequeryaction was introduced 1385 1707 1386 if (num_phrases > 0) isApprox = Exact; 1708 if (maxdocs == -1) maxdocs = numdocs; 1709 else if (numdocs > maxdocs) { 1710 numdocs = maxdocs; 1711 isApprox = MoreThan; 1712 } 1713 1714 if (isApprox == Approximate) resline = "_textapprox_"; 1715 else if (isApprox == MoreThan) resline = "_textmorethan_"; 1716 1717 if (numdocs == 0) resline = "_textnodocs_"; 1718 else if (numdocs == 1) resline += "_text1doc_"; 1719 else resline += text_t(numdocs) + " _textlotsdocs_"; 1720 1721 disp.setmacro("resultline", "query", resline); 1722 1723 int firstdoc = args.getintarg("r"); 1724 int hitsperpage = args.getintarg("o"); 1725 if (hitsperpage == -1) hitsperpage = numdocs; 1726 1727 // set up _thisfirst_ and _thislast_ macros 1728 disp.setmacro ("thisfirst", "query", firstdoc); 1729 int thislast = firstdoc + (hitsperpage - 1); 1730 if (thislast > numdocs) thislast = numdocs; 1731 disp.setmacro ("thislast", "query", thislast); 1732 1733 // set up _prevfirst_ and _prevlast_ macros 1734 if (firstdoc > 1) { 1735 disp.setmacro ("prevlast", "query", firstdoc - 1); 1736 int prevfirst = firstdoc - hitsperpage; 1737 if (prevfirst < 1) prevfirst = 1; 1738 disp.setmacro ("prevfirst", "query", prevfirst); 1739 } 1740 1741 // set up _nextfirst_ and _nextlast_ macros 1742 if (thislast < numdocs) { 1743 disp.setmacro ("nextfirst", "query", thislast + 1); 1744 int nextlast = thislast + hitsperpage; 1745 if (nextlast > numdocs) nextlast = numdocs; 1746 disp.setmacro ("nextlast", "query", nextlast); 1747 } 1748 1749 // do quoted query here cos we may have added quotes during query pre-processing 1387 1388 basequeryaction::define_query_macros(args,disp,numdocs,isApprox); 1389 1750 1390 if (args["ct"]==0) { // mg queries only, not mgpp 1751 1391 // get the quoted bits of the query string and set _quotedquery_ … … 1772 1412 } 1773 1413 1774 // define_single_query_macros sets the extra macros for search_single_coll1775 // that couldn't be set until the query had been done. Those macros are1776 // _freqmsg_ and _stopwordsmsg_1777 void queryaction::define_single_query_macros (cgiargsclass &args,1778 displayclass &disp,1779 const FilterResponse_t &response) {1780 // set up _freqmsg_ and _stopwordsmsg_ macros1781 1782 text_t freqmsg = "";1783 freqmsg = "_textfreqmsg1_";1784 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();1785 TermInfo_tarray::const_iterator end_term = response.termInfo.end();1786 while (this_term != end_term) {1787 freqmsg += (*this_term).term + ": " + (*this_term).freq;1788 if ((this_term + 1) != end_term)1789 freqmsg += ", ";1790 ++this_term;1791 }1792 disp.setmacro ("freqmsg", "query", freqmsg);1793 1794 text_tset::const_iterator this_stopword = response.stopwords.begin();1795 text_tset::const_iterator end_stopword = response.stopwords.end();1796 if (this_stopword != end_stopword) {1797 text_t stopwordsmsg = "_textstopwordsmsg_ ";1798 while (this_stopword != end_stopword) {1799 if (stopwordsmsg != "_textstopwordsmsg_ ") {1800 stopwordsmsg += ", ";1801 }1802 stopwordsmsg += (*this_stopword);1803 ++this_stopword;1804 }1805 disp.setmacro("stopwordsmsg", "query", stopwordsmsg);1806 }1807 }1808 1809 1414 // should this change for cross coll search?? 1810 1415 bool queryaction::save_search_history (cgiargsclass &args, int numdocs, … … 1840 1445 if (set_history_info(userid, query, dbhome, display)) return true; 1841 1446 else return false; 1842 1843 1844 } 1845 1447 } 1448
Note:
See TracChangeset
for help on using the changeset viewer.