Changeset 22046

Show
Ignore:
Timestamp:
06.05.2010 12:55:03 (9 years ago)
Author:
davidb
Message:

Changes necessary to support new sql-query action

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/Makefile.in

    r21485 r22046  
    9393USE_SQLITE = @USE_SQLITE@ 
    9494ifeq ($(USE_SQLITE), 1) 
     95SQLITE_DEFINES = -DUSE_SQLITE 
    9596SQLITE_LIBS = $(COMMON_PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread 
    9697else 
     98SQLITE_DEFINES = 
    9799SQLITE_LIBS =  
    98100endif 
     101 
     102ifeq ($(USE_SQLITE), 1) 
     103SQL_SOURCES = sqlqueryaction.cpp 
     104SQL_OBJECTS = sqlqueryaction.o 
     105else 
     106SQL_SOURCES = 
     107SQL_OBJECTS = 
     108endif 
     109 
    99110 
    100111USE_Z3950 = @USE_Z3950@ 
     
    135146CXX = @CXX@ 
    136147CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@ 
    137 DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(GDBM_DEFINES) $(Z3950_DEFS) 
     148DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(GDBM_DEFINES) $(SQLITE_DEFINES) $(Z3950_DEFS) 
    138149INCLUDES = -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib \ 
    139150        -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) \ 
     
    186197    phindbrowserclass.cpp \ 
    187198    pingaction.cpp \ 
     199    basequeryaction.cpp \ 
    188200    queryaction.cpp \ 
     201    $(SQL_SOURCES) \ 
    189202    querytools.cpp \ 
    190203    receptionist.cpp \ 
     
    231244    phindbrowserclass.o \ 
    232245    pingaction.o \ 
     246    basequeryaction.o \ 
    233247    queryaction.o \ 
     248    $(SQL_OBJECTS) \ 
    234249    querytools.o \ 
    235250    receptionist.o \ 
  • main/trunk/greenstone2/runtime-src/src/recpt/formattools.cpp

    r21808 r22046  
    12651265   
    12661266    ResultDocInfo_t& trav_docinfo = trav_response.docInfo[0]; 
     1267 
    12671268    // use this for rest of routine 
    12681269    docinfo = trav_docinfo; 
     
    12811282    here++; 
    12821283    if (*(oid.begin()) == '"') translate_parent (oid, docinfo.OID); 
    1283      
     1284 
    12841285    //get the information associated with the metadata for child doc 
    12851286    if (!get_info (oid, collection, "", child_metadata,  
     
    12961297    text_t child_metavalue  
    12971298      = get_formatted_meta_text(child_docinfo.OID,metaname_rec,meta,siblings_values); 
     1299 
     1300 
    12981301    if (!first) result += child_field; 
    12991302    first = false; 
    13001303    // 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; 
    13031308  } 
    13041309  return result; 
  • main/trunk/greenstone2/runtime-src/src/recpt/librarymain.cpp

    r21324 r22046  
    4949#include "pingaction.h" 
    5050#include "queryaction.h" 
     51 
     52#if defined(USE_SQLITE) 
     53#include "sqlqueryaction.h" 
     54#endif 
     55 
    5156#include "tipaction.h" 
    5257#include "statusaction.h" 
     
    141146  aqueryaction->set_receptionist (&recpt); 
    142147  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 
    144155  documentaction *adocumentaction = new documentaction(); 
    145156  adocumentaction->set_receptionist (&recpt); 
  • main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp

    r18481 r22046  
    725725    disp.setmacro("numbytes", displayclass::defaultpackage, numbytes); 
    726726 
    727     // set up ct, qt, qto 
     727    // set up ct, qt, qto, sqlqto 
    728728    set_query_type_args(cinfo, args); 
    729729    // set up ks, ss, afs 
  • main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp

    r20601 r22046  
    3838#include <assert.h> 
    3939 
    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 
     41queryaction::queryaction ()  
     42  : basequeryaction() 
     43{ 
    5344  num_phrases = 0; 
    5445 
     46  cgiarginfo arg_ainfo; 
     47 
    5548  // this action uses cgi variable "a" 
    56   cgiarginfo arg_ainfo; 
    5749  arg_ainfo.shortname = "a"; 
    5850  arg_ainfo.longname = "action"; 
     
    136128 
    137129 
    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  
    165130  // "t" - 1 = ranked 0 = boolean 
    166131  arg_ainfo.shortname = "t"; 
     
    226191  argsinfo.addarginfo (NULL, arg_ainfo); 
    227192  
    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); 
    254193 
    255194  // "ccs" 
     
    281220  argsinfo.addarginfo (NULL, arg_ainfo); 
    282221 
    283   // "hd" history display  - search history only displayed when 
    284   // this var set to something other than 0 
    285   // this number of records is displayed 
    286   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 submit 
    296   // query 
    297   // 0 = no save 1 = save 
    298   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); 
    305222 
    306223  // "g" - new arg for granularity, for mgpp collections 
     
    376293  argsinfo.addarginfo (NULL, arg_ainfo); 
    377294 
    378   // "fqn" - number of fields in the query form 
    379   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 query 
    388   // - a comma separated list 
    389   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 query 
    398   // - a comma separated list 
    399   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    
    407295 
    408296  // "fqs" - the list of stemming options in the form query 
     
    427315  argsinfo.addarginfo (NULL, arg_ainfo); 
    428316   
    429   // "fqc" - the list of boolean operators in the form query 
    430   // - a comma separated list 
    431   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 result 
    467   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 result 
    476   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); 
    483317 
    484318  // "sf" - Sort field. Set to field to be used for sorting search reult 
    485319  // set (only implemented for lucene collections at present). 
    486   arg_ainfo.shortname = "sf"; 
    487   arg_ainfo.longname = "sort field"; 
     320  arg_ainfo.shortname = "sqlsf"; 
     321  arg_ainfo.longname = "sql sort field"; 
    488322  arg_ainfo.multiplechar = true; 
    489323  arg_ainfo.defaultstatus = cgiarginfo::weak; 
     
    492326  argsinfo.addarginfo (NULL, arg_ainfo); 
    493327 
    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 
     331queryaction::~queryaction ()  
     332{ 
    503333} 
    504334 
    505335void queryaction::configure (const text_t &key, const text_tarray &cfgline) { 
    506   action::configure (key, cfgline); 
     336  basequeryaction::configure (key, cfgline); 
    507337} 
    508338 
    509339bool queryaction::init (ostream &logout) { 
    510   return action::init (logout); 
     340  return basequeryaction::init (logout); 
    511341} 
    512342 
    513343bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,  
    514                  recptprotolistclass * /*protos*/, ostream &logout) { 
     344                 recptprotolistclass* protos, ostream &logout) { 
    515345 
    516346  // check t argument 
     
    538368  } 
    539369 
    540   // check m argument 
    541   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 argument 
    549   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 argument 
    557   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 argument 
    564   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 argument 
    572   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   } 
    578370 
    579371  // check ct argument 
     
    617409  } 
    618410 
    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 
    633413} 
    634414 
    635415void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args,  
    636416                      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 
    658421  define_query_interface(disp, args, protos, logout); 
    659  
    660  
    661422} 
    662423 
     
    693454} 
    694455 
    695  
    696 // sets the selection box macros _hselection_, _jselection_, _nselection_ _gselection_, fqfselection_  
    697 void queryaction::set_option_macro (const text_t &macroname,  
    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 } 
    734456 
    735457 
     
    832554} // define external macros 
    833555   
     556 
    834557void queryaction::set_sfselection_macro(text_t current_value,  
    835558                       const FilterOption_t &option,  
     
    924647  disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue); 
    925648} 
     649 
    926650void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args,  
    927                recptprotolistclass *protos, ostream &logout) { 
     651                      recptprotolistclass *protos,  
     652                      ostream &logout)  
     653{ 
    928654 
    929655  // defines the following macros 
     
    952678   
    953679} 
    954  
    955 void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,  
    956                      recptprotolistclass *protos, ostream &logout) { 
    957  
    958   // defines the following macros 
    959   // _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 them  
    977     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 out 
    989     decode_cgi_arg(query); // un cgisafe it 
    990     escquery = escape_quotes(query); // escape the quotes and newlines 
    991     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       + query  
    1002       + "</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 info  
    1014     else { 
    1015       historylist += "_textnohistory_"; 
    1016     } 
    1017     historylist += "<! ---- end of history list ----->\n"; 
    1018   } // else display list 
    1019   disp.setmacro("searchhistorylist", "query", historylist); 
    1020    
    1021 } // define history macros 
    1022680 
    1023681void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos, 
     
    1153811  } 
    1154812 
    1155  
    1156  
    1157813  if (args["ccs"] == "1") { 
    1158814    if (!args["cc"].empty()) { 
     
    1177833  return true; 
    1178834} 
     835 
     836 
     837 
     838// request.filterResultOptions and request.fields (if required) should 
     839// be set from the calling code 
     840void 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 
     849void 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 
    1179858 
    1180859bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos, 
     
    16881367  } // args["qt"]=1 
    16891368  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"; 
    16911370  } 
    16921371} 
     
    17001379// and search_multiple_coll 
    17011380void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp, 
    1702                        int numdocs, isapprox isApprox) { 
    1703    
    1704   // set up _resultline_ macro 
    1705   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 
    17071386  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 
    17501390  if (args["ct"]==0) { // mg queries only, not mgpp 
    17511391    // get the quoted bits of the query string and set _quotedquery_ 
     
    17721412} 
    17731413 
    1774 // define_single_query_macros sets the extra macros for search_single_coll  
    1775 // that couldn't be set until the query had been done. Those macros are  
    1776 // _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_ macros 
    1781  
    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  
    18091414// should this change for cross coll search?? 
    18101415bool queryaction::save_search_history (cgiargsclass &args, int numdocs,  
     
    18401445  if (set_history_info(userid, query, dbhome, display)) return true; 
    18411446  else return false; 
    1842  
    1843  
    1844 } 
    1845  
     1447} 
     1448 
  • main/trunk/greenstone2/runtime-src/src/recpt/queryaction.h

    r12785 r22046  
    2929 
    3030#include "gsdlconf.h" 
    31 #include "action.h" 
     31#include "basequeryaction.h" 
    3232#include "receptionist.h" 
    3333 
    34 struct colinfo_t { 
    35   void clear(); 
    36   colinfo_t () {clear();} 
    3734 
    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 { 
     35class queryaction : public basequeryaction { 
    6036 
    6137protected: 
    62  
    63   receptionist *recpt; 
    64  
    6538  text_t m_strUseInterfaceLanguageForQuery; 
    6639  text_t formatstring; 
     
    6841  int num_phrases; 
    6942 
    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,  
    7151                       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); 
    7553 
    76   void get_formatted_query_string (text_t &formattedstring, bool segment,  
    77                    cgiargsclass &args,  
    78                    displayclass &disp, ostream &logout); 
    7954  void define_query_interface(displayclass &disp, cgiargsclass &args,  
    8055                  recptprotolistclass *protos, ostream &logout); 
    8156   
    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 &macroname, 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); 
    9160 
    9261  void set_gformselection_macro (text_t current_value, 
     
    10069           displayclass &disp, outconvertclass &outconvert, 
    10170           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 
    10282   
    10383  bool search_multiple_collections (cgiargsclass &args,  
     
    11898 
    11999 
    120   bool save_search_history(cgiargsclass &args, int numdocs, isapprox isApprox); 
     100  virtual bool save_search_history(cgiargsclass &args, int numdocs,  
     101                   isapprox isApprox); 
    121102 
    122103public: 
    123104  queryaction (); 
    124   virtual ~queryaction () {} 
     105  virtual ~queryaction (); 
    125106 
    126   void set_receptionist (receptionist *therecpt) {recpt=therecpt;} 
    127    
    128107  void configure (const text_t &key, const text_tarray &cfgline); 
    129108  bool init (ostream &logout); 
     
    134113                  recptprotolistclass *protos, ostream &logout); 
    135114 
    136   void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos, 
    137              response_t &response, text_t &response_data,  
    138              ostream &logout); 
    139    
    140115  virtual void define_internal_macros (displayclass &disp, cgiargsclass &args,  
    141116                   recptprotolistclass *protos, ostream &logout); 
  • main/trunk/greenstone2/runtime-src/src/recpt/querytools.cpp

    r20602 r22046  
    8282    args.setintarg("qto", type); 
    8383  }  
    84    
     84 
    8585  if (args["qt"].empty()) { 
    8686    int arg_qto = args.getintarg("qto"); 
     
    9191    } 
    9292  } 
     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 
    93112} 
    94113 
     
    109128} 
    110129 
     130 
     131 
     132void 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 
    111155// request.filterResultOptions and request.fields (if required) should 
    112156// be set from the calling code 
    113 void set_queryfilter_options (FilterRequest_t &request,  
    114                   const text_t &querystring, 
    115                   cgiargsclass &args) { 
     157void 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 
    116164 
    117165  request.filterName = "QueryFilter"; 
     
    190238  } 
    191239 
    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 
     245void 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); 
    200252 
    201253  // fill in the second query if needed 
     
    245297    } 
    246298  } 
    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 
     310void 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 
    270324 
    271325bool is_special_character(int indexer_type, unsigned short character) { 
     
    551605    if (!values[i].empty()) { 
    552606      text_t this_value = values[i]; 
     607 
    553608      // remove operators for simple search, segments text if necessary 
    554609      format_querystring(this_value, argb, segment);  
     610            
    555611      // add tag info for this field (and other processing) 
    556612      format_field_info(this_value, fields[i], argct, argt, argb); 
     613 
    557614      // add into query string 
    558615      if (argct == 2) { 
     
    644701  } 
    645702} 
     703 
     704 
     705// SQL versions for parsing query form 
     706 
     707void 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 
     770void 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 
    646847 
    647848// Extended addqueryelem for Human Info project 
     
    738939    querystring = tag+":("+querystring+")"; 
    739940  } 
     941     
     942} 
     943 
     944 
     945void 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 + "))"; 
    7401032     
    7411033} 
     
    9011193    finalquery.push_back(' ');  
    9021194  } 
    903  
     1195  
    9041196  querystring  = finalquery; 
     1197} 
     1198 
     1199 
     1200void 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); 
    9051205} 
    9061206 
  • main/trunk/greenstone2/runtime-src/src/recpt/querytools.h

    r20602 r22046  
    3434void set_stem_index_args(ColInfoResponse_t *cinfo, cgiargsclass &args); 
    3535 
    36 void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring, 
    37                   cgiargsclass &args); 
     36void set_basequeryfilter_options (FilterRequest_t &request,  
     37                  cgiargsclass &args); 
    3838 
    39 void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring1, 
    40                   const text_t &querystring2, cgiargsclass &args); 
     39void set_fulltext_queryfilter_options (FilterRequest_t &request,  
     40                       const text_t &querystring, 
     41                       cgiargsclass &args); 
     42 
     43void set_fulltext_queryfilter_options (FilterRequest_t &request,  
     44                       const text_t &querystring1, 
     45                       const text_t &querystring2,  
     46                       cgiargsclass &args); 
     47 
     48void set_sql_queryfilter_options (FilterRequest_t &request,  
     49                  cgiargsclass &args); 
     50 
    4151 
    4252// don't hassle the function name ... it's been a long day ;) 
     
    5868void parse_adv_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 
    5969 
     70// similar, but for SQL 
     71void parse_sqlreg_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 
     72void parse_sqladv_query_form(text_t &formattedstring, cgiargsclass &args, bool segment); 
     73 
    6074// Added for Human Info project 
    6175void addqueryelem_ex(text_t &querystring, const text_t &tag,  
     
    6478             const text_t& combine, const text_t& word_combine); 
    6579 
     80void format_field_info_sql(text_t &querystring, const text_t& tagseq,  
     81               const text_t& sqlcomb, int argt, int argb); 
     82 
    6683void format_field_info(text_t &querystring, text_t tag, int argct, int argt, int argb); 
    6784