Changeset 4200


Ignore:
Timestamp:
2003-04-30T14:41:06+12:00 (21 years ago)
Author:
kjdon
Message:

added form search capability to cross coll search, put the query format stuff for form queries into a new method so search_single and search_multiple can both use it, search_mulitple now uses define_query_macros, but this is simplified to only do the ones that are the same for both single and multi search. search history now provided for search multi colls - it needs some thought into what to display cos now there is more than one coll.

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/queryaction.cpp

    r4194 r4200  
    10611061  FilterResponse_t response;
    10621062  request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
    1063   text_t formattedstring = args["q"];
    10641063  text_t freqmsg = "_textfreqmsg1_";
    10651064  int numdocs = 0;
    10661065  isapprox isApprox = Exact;
    10671066
    1068   format_querystring (formattedstring, args.getintarg("b"));
     1067  text_t formattedstring = "";
     1068  get_formatted_query_string(formattedstring, args, disp, logout);
     1069
     1070  if (formattedstring.empty()) {
     1071    // dont bother doing a query if no query string
     1072    define_history_macros (disp, args, protos, logout);
     1073    textout << outconvert << disp << "_query:header_\n"
     1074      << "_query:content_";
     1075    textout << outconvert << disp << "_query:footer_";
     1076
     1077    return true;
     1078  }
     1079
    10691080  set_queryfilter_options (request, formattedstring, args);
    10701081
     
    11621173    }
    11631174    col_here ++;
    1164   }
     1175  } // for each coll
    11651176
    11661177  disp.setmacro ("freqmsg", "query", freqmsg);
    11671178
    1168   int maxdocs = args.getintarg("m");
    1169   int firstdoc = args.getintarg("r");
    1170   int hitsperpage = args.getintarg("o");
    1171   if (num_phrases > 0) isApprox = Exact;
    1172   if (maxdocs == -1) maxdocs = numdocs;
    1173   else if (numdocs > maxdocs) {
    1174     numdocs = maxdocs;
    1175     isApprox = MoreThan;
    1176   }
    1177   if (hitsperpage == -1) hitsperpage = numdocs;
    1178 
    1179   text_t resline;
    1180   if (isApprox == Approximate) resline = "_textapprox_";
    1181   else if (isApprox == MoreThan) resline = "_textmorethan_";
    1182  
    1183   if (numdocs == 0) resline = "_textnodocs_";
    1184   else if (numdocs == 1) resline += "_text1doc_";
    1185   else resline += text_t(numdocs) + " _textlotsdocs_";
    1186   disp.setmacro("resultline", "query", resline);
    1187 
     1179  define_query_macros( args, disp, numdocs, isApprox);
     1180  // save the query if appropriate
     1181  save_search_history(args, numdocs, isApprox);
     1182  define_history_macros (disp, args, protos, logout);
     1183
     1184  textout << outconvert << disp << "_query:header_\n"
     1185      << "_query:content_";
     1186
     1187  // now go through each result and output it
    11881188  QueryResult_tset::iterator res_here = results.begin();
    11891189  QueryResult_tset::iterator res_end = results.end();
     
    11951195  browserclass *browserptr = NULL;
    11961196
    1197   // set up _thisfirst_ and _thislast_ macros
    1198   disp.setmacro ("thisfirst", "query", firstdoc);
     1197  int count = 1;
     1198  int firstdoc = args.getintarg("r");
     1199  int hitsperpage = args.getintarg("o");
    11991200  int thislast = firstdoc + (hitsperpage - 1);
    1200   if (thislast > numdocs) thislast = numdocs;
    1201   disp.setmacro ("thislast", "query", thislast);
    1202 
    1203   // set up _prevfirst_ and _prevlast_ macros
    1204   if (firstdoc > 1) {
    1205     disp.setmacro ("prevlast", "query", firstdoc - 1);
    1206     int prevfirst = firstdoc - hitsperpage;
    1207     if (prevfirst < 1) prevfirst = 1;
    1208     disp.setmacro ("prevfirst", "query", prevfirst);
    1209   }
    1210 
    1211   // set up _nextfirst_ and _nextlast_ macros
    1212   if (thislast < numdocs) {
    1213     disp.setmacro ("nextfirst", "query", thislast + 1);
    1214     int nextlast = thislast + hitsperpage;
    1215     if (nextlast > numdocs) nextlast = numdocs;
    1216     disp.setmacro ("nextlast", "query", nextlast);
    1217   }
    1218 
    1219   textout << outconvert << disp << "_query:header_\n"
    1220       << "_query:content_";
    1221 
    1222   int count = 1;
    12231201
    12241202  // output results
     
    12891267  text_t formatstring;
    12901268  if (!get_formatstring (classification, browsertype,
    1291              cinfo->format, formatstring))
     1269             cinfo->format, formatstring)) {
    12921270    formatstring = bptr->get_default_formatstring();
    1293 
     1271  }
    12941272  FilterRequest_t request;
    12951273  FilterResponse_t response;
     
    13031281  request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
    13041282  text_t formattedstring = "";
    1305 
     1283  get_formatted_query_string(formattedstring, args, disp, logout);
     1284
     1285
     1286  if (!formattedstring.empty()) { // do the query
     1287    // note! formattedstring is in unicode! mg and mgpp must convert!
     1288    set_queryfilter_options (request, formattedstring, args);
     1289    collectproto->filter (collection, request, response, err, logout);
     1290    if (err != noError) {
     1291      outconvertclass text_t2ascii;
     1292      logout << text_t2ascii
     1293         << "queryaction::search_single_collections: call to QueryFilter failed "
     1294         << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
     1295      return false;
     1296    }
     1297 
     1298    define_query_macros (args, disp, response.numDocs, response.isApprox);
     1299    define_single_query_macros(args, disp, response);
     1300
     1301    // save the query if appropriate
     1302    save_search_history(args, response.numDocs, response.isApprox);
     1303  }
     1304  define_history_macros (disp, args, protos, logout);
     1305 
     1306  textout << outconvert << disp << "_query:header_\n"
     1307      << "_query:content_";
     1308
     1309  // output the results
     1310  bool use_table = is_table_content (formatlistptr);
     1311  bptr->output_section_group (response, args, collection, 0, formatlistptr,
     1312                  use_table, request.fields, request.getParents,
     1313                  collectproto, disp, outconvert, textout, logout);
     1314 
     1315
     1316  textout << outconvert << disp << "_query:footer_";
     1317 
     1318  delete (formatlistptr);
     1319 
     1320  return true;
     1321}
     1322 
     1323// does the formatting of the query string - either uses q for a text search
     1324// or the form values for an form search
     1325// also adds dates if appropriate in text search
     1326void queryaction::get_formatted_query_string (text_t &formattedstring,
     1327                          cgiargsclass &args,
     1328                          displayclass &disp,
     1329                          ostream &logout) {
    13061330  if (args["qt"]=="0") { // normal text search
    13071331    formattedstring = args["q"];
    13081332    format_querystring (formattedstring, args.getintarg("b"));
    13091333    add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
    1310         args.getintarg("dsbc"), args.getintarg("debc"));
     1334          args.getintarg("dsbc"), args.getintarg("debc"));
    13111335  }
    13121336  else if (args["qt"]=="1" ){ // form search
     
    13431367  } // args["qt"]=1
    13441368  else {
    1345     logout << "ERROR (query_action::search_single_collection): querytype not defined\n";
    1346     return false;
    1347   }
    1348 
    1349   if (!formattedstring.empty()) { // do the query
    1350     // note! formattedstring is in unicode! mg and mgpp must convert!
    1351     set_queryfilter_options (request, formattedstring, args);
    1352     collectproto->filter (collection, request, response, err, logout);
    1353     if (err != noError) {
    1354       outconvertclass text_t2ascii;
    1355       logout << text_t2ascii
    1356          << "queryaction::search_single_collections: call to QueryFilter failed "
    1357          << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
    1358       return false;
    1359     }
    1360  
    1361     define_query_macros (args, disp, response);
    1362 
    1363     // save the query if appropriate
    1364     if (!save_search_history(args, response))
    1365       logout << "save failed";
    1366   }
    1367 
    1368   define_history_macros (disp, args, protos, logout);
    1369  
    1370   textout << outconvert << disp << "_query:header_\n"
    1371       << "_query:content_";
    1372 
    1373   // output the results
    1374   bool use_table = is_table_content (formatlistptr);
    1375   bptr->output_section_group (response, args, collection, 0, formatlistptr,
    1376                   use_table, request.fields, request.getParents,
    1377                   collectproto, disp, outconvert, textout, logout);
    1378  
    1379 
    1380   textout << outconvert << disp << "_query:footer_";
    1381  
    1382   delete (formatlistptr);
    1383  
    1384   return true;
    1385 }
    1386  
     1369    logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n";
     1370  }
     1371}
     1372
     1373
    13871374// define_query_macros sets the macros that couldn't be set until the
    1388 // query had been done. Those macros are _freqmsg_, _quotedquery_,
     1375// query had been done. Those macros are
    13891376// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
    13901377// _thisfirst_, and _thislast_
    1391 void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
    1392                        const FilterResponse_t &response) {
    1393   // set up _freqmsg_ and _quotedquery_ macros
    1394   text_t freqmsg = "_textfreqmsg1_";
    1395   TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
    1396   TermInfo_tarray::const_iterator end_term = response.termInfo.end();
    1397   while (this_term != end_term) {
    1398     // check that the term doesn't consist completely of digits...
    1399     //    char *term = (*this_term).term.getcstr();
    1400     //    char *lastchar;
    1401     //    strtol(term,&lastchar,10);
    1402     //    if(*lastchar != '\0'){
    1403     freqmsg += (*this_term).term + ": " + (*this_term).freq;
    1404     if ((this_term + 1) != end_term)
    1405       freqmsg += ", ";
    1406     //    }
    1407     //    delete term;
    1408     this_term ++;
    1409   }
    1410   disp.setmacro ("freqmsg", "query", freqmsg);
    1411 
     1378// this has been simplified so it can be used with both search_single_coll
     1379// and search_multiple_coll
     1380void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
     1381                       int numdocs, isapprox isApprox) {
     1382 
    14121383  // set up _resultline_ macro
    14131384  text_t resline;
    14141385  int maxdocs = args.getintarg("m");
    1415   int numdocs = response.numDocs;
    1416   isapprox isApprox = response.isApprox;
    14171386  if (num_phrases > 0) isApprox = Exact;
    14181387  if (maxdocs == -1) maxdocs = numdocs;
     
    14581427}
    14591428
    1460 bool queryaction::save_search_history (cgiargsclass &args, const FilterResponse_t &response)
    1461 {
     1429// define_single_query_macros sets the extra macros for search_single_coll
     1430// that couldn't be set until the query had been done. Those macros are
     1431// _freqmsg_, _quotedquery_
     1432void queryaction::define_single_query_macros (cgiargsclass &args,
     1433                          displayclass &disp,
     1434                          const FilterResponse_t &response) {
     1435  // set up _freqmsg_ and _quotedquery_ macros
     1436  text_t freqmsg = "_textfreqmsg1_";
     1437  TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
     1438  TermInfo_tarray::const_iterator end_term = response.termInfo.end();
     1439  while (this_term != end_term) {
     1440    freqmsg += (*this_term).term + ": " + (*this_term).freq;
     1441    if ((this_term + 1) != end_term)
     1442      freqmsg += ", ";
     1443    this_term ++;
     1444  }
     1445  disp.setmacro ("freqmsg", "query", freqmsg);
     1446}
     1447
     1448// should this change for cross coll search??
     1449bool queryaction::save_search_history (cgiargsclass &args, int numdocs,
     1450                       isapprox isApprox) {
    14621451  if (args["q"]=="") return true; // null query, dont save
    1463   if (args["hs"]=="0") return true; // only save when submit query
    1464                                     // displayed
     1452  if (args["hs"]=="0") return true; // only save when submit query pressed
     1453 
    14651454  // get userid
    14661455  text_t userid = args["z"];
    14671456
    14681457  // the number of docs goes on the front of the query string
    1469   int numdocs= response.numDocs;
    14701458  text_t query = text_t(numdocs);
    1471   if (response.isApprox==MoreThan) { // there were more docs found
     1459  if (isApprox==MoreThan) { // there were more docs found
    14721460    query.push_back('+');
    14731461  }
  • trunk/gsdl/src/recpt/queryaction.h

    r3546 r4200  
    6666  int num_phrases;
    6767
     68  virtual void define_single_query_macros (cgiargsclass &args,
     69                       displayclass &disp,
     70                       const FilterResponse_t &response);
    6871  virtual void define_query_macros (cgiargsclass &args, displayclass &disp,
    69                 const FilterResponse_t &response);
     72                int numDocs, isapprox isApprox);
    7073
     74  void get_formatted_query_string (text_t &formattedstring, cgiargsclass &args,
     75                   displayclass &disp, ostream &logout);
    7176  void define_query_interface(displayclass &disp, cgiargsclass &args,
    72                recptprotolistclass *protos, ostream &logout);
    73 
     77                  recptprotolistclass *protos, ostream &logout);
     78 
    7479  void define_form_macros (displayclass &disp, cgiargsclass &args,
    7580               recptprotolistclass *protos, ostream &logout);
     
    110115
    111116
    112   bool save_search_history(cgiargsclass &args,
    113                const FilterResponse_t &response);
     117  bool save_search_history(cgiargsclass &args, int numdocs, isapprox isApprox);
    114118
    115119public:
Note: See TracChangeset for help on using the changeset viewer.