Changeset 22046
- Timestamp:
- 2010-05-06T12:55:03+12:00 (14 years ago)
- Location:
- main/trunk/greenstone2/runtime-src/src/recpt
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/recpt/Makefile.in
r21485 r22046 93 93 USE_SQLITE = @USE_SQLITE@ 94 94 ifeq ($(USE_SQLITE), 1) 95 SQLITE_DEFINES = -DUSE_SQLITE 95 96 SQLITE_LIBS = $(COMMON_PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread 96 97 else 98 SQLITE_DEFINES = 97 99 SQLITE_LIBS = 98 100 endif 101 102 ifeq ($(USE_SQLITE), 1) 103 SQL_SOURCES = sqlqueryaction.cpp 104 SQL_OBJECTS = sqlqueryaction.o 105 else 106 SQL_SOURCES = 107 SQL_OBJECTS = 108 endif 109 99 110 100 111 USE_Z3950 = @USE_Z3950@ … … 135 146 CXX = @CXX@ 136 147 CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@ 137 DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(GDBM_DEFINES) $( Z3950_DEFS)148 DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(GDBM_DEFINES) $(SQLITE_DEFINES) $(Z3950_DEFS) 138 149 INCLUDES = -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib \ 139 150 -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) \ … … 186 197 phindbrowserclass.cpp \ 187 198 pingaction.cpp \ 199 basequeryaction.cpp \ 188 200 queryaction.cpp \ 201 $(SQL_SOURCES) \ 189 202 querytools.cpp \ 190 203 receptionist.cpp \ … … 231 244 phindbrowserclass.o \ 232 245 pingaction.o \ 246 basequeryaction.o \ 233 247 queryaction.o \ 248 $(SQL_OBJECTS) \ 234 249 querytools.o \ 235 250 receptionist.o \ -
main/trunk/greenstone2/runtime-src/src/recpt/formattools.cpp
r21808 r22046 1265 1265 1266 1266 ResultDocInfo_t& trav_docinfo = trav_response.docInfo[0]; 1267 1267 1268 // use this for rest of routine 1268 1269 docinfo = trav_docinfo; … … 1281 1282 here++; 1282 1283 if (*(oid.begin()) == '"') translate_parent (oid, docinfo.OID); 1283 1284 1284 1285 //get the information associated with the metadata for child doc 1285 1286 if (!get_info (oid, collection, "", child_metadata, … … 1296 1297 text_t child_metavalue 1297 1298 = get_formatted_meta_text(child_docinfo.OID,metaname_rec,meta,siblings_values); 1299 1300 1298 1301 if (!first) result += child_field; 1299 1302 first = false; 1300 1303 // need to do this here cos otherwise we are in the wrong document 1301 result += expand_metadata(child_metavalue,collection,collectproto, 1302 child_docinfo,disp,options,logout); 1304 text_t em = expand_metadata(child_metavalue,collection,collectproto, 1305 child_docinfo,disp,options,logout); 1306 1307 result += em; 1303 1308 } 1304 1309 return result; -
main/trunk/greenstone2/runtime-src/src/recpt/librarymain.cpp
r21324 r22046 49 49 #include "pingaction.h" 50 50 #include "queryaction.h" 51 52 #if defined(USE_SQLITE) 53 #include "sqlqueryaction.h" 54 #endif 55 51 56 #include "tipaction.h" 52 57 #include "statusaction.h" … … 141 146 aqueryaction->set_receptionist (&recpt); 142 147 recpt.add_action (aqueryaction); 143 148 149 #if defined(USE_SQLITE) 150 sqlqueryaction *asqlqueryaction = new sqlqueryaction(); 151 asqlqueryaction->set_receptionist (&recpt); 152 recpt.add_action (asqlqueryaction); 153 #endif 154 144 155 documentaction *adocumentaction = new documentaction(); 145 156 adocumentaction->set_receptionist (&recpt); -
main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp
r18481 r22046 725 725 disp.setmacro("numbytes", displayclass::defaultpackage, numbytes); 726 726 727 // set up ct, qt, qto 727 // set up ct, qt, qto, sqlqto 728 728 set_query_type_args(cinfo, args); 729 729 // set up ks, ss, afs -
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 -
main/trunk/greenstone2/runtime-src/src/recpt/queryaction.h
r12785 r22046 29 29 30 30 #include "gsdlconf.h" 31 #include " action.h"31 #include "basequeryaction.h" 32 32 #include "receptionist.h" 33 33 34 struct colinfo_t {35 void clear();36 colinfo_t () {clear();}37 34 38 format_t *formatlistptr; 39 browserclass *browserptr; 40 }; 41 42 struct QueryResult_t { 43 void clear (); 44 QueryResult_t () {clear();} 45 46 ResultDocInfo_t doc; 47 text_t collection; 48 }; 49 50 struct gteqQueryResult_t 51 { 52 bool operator()(const QueryResult_t &t1, const QueryResult_t &t2) const 53 { return t1.doc.ranking >= t2.doc.ranking; } 54 }; 55 56 typedef set<QueryResult_t, gteqQueryResult_t> QueryResult_tset; 57 58 59 class queryaction : public action { 35 class queryaction : public basequeryaction { 60 36 61 37 protected: 62 63 receptionist *recpt;64 65 38 text_t m_strUseInterfaceLanguageForQuery; 66 39 text_t formatstring; … … 68 41 int num_phrases; 69 42 70 virtual void define_single_query_macros (cgiargsclass &args, 43 virtual text_t query_filter_name () {return "QueryFilter";} 44 45 virtual void define_query_macros (cgiargsclass &args, displayclass &disp, 46 int numDocs, isapprox isApprox); 47 48 virtual void get_formatted_query_string (text_t &formattedstring, 49 bool segment, 50 cgiargsclass &args, 71 51 displayclass &disp, 72 const FilterResponse_t &response); 73 virtual void define_query_macros (cgiargsclass &args, displayclass &disp, 74 int numDocs, isapprox isApprox); 52 ostream &logout); 75 53 76 void get_formatted_query_string (text_t &formattedstring, bool segment,77 cgiargsclass &args,78 displayclass &disp, ostream &logout);79 54 void define_query_interface(displayclass &disp, cgiargsclass &args, 80 55 recptprotolistclass *protos, ostream &logout); 81 56 82 void define_form_macros (displayclass &disp, cgiargsclass &args, 83 recptprotolistclass *protos, ostream &logout); 84 85 void define_history_macros (displayclass &disp, cgiargsclass &args, 86 recptprotolistclass *protos, ostream &logout); 87 88 virtual void set_option_macro (const text_t ¯oname, text_t current_value, 89 bool display_single, bool add_js_update, 90 const FilterOption_t &option, displayclass &disp); 57 virtual void define_form_macros (displayclass &disp, cgiargsclass &args, 58 recptprotolistclass *protos, 59 ostream &logout); 91 60 92 61 void set_gformselection_macro (text_t current_value, … … 100 69 displayclass &disp, outconvertclass &outconvert, 101 70 ostream &textout, ostream &logout); 71 72 virtual void set_queryfilter_options (FilterRequest_t &request, 73 const text_t &querystring, 74 cgiargsclass &args); 75 76 virtual void set_queryfilter_options (FilterRequest_t &request, 77 const text_t &querystring1, 78 const text_t &querystring2, 79 cgiargsclass &args); 80 81 102 82 103 83 bool search_multiple_collections (cgiargsclass &args, … … 118 98 119 99 120 bool save_search_history(cgiargsclass &args, int numdocs, isapprox isApprox); 100 virtual bool save_search_history(cgiargsclass &args, int numdocs, 101 isapprox isApprox); 121 102 122 103 public: 123 104 queryaction (); 124 virtual ~queryaction () {}105 virtual ~queryaction (); 125 106 126 void set_receptionist (receptionist *therecpt) {recpt=therecpt;}127 128 107 void configure (const text_t &key, const text_tarray &cfgline); 129 108 bool init (ostream &logout); … … 134 113 recptprotolistclass *protos, ostream &logout); 135 114 136 void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,137 response_t &response, text_t &response_data,138 ostream &logout);139 140 115 virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 141 116 recptprotolistclass *protos, ostream &logout); -
main/trunk/greenstone2/runtime-src/src/recpt/querytools.cpp
r20602 r22046 82 82 args.setintarg("qto", type); 83 83 } 84 84 85 85 if (args["qt"].empty()) { 86 86 int arg_qto = args.getintarg("qto"); … … 91 91 } 92 92 } 93 94 95 // decide if sqlqto should be set or not 96 unsigned int sql_type = 0; 97 text_t infodb_type = cinfo->infodbType; 98 if ((infodb_type == "sqlite") || (infodb_type == "mssql")) { 99 if (findword(search_types.begin(), search_types.end(), "sqlform") != search_types.end()) { 100 sql_type = 1; 101 } 102 } 103 104 if (sql_type) { 105 args["sqlqto"] = "1"; 106 } 107 else { 108 args["sqlqto"] = "0"; 109 } 110 111 93 112 } 94 113 … … 109 128 } 110 129 130 131 132 void set_basequeryfilter_options (FilterRequest_t &request, 133 cgiargsclass &args) 134 { 135 136 OptionValue_t option; 137 int arg_m = args.getintarg("m"); 138 139 option.name = "Maxdocs"; 140 option.value = arg_m; 141 request.filterOptions.push_back (option); 142 143 // option.name = "StartResults"; 144 // option.value = args["r"]; 145 // request.filterOptions.push_back (option); 146 147 // option.name = "EndResults"; 148 // int endresults = args.getintarg("o") + (args.getintarg("r") - 1); 149 // if ((endresults > arg_m) && (arg_m != -1)) endresults = arg_m; 150 // option.value = endresults; 151 // request.filterOptions.push_back (option); 152 } 153 154 111 155 // request.filterResultOptions and request.fields (if required) should 112 156 // be set from the calling code 113 void set_queryfilter_options (FilterRequest_t &request, 114 const text_t &querystring, 115 cgiargsclass &args) { 157 void set_fulltext_queryfilter_options (FilterRequest_t &request, 158 const text_t &querystring, 159 cgiargsclass &args) 160 { 161 // better if this function, and the two-query companion function 162 // was implemented in queryaction.cpp 163 // Has to be done here to documentaction.cpp can call it directly 116 164 117 165 request.filterName = "QueryFilter"; … … 190 238 } 191 239 192 set_more_queryfilter_options (request, args); 193 } 194 195 void set_queryfilter_options (FilterRequest_t &request, 196 const text_t &querystring1, 197 const text_t &querystring2, cgiargsclass &args) { 198 199 set_queryfilter_options (request, querystring1, args); 240 set_basequeryfilter_options(request, args); 241 } 242 243 244 245 void set_fulltext_queryfilter_options (FilterRequest_t &request, 246 const text_t &querystring1, 247 const text_t &querystring2, 248 cgiargsclass &args) 249 { 250 251 set_fulltext_queryfilter_options (request, querystring1, args); 200 252 201 253 // fill in the second query if needed … … 245 297 } 246 298 } 247 set_more_queryfilter_options (request, args); 248 } 249 250 void set_more_queryfilter_options (FilterRequest_t &request, 251 cgiargsclass &args) { 252 253 OptionValue_t option; 254 int arg_m = args.getintarg("m"); 255 256 option.name = "Maxdocs"; 257 option.value = arg_m; 258 request.filterOptions.push_back (option); 259 260 // option.name = "StartResults"; 261 // option.value = args["r"]; 262 // request.filterOptions.push_back (option); 263 264 // option.name = "EndResults"; 265 // int endresults = args.getintarg("o") + (args.getintarg("r") - 1); 266 // if ((endresults > arg_m) && (arg_m != -1)) endresults = arg_m; 267 // option.value = endresults; 268 // request.filterOptions.push_back (option); 269 } 299 300 // this is probably redundant, as first line to this method will have 301 // already caused it to invoke set_basequeryfilter_options 302 303 set_basequeryfilter_options(request, args); 304 } 305 306 307 308 // request.filterResultOptions and request.fields (if required) should 309 // be set from the calling code 310 void set_sql_queryfilter_options (FilterRequest_t &request, 311 cgiargsclass &args) 312 { 313 if (!args["sqlsf"].empty()) { // sort field for lucene 314 OptionValue_t option; 315 316 option.name = "SortField"; 317 option.value = args["sqlsf"]; 318 request.filterOptions.push_back (option); 319 } 320 321 set_basequeryfilter_options(request, args); 322 } 323 270 324 271 325 bool is_special_character(int indexer_type, unsigned short character) { … … 551 605 if (!values[i].empty()) { 552 606 text_t this_value = values[i]; 607 553 608 // remove operators for simple search, segments text if necessary 554 609 format_querystring(this_value, argb, segment); 610 555 611 // add tag info for this field (and other processing) 556 612 format_field_info(this_value, fields[i], argct, argt, argb); 613 557 614 // add into query string 558 615 if (argct == 2) { … … 644 701 } 645 702 } 703 704 705 // SQL versions for parsing query form 706 707 void parse_sqlreg_query_form(text_t &querystring, cgiargsclass &args, bool segment) 708 { 709 querystring.clear(); 710 711 int argt = args.getintarg("t");// t=0 -and, t=1 - or 712 int argb = args.getintarg("b"); 713 714 text_t combine; 715 716 if (argt == 0) combine = "AND"; 717 else combine = "OR"; 718 719 text_t field = args["sqlfqf"]; 720 if (field.empty()) return; // no query 721 text_tarray fields; 722 splitchar(field.begin(), field.end(), ',', fields); 723 724 text_t sqlcomb = args["sqlfqc"]; 725 if (sqlcomb.empty()) return; //somethings wrong 726 text_tarray sqlcombs; 727 splitchar(sqlcomb.begin(), sqlcomb.end(), ',', sqlcombs); 728 729 text_t value = args["fqv"]; 730 if (value.empty()) return; // somethings wrong 731 text_tarray values; 732 splitchar(value.begin(), value.end(), ',', values); 733 734 735 for (int i=0; i< values.size(); ++i) { 736 if (!values[i].empty()) { 737 text_t this_value = values[i]; 738 739 // remove operators for simple search, segments text if necessary 740 format_querystring(this_value, argb, segment); 741 742 // add tag info for this field (and other processing) 743 format_field_info_sql(this_value, fields[i], sqlcombs[i], argt, argb); 744 745 const text_t DISTINCT_SELECT_WHERE 746 = "SELECT DISTINCT docOID FROM document_metadata WHERE "; 747 748 if (querystring.empty()) { 749 // first query term 750 querystring = DISTINCT_SELECT_WHERE + this_value; 751 } 752 else { 753 this_value = DISTINCT_SELECT_WHERE + this_value; 754 755 if (combine=="AND") { 756 // INNER JOIN to restrict to only matching docOIDs 757 querystring = "SELECT docOID FROM (" + querystring + ")" 758 + " INNER JOIN (" + this_value +") USING (docOID)"; 759 } 760 else if (combine=="OR") { 761 // Union to allow union of the two 762 querystring = querystring + " UNION " + this_value; 763 } 764 } 765 } 766 } 767 } 768 769 770 void parse_sqladv_query_form(text_t &querystring, cgiargsclass &args, 771 bool segment) 772 { 773 querystring.clear(); 774 775 int argt = 0; // set it to 0 = AND, by default 776 int argb = args.getintarg("b"); 777 text_t combine = "AND"; 778 779 text_t field = args["sqlfqf"]; 780 781 if (field.empty()) return; // no query 782 text_tarray fields; 783 splitchar(field.begin(), field.end(), ',', fields); 784 785 text_t sqlcomb = args["sqlfqc"]; 786 if (sqlcomb.empty()) return; //somethings wrong 787 text_tarray sqlcombs; 788 splitchar(sqlcomb.begin(), sqlcomb.end(), ',', sqlcombs); 789 790 text_t value = args["fqv"]; 791 if (value.empty()) return; // somethings wrong 792 text_tarray values; 793 splitchar(value.begin(), value.end(), ',', values); 794 795 text_t comb = args["fqc"]; 796 if (comb.empty()) return; //somethings wrong 797 text_tarray combs; 798 splitchar(comb.begin(), comb.end(), ',', combs); 799 800 for(int i=0; i< values.size(); ++i) { 801 if (!values[i].empty()) { 802 if (i>0) { 803 if (combs[i-1]=="and") { combine = "AND"; } 804 else if (combs[i-1]=="or") { combine = "OR"; } 805 else if (combs[i-1]=="not") { combine = "NOT"; } 806 } 807 text_t this_value = values[i]; 808 809 // remove operators for simple search, segments text if necessary 810 format_querystring(this_value, argb, segment); 811 812 // add tag info for this field (and other processing) 813 format_field_info_sql(this_value, fields[i], sqlcombs[i], argt, argb); 814 815 // add into query string 816 817 const text_t DISTINCT_SELECT_WHERE 818 = "SELECT DISTINCT docOID FROM document_metadata WHERE "; 819 820 if (querystring.empty()) { 821 // first query term 822 querystring = DISTINCT_SELECT_WHERE + this_value; 823 } 824 else { 825 this_value = DISTINCT_SELECT_WHERE + this_value; 826 827 if (combine=="AND") { 828 // INNER JOIN to restrict to only matching docOIDs 829 querystring = "SELECT docOID FROM (" + querystring + ")" 830 + " INNER JOIN (" + this_value +") USING (docOID)"; 831 } 832 else if (combine=="OR") { 833 // Union to allow union of the two 834 querystring = querystring + " UNION " + this_value; 835 } 836 else { 837 cerr << "Unsupported combination operation: " << combine << endl; 838 } 839 } 840 841 } 842 } 843 } 844 845 846 646 847 647 848 // Extended addqueryelem for Human Info project … … 738 939 querystring = tag+":("+querystring+")"; 739 940 } 941 942 } 943 944 945 void add_field_info_sql(text_t &querystring, const text_t &tagseq, 946 const text_t& sqlcomb) 947 { 948 949 if (tagseq == "") return; // do nothing 950 951 text_t element_in = "(element IN ("; 952 953 text_tlist mdterms; 954 955 splitword(tagseq.begin(), tagseq.end(), "/", mdterms); 956 957 text_t tags_in = ""; 958 959 while (!mdterms.empty()) { 960 text_t tag = mdterms.front(); 961 mdterms.pop_front(); 962 963 if (!tag.empty()) { 964 965 if (tag.size()>3 && (substr(tag.begin(), tag.begin()+3) == "ex.")) { 966 tag = substr (tag.begin()+3, tag.end()); 967 } 968 969 if (!tags_in.empty()) { 970 tags_in += ","; 971 } 972 973 tags_in += "'" + tag + "'"; 974 } 975 } 976 977 element_in += tags_in + ") AND ("; 978 979 if (sqlcomb == "=") { 980 // override what it means to do equality, to make it more like full text 981 // searching 982 983 text_t orterms = ""; 984 text_t term = ""; 985 bool in_phrase = false; 986 987 text_t::const_iterator here = querystring.begin(); 988 text_t::const_iterator end = querystring.end(); 989 while (here != end) { 990 if (is_unicode_letdig(*here)) { 991 term.push_back(*here); 992 } 993 else if (*here == '"') { 994 term.push_back(*here); 995 if (!in_phrase) { 996 in_phrase = true; 997 } else { 998 in_phrase = false; 999 } 1000 } 1001 else if (in_phrase) { 1002 // Found word boundary, but in a phrase, so does not complete term 1003 term.push_back(*here); 1004 } 1005 else { 1006 // Found a word boundary 1007 if (!orterms.empty()) { 1008 orterms += " OR "; 1009 } 1010 orterms += "value LIKE '%" + term + "%'"; 1011 term.clear(); 1012 } 1013 ++here; 1014 } 1015 1016 if (!term.empty()) { 1017 if (!orterms.empty()) { 1018 orterms += " OR "; 1019 } 1020 orterms += "value LIKE '%" + term + "%'"; 1021 } 1022 1023 element_in += orterms; 1024 } 1025 else { 1026 // search on value is "as is" querystring 1027 element_in += "value " + sqlcomb + " '" + querystring+"'"; 1028 } 1029 1030 1031 querystring = element_in + "))"; 740 1032 741 1033 } … … 901 1193 finalquery.push_back(' '); 902 1194 } 903 1195 904 1196 querystring = finalquery; 1197 } 1198 1199 1200 void format_field_info_sql(text_t &querystring, const text_t &tagseq, 1201 const text_t &sqlcomb, 1202 int argt, int argb) 1203 { 1204 add_field_info_sql(querystring, tagseq, sqlcomb); 905 1205 } 906 1206 -
main/trunk/greenstone2/runtime-src/src/recpt/querytools.h
r20602 r22046 34 34 void set_stem_index_args(ColInfoResponse_t *cinfo, cgiargsclass &args); 35 35 36 void set_ queryfilter_options (FilterRequest_t &request, const text_t &querystring,37 36 void set_basequeryfilter_options (FilterRequest_t &request, 37 cgiargsclass &args); 38 38 39 void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring1, 40 const text_t &querystring2, cgiargsclass &args); 39 void set_fulltext_queryfilter_options (FilterRequest_t &request, 40 const text_t &querystring, 41 cgiargsclass &args); 42 43 void set_fulltext_queryfilter_options (FilterRequest_t &request, 44 const text_t &querystring1, 45 const text_t &querystring2, 46 cgiargsclass &args); 47 48 void set_sql_queryfilter_options (FilterRequest_t &request, 49 cgiargsclass &args); 50 41 51 42 52 // don't hassle the function name ... it's been a long day ;) … … 58 68 void parse_adv_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 59 69 70 // similar, but for SQL 71 void parse_sqlreg_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 72 void parse_sqladv_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 73 60 74 // Added for Human Info project 61 75 void addqueryelem_ex(text_t &querystring, const text_t &tag, … … 64 78 const text_t& combine, const text_t& word_combine); 65 79 80 void format_field_info_sql(text_t &querystring, const text_t& tagseq, 81 const text_t& sqlcomb, int argt, int argb); 82 66 83 void format_field_info(text_t &querystring, text_t tag, int argct, int argt, int argb); 67 84
Note:
See TracChangeset
for help on using the changeset viewer.