Changeset 23378 for main/trunk


Ignore:
Timestamp:
2010-12-03T15:44:34+13:00 (13 years ago)
Author:
kjdon
Message:

removed search_single_collection as its the same as the one in basequeryaction. Also, reordered code in search_multiple_collection so that its a bit easier to understand

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp

    r22984 r23378  
    908908  }
    909909
     910  // check the main coll
     911  text_t main_collection = args["c"];
     912  recptproto *collectproto = protos->getrecptproto (main_collection, logout);
     913  if (collectproto == NULL) {
     914    logout << outconvert << "queryaction::search_multiple_collection: " << main_collection
     915       << " collection has a NULL collectproto\n";
     916
     917    // Display the "this collection is not installed on this system" page
     918    disp.setmacro("cvariable", displayclass::defaultpackage, main_collection);
     919    disp.setmacro("content", "query", "<p>_textbadcollection_<p>");
     920
     921    textout << outconvert << disp << "_query:header_\n"
     922        << "_query:content_\n" << "_query:footer_\n";
     923    return true;
     924  }
     925
     926  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, main_collection, logout);
     927  if (cinfo == NULL) {
     928    logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL for '"<<main_collection<<"'\n";
     929    return false;
     930  }
     931
     932  // get the formatted query string
     933  // what to do about segmentation for multiple colls??
     934  // TODO
     935  bool segment = false;
     936  text_t formattedstring = "";
     937  get_formatted_query_string(formattedstring, segment, args, disp, logout);
     938
     939  if (formattedstring.empty()) {
     940    // dont bother doing a query if no query string
     941    define_history_macros (disp, args, protos, logout);
     942    textout << outconvert << disp << "_query:header_\n"
     943      << "_query:content_";
     944    textout << outconvert << disp << "_query:footer_";
     945
     946    return true;
     947  }
     948
     949
    910950  // queryaction uses "VList" browser to display results,
    911951  // a queries clasification is "Search"
     
    916956  map<text_t, colinfo_t, lttext_t> colinfomap;
    917957
    918   ColInfoResponse_t *cinfo = NULL;
    919   recptproto *collectproto = NULL;
    920958  comerror_t err;
    921959  FilterRequest_t request;
     
    926964  isapprox isApprox = Exact;
    927965
    928   // what to do about segmentation for multiple colls??
    929   bool segment = false;
    930   text_t formattedstring = "";
    931   get_formatted_query_string(formattedstring, segment, args, disp, logout);
    932 
    933   if (formattedstring.empty()) {
    934     // dont bother doing a query if no query string
    935     define_history_macros (disp, args, protos, logout);
    936     textout << outconvert << disp << "_query:header_\n"
    937       << "_query:content_";
    938     textout << outconvert << disp << "_query:footer_";
    939 
    940     return true;
    941   }
     966
    942967  bool syntax_error = false;
    943968
     
    954979  option.value = args["m"];
    955980  request.filterOptions.push_back (option);
    956 
    957   text_tarray::iterator col_here = collections.begin();
    958   text_tarray::iterator col_end = collections.end();
    959 
    960   map<text_t, int, lttext_t> termfreqs;
    961  
    962   // just check the main col for formatting info - use individual format statements, or the main one?
    963  
    964   browserclass *bptr = browsers->getbrowser (browsertype);
    965  
    966   text_t main_col = args["c"];
    967   cinfo = recpt->get_collectinfo_ptr (collectproto, main_col, logout);
    968   if (cinfo == NULL) {
    969     logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL for '"<<main_col<<"'\n";
    970     return false;
    971   }
    972  
     981 
     982  // check the main collection for uniform formatting info - do we use
     983  // individual format statements, or just the main one?
    973984  bool use_main_col_format = false;
    974985  if (cinfo->ccsOptions & CCSUniformSearchResultsFormatting) {
    975986    use_main_col_format = true;
    976987  }
     988
     989  browserclass *bptr = browsers->getbrowser (browsertype);
    977990 
    978991  request.fields.erase (request.fields.begin(), request.fields.end());
     
    9921005  }
    9931006 
     1007  text_tarray::iterator col_here = collections.begin();
     1008  text_tarray::iterator col_end = collections.end();
     1009
     1010  map<text_t, int, lttext_t> termfreqs;
     1011
    9941012  while (col_here != col_end) {
    9951013
    9961014    collectproto = protos->getrecptproto (*col_here, logout);
    9971015    if (collectproto == NULL) {
     1016      // skip this collection
    9981017      logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
    9991018         << " collection has a NULL collectproto, ignoring\n";
     
    10031022    cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
    10041023    if (cinfo == NULL) {
     1024      // skip this collection
    10051025      logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
    10061026      ++col_here;
    10071027      continue;
    10081028    }
    1009 
     1029   
    10101030    if (!use_main_col_format) {
    10111031      request.fields.erase (request.fields.begin(), request.fields.end());
     
    10131033      bptr->load_metadata_defaults (request.fields);
    10141034     
    1015     //browserclass *bptr = browsers->getbrowser (browsertype);
    1016 
    1017     // get the formatstring if there is one
     1035      // get the formatstring if there is one
    10181036      if (!get_formatstring (classification, browsertype,
    10191037                 cinfo->format, formatstring)) {
     
    10761094      while (doc_here != doc_end) {
    10771095    thisresult.doc = *doc_here;
    1078     results.insert (thisresult);
     1096    results.insert (thisresult); // this is ordering based on doc rank
    10791097    ++doc_here;
    10801098      }
     
    11511169}
    11521170
    1153 bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
    1154                         recptprotolistclass *protos, browsermapclass *browsers,
    1155                         displayclass &disp, outconvertclass &outconvert,
    1156                         ostream &textout, ostream &logout) {
    1157 
    1158   recptproto *collectproto = protos->getrecptproto (collection, logout);
    1159   if (collectproto == NULL) {
    1160     logout << outconvert << "queryaction::search_single_collection: " << collection
    1161        << " collection has a NULL collectproto\n";
    1162 
    1163     // Display the "this collection is not installed on this system" page
    1164     disp.setmacro("cvariable", displayclass::defaultpackage, collection);
    1165     disp.setmacro("content", "query", "<p>_textbadcollection_<p>");
    1166 
    1167     textout << outconvert << disp << "_query:header_\n"
    1168         << "_query:content_\n" << "_query:footer_\n";
    1169     return true;
    1170   }
    1171 
    1172   // queryaction uses "VList" browser to display results,
    1173   // a queries clasification is "Search"
    1174   text_t browsertype = "VList";
    1175   text_t classification = "Search";
    1176 
    1177   comerror_t err;
    1178   ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
    1179 
    1180   if (cinfo == NULL) {
    1181     logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
    1182     return false;
    1183   }
    1184    
    1185   bool segment = cinfo->isSegmented;
    1186   browserclass *bptr = browsers->getbrowser (browsertype);
    1187 
    1188   // get the formatstring if there is one
    1189   text_t formatstring;
    1190   if (!get_formatstring (classification, browsertype,
    1191              cinfo->format, formatstring)) {
    1192     formatstring = bptr->get_default_formatstring();
    1193   }
    1194   FilterRequest_t request;
    1195   FilterResponse_t response;
    1196 
    1197   text_t hits_per_page_old = args["o"];
    1198   text_t start_results_from_old = args["r"]; 
    1199 
    1200   // if the "ifl" argument is set to 1, we only want to get one document
    1201   // this may be the first search result (from "I feel lucky") or maybe a
    1202   // specified search result (from next/prev search result link)
    1203   if (args["ifl"] == "1") {
    1204     args["r"] = args["ifln"]; // the document number we want
    1205     args["o"] = "1";
    1206   }
    1207 
    1208   bptr->set_filter_options (request, args);
    1209   bptr->load_metadata_defaults (request.fields);
    1210 
    1211   format_t *formatlistptr = new format_t();
    1212   parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
    1213    
    1214   // do the query
    1215   request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
    1216   text_t formattedstring = "";
    1217   get_formatted_query_string(formattedstring, segment, args, disp, logout);
    1218 
    1219 
    1220   if (!formattedstring.empty()) { // do the query
    1221     // note! formattedstring is in unicode! mg and mgpp must convert!
    1222     set_queryfilter_options (request, formattedstring, args);
    1223 
    1224     collectproto->filter (collection, request, response, err, logout);
    1225 
    1226     if (err != noError) {
    1227       outconvertclass text_t2ascii;
    1228       logout << text_t2ascii
    1229          << "queryaction::search_single_collections: call to QueryFilter failed "
    1230          << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
    1231      
    1232     }
    1233 
    1234     // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
    1235     if (err == noError && !args["ifl"].empty()) {
    1236       //Restore the "r" and "o" arg
    1237       args["r"] = start_results_from_old;
    1238       args["o"] = hits_per_page_old;
    1239      
    1240       //Find whether DocumentSearchResultLinks is enabled
    1241       bool show_links = false;
    1242       text_tmap::const_iterator format_here = cinfo->format.begin();
    1243       text_tmap::const_iterator format_end = cinfo->format.end();
    1244      
    1245       while (format_here != format_end) {
    1246     if (((*format_here).first == "DocumentSearchResultLinks") &&
    1247         ((*format_here).second == "true")){
    1248       show_links = true;
    1249       break;
    1250     }
    1251     ++format_here;
    1252       }
    1253      
    1254       if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
    1255    
    1256     // The first search result is the one we want
    1257     if (response.docInfo.begin() != response.docInfo.end()) {
    1258      
    1259       ResultDocInfo_tarray::iterator section = response.docInfo.begin();
    1260      
    1261       // We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
    1262       int srn = 0;
    1263       int srp = 0;
    1264       if (show_links) {
    1265         int ifln = args["ifln"].getint();
    1266         srn = ifln + 1;
    1267         if (srn > response.numDocs) {
    1268           srn = 0;
    1269         }
    1270         srp = ifln - 1;
    1271         if (srp < 0) {
    1272           srp = 0;
    1273         }
    1274       }
    1275      
    1276       textout << outconvert << disp
    1277           << "Location: _gwcgi_?e=_compressedoptions_&a=d&c="
    1278           << collection << "&cl=search&d=" << (*section).OID
    1279           << "&srn=" << srn << "&srp=" << srp << "\n\n";
    1280       textout << flush;
    1281      
    1282       return true;
    1283     }
    1284       }
    1285    
    1286       // There weren't enough (or any) matching documents
    1287       // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
    1288       // done the right thing (because ifl was set), so we need to make sure the output is html
    1289       textout << "Content-type: text/html\n\n";
    1290      
    1291     }
    1292 
    1293     if (err != noError) {
    1294       disp.setmacro("resultline", "query", "_textnodocs_");
    1295       if (err == syntaxError) {
    1296     disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
    1297       } else {
    1298     disp.setmacro ("freqmsg", "query", "");
    1299       }
    1300     } else {
    1301      
    1302       define_query_macros (args, disp, response.numDocs, response.isApprox);
    1303       define_single_query_macros(args, disp, response);
    1304       // save the query if appropriate
    1305       save_search_history(args, response.numDocs, response.isApprox);
    1306     }
    1307 
    1308     // If Lucene threw a TooManyClauses exception, tell the user about it
    1309     if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
    1310       disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
    1311     }
    1312   }
    1313  
    1314   //Restore the "r" and "o" arg in case they have been changed and we still get here
    1315   args["r"] = start_results_from_old;
    1316   args["o"] = hits_per_page_old;
    1317 
    1318   define_history_macros (disp, args, protos, logout);
    1319 
    1320   textout << outconvert << disp << "_query:header_\n"
    1321       << "_query:content_";
    1322  
    1323   if (err == noError) {
    1324     // output the results
    1325     text_t numdocs_t = response.numDocs; 
    1326     args["nmd"] = numdocs_t;
    1327     bool use_table = is_table_content (formatlistptr);
    1328     bptr->output_section_group (response, args, collection, 0, formatlistptr,
    1329                 use_table, request.fields, request.getParents,
    1330                 collectproto, disp, outconvert, textout, logout);
    1331   }
    1332 
    1333   textout << outconvert << disp << "_query:footer_";
    1334  
    1335   delete (formatlistptr);
    1336  
    1337   return true;
    1338 }
    1339  
     1171
    13401172// does the formatting of the query string - either uses q for a text search
    13411173// or the form values for an form search
  • main/trunk/greenstone2/runtime-src/src/recpt/queryaction.h

    r22046 r23378  
    8989                    ostream &logout);
    9090 
    91   virtual bool search_single_collection (cgiargsclass &args,
    92                      const text_t &collection,
    93                      recptprotolistclass *protos,
    94                      browsermapclass *browsers,
    95                      displayclass &disp,
    96                      outconvertclass &outconvert,
    97                      ostream &textout, ostream &logout);
    98 
    99 
    10091  virtual bool save_search_history(cgiargsclass &args, int numdocs,
    10192                   isapprox isApprox);
Note: See TracChangeset for help on using the changeset viewer.