Changeset 7594


Ignore:
Timestamp:
2004-06-16T09:48:55+12:00 (20 years ago)
Author:
mdewsnip
Message:

"I'm feeling lucky" functionality (a la Google). An extra argument ("ifl") can be specified to a query -- in this case, the user will be taken directly to the first matching document.

You can add a checkbox to the query form to get this functionality:

<input type=checkbox name="ifl">I'm feeling lucky!

This functionality is also very useful to go directly from some key value (eg. a unique file name) to a document, from within format statements. This removes the need to know the HASH ID of the target document.

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

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/cgiargs.h

    r7429 r7594  
    5151// should be produced
    5252// fullcontent same as content but the action should put content-type as last header.
    53 enum response_t {location, content, fullcontent};
     53enum response_t {location, content, fullcontent, undecided_location};
    5454
    5555
  • trunk/gsdl/src/recpt/queryaction.cpp

    r7441 r7594  
    418418  arg_ainfo.savedarginfo = cgiarginfo::must;
    419419  argsinfo.addarginfo (NULL, arg_ainfo);
    420  
     420
     421  // "ifl" - I'm feeling lucky! (Go directly to the first matching document)
     422  arg_ainfo.shortname = "ifl";
     423  arg_ainfo.longname = "i'm feeling lucky";
     424  arg_ainfo.multiplechar = false;
     425  arg_ainfo.defaultstatus = cgiarginfo::weak;
     426  arg_ainfo.argdefault = g_EmptyText;
     427  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     428  argsinfo.addarginfo (NULL, arg_ainfo);
     429
    421430}
    422431
     
    538547}
    539548
    540 void queryaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
     549void queryaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
    541550                    response_t &response, text_t &response_data,
    542551                    ostream &/*logout*/) {
     552  // If this is an "I'm feeling lucky" request, we don't know the target location until later
     553  if (!args["ifl"].empty()) {
     554    response = undecided_location;
     555    return;
     556  }
     557
    543558  response = content;
    544559  response_data = "text/html";
     
    13121327    bool syntax_error = false;
    13131328    if (err == syntaxError) syntax_error = true;
     1329
     1330    if (!args["ifl"].empty()) {
     1331      // Go directly to the first matching document
     1332      ResultDocInfo_tarray::iterator thissection = response.docInfo.begin();
     1333      if (thissection != response.docInfo.end()) {
     1334    text_t& arg_d = (*thissection).OID;
     1335    text_t doc_url = "_httpdocument_";
     1336    doc_url += "&c=" + collection;
     1337    doc_url += "&d=" + arg_d;
     1338
     1339    // location response (url may contain macros!!)
     1340    textout << outconvert << disp << "Location: " << doc_url << "\n\n";
     1341      }
     1342      // Ooops... there weren't any matching documents
     1343      else {
     1344    // Surely there must be a better way to get the query URL without the ifl argument?
     1345    // This is not complete!
     1346    text_t query_url = "_gwcgi_";
     1347    query_url += "?e=" + args["e"];
     1348    query_url += "&h=" + args["h"];
     1349    query_url += "&q=" + args["q"];
     1350    query_url += "&r=" + args["r"];
     1351    query_url += "&t=" + args["t"];
     1352    query_url += "&hs=" + args["hs"];
     1353
     1354    textout << outconvert << disp << "Location: " << query_url << "\n\n";
     1355      }
     1356
     1357      textout << flush;
     1358      return true;
     1359    }
     1360
    13141361    //return false;
    13151362    define_query_macros (args, disp, response.numDocs, response.isApprox);
  • trunk/gsdl/src/recpt/receptionist.cpp

    r7509 r7594  
    848848
    849849    contentout << text_t2ascii << "Content-type: " << response_data << "\n\n";
    850   } else {
     850  }
     851  else if (response == undecided_location) {
     852    // Wait until later to output the target location
     853    // Used for the "I'm feeling lucky" functionality
     854  }
     855  else {
    851856    // unknown response
    852857    logout << "Error: get_cgihead_info returned an unknown response type.\n";
Note: See TracChangeset for help on using the changeset viewer.