Changeset 13280


Ignore:
Timestamp:
2006-11-15T17:24:48+13:00 (17 years ago)
Author:
mdewsnip
Message:

Tidied up the "I'm feeling lucky" functionality and added an "ifln" argument for specifying which matching result to display.

File:
1 edited

Legend:

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

    r12866 r13280  
    447447  argsinfo.addarginfo (NULL, arg_ainfo);
    448448
    449   // "ifl" - I'm feeling lucky! (Go directly to the first matching document)
     449  // "ifl" - I'm feeling lucky! (Go directly to a matching document)
    450450  arg_ainfo.shortname = "ifl";
    451451  arg_ainfo.longname = "i'm feeling lucky";
     
    453453  arg_ainfo.defaultstatus = cgiarginfo::weak;
    454454  arg_ainfo.argdefault = g_EmptyText;
     455  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     456  argsinfo.addarginfo (NULL, arg_ainfo);
     457
     458  // "ifln" - I'm feeling lucky number (Go directly to the nth matching document)
     459  arg_ainfo.shortname = "ifln";
     460  arg_ainfo.longname = "i'm feeling lucky number";
     461  arg_ainfo.multiplechar = true;
     462  arg_ainfo.defaultstatus = cgiarginfo::weak;
     463  arg_ainfo.argdefault = "1";
    455464  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
    456465  argsinfo.addarginfo (NULL, arg_ainfo);
     
    14561465     
    14571466    }
    1458    
     1467
     1468    // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
    14591469    if (err == noError && !args["ifl"].empty()) {
    1460       // Go directly to the first matching document
     1470      // Find the search result specified by the ifln argument
     1471      int section_number = 1;
    14611472      ResultDocInfo_tarray::iterator thissection = response.docInfo.begin();
    1462       if (thissection != response.docInfo.end()) {
    1463     // This URL must have "&" and not "&"!
    1464     text_t doc_url = "_gwcgi_?e=_compressedoptions_&a=d&c=" + collection + "&d=" + (*thissection).OID;
    1465 
    1466     // location response (url may contain macros!!)
    1467     textout << outconvert << disp << "Location: " << doc_url << "\n\n";
     1473      while (section_number != args["ifln"] && thissection != response.docInfo.end()) {
     1474    section_number++;
     1475    thissection++;
     1476      }
     1477
     1478      // If the search result exists, go directly to it
     1479      if (section_number == args["ifln"] && thissection != response.docInfo.end()) {
     1480    // Location response (this URL must have "&" and not "&amp;"!)
     1481    textout << outconvert << disp << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" << collection << "&d=" << (*thissection).OID << "\n\n";
    14681482    textout << flush;
    14691483    return true;
    14701484      }
    1471       // Ooops... there weren't any matching documents
    1472       else {
    1473     // We'll just carry on as if ifl wasn't set. The only catch is that
    1474     // get_cgihead_info won't have done the right thing (because ifl was
    1475     // set), so we need to make sure the output is html
    1476     textout << "Content-type: text/html\n\n";
    1477       }
     1485
     1486      // There weren't enough (or any) matching documents
     1487      // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
     1488      // done the right thing (because ifl was set), so we need to make sure the output is html
     1489      textout << "Content-type: text/html\n\n";
    14781490    }
    14791491
Note: See TracChangeset for help on using the changeset viewer.