greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 17936

Show
Ignore:
Timestamp:
2008-11-27 12:27:21 (1 month ago)
Author:
kjdon
Message:

changed ifl code (also used for next and prev search results) so we only ask for one result, rather than all results then iterate through to find the one we want. The old way was really slow for large collections with thousands of search results

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gsdl/trunk/runtime-src/src/recpt/queryaction.cpp

    r15589 r17936  
    14651465  FilterResponse_t response; 
    14661466 
    1467   text_t maxDoc_old = args["o"]; 
    1468   text_t starts_old = args["r"];   
    1469  
    1470     //if the "ifl" argument is set ignore the "r" and "o" arg 
    1471   if(!args["ifl"].empty()){ 
    1472     args["r"] = 1; 
    1473     args["o"] = args["m"]; 
    1474   } 
    1475   
     1467  text_t hits_per_page_old = args["o"]; 
     1468  text_t start_results_from_old = args["r"];   
     1469 
     1470  // if the "ifl" argument is set to 1, we only want to get one document 
     1471  // this may be the first search result (from "I feel lucky") or maybe a  
     1472  // specified search result (from next/prev search result link) 
     1473  if (args["ifl"] == "1") { 
     1474    args["r"] = args["ifln"]; // the document number we want,  
     1475    args["o"] = "1"; 
     1476  } 
    14761477 
    14771478  bptr->set_filter_options (request, args); 
     
    15041505    if (err == noError && !args["ifl"].empty()) { 
    15051506      //Restore the "r" and "o" arg 
    1506       args["r"] = starts_old; 
    1507       args["o"] = maxDoc_old
    1508  
     1507      args["r"] = start_results_from_old; 
     1508      args["o"] = hits_per_page_old
     1509       
    15091510      //Find whether DocumentSearchResultLinks is enabled 
    15101511      bool show_links = false; 
    15111512      text_tmap::const_iterator format_here = cinfo->format.begin(); 
    15121513      text_tmap::const_iterator format_end = cinfo->format.end(); 
    1513  
    1514        while (format_here != format_end) { 
    1515          if (((*format_here).first == "DocumentSearchResultLinks") &&  
    1516              ((*format_here).second == "true")){ 
    1517            show_links = true; 
    1518            break; 
    1519          } 
    1520          ++format_here; 
    1521        }  
    1522  
    1523        if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) 
    1524        { 
    1525          // Find the search result specified by the ifln argument    
    1526          ResultDocInfo_tarray::iterator thissection = response.docInfo.begin(); 
    1527          int section_number = 1; 
    1528          int ifln = args["ifln"].getint(); 
    1529                
    1530          while (section_number != ifln  && thissection != response.docInfo.end()) {      
    1531            thissection++; 
    1532            section_number++; 
    1533          } 
    1534          // If the search result exists, go directly to it 
    1535          if (section_number == ifln && thissection != response.docInfo.end()) { 
    1536            // Location response (this URL must have "&" and not "&"!) 
    1537            int num_docs =  response.numDocs; 
    1538            int srn = 0; 
    1539            int srp = 0; 
    1540            if (show_links && section_number < num_docs ) { 
    1541              srn = section_number + 1; 
    1542            } 
    1543            if (show_links && section_number > 1 ) { 
    1544              srp = section_number - 1; 
    1545            } 
    1546          
    1547            textout << outconvert << disp << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" << collection << "&cl=search&d=" << (*thissection).OID <<"&srn="<<srn<<"&srp="<<srp<< "\n\n"; 
    1548            textout << flush; 
    1549             
    1550            return true; 
    1551          } 
    1552        } 
    1553         
     1514       
     1515      while (format_here != format_end) { 
     1516        if (((*format_here).first == "DocumentSearchResultLinks") &&  
     1517            ((*format_here).second == "true")){ 
     1518          show_links = true; 
     1519          break; 
     1520        } 
     1521        ++format_here; 
     1522      }  
     1523       
     1524      if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) { 
     1525         
     1526        // The first search result is the one we want 
     1527        if (response.docInfo.begin() != response.docInfo.end()) { 
     1528           
     1529          ResultDocInfo_tarray::iterator section = response.docInfo.begin(); 
     1530           
     1531          // We still need to set "srn" and "srp" values (next and prev search result numbers 
     1532          int ifln = args["ifln"].getint(); 
     1533          int srn = ifln + 1; 
     1534          if (srn > response.numDocs) { 
     1535            srn = 0; 
     1536          } 
     1537          int srp = ifln - 1; 
     1538          if (srp < 0) { 
     1539            srp = 0; 
     1540          } 
     1541           
     1542           
     1543          textout << outconvert << disp << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" << collection << "&cl=search&d=" << (*section).OID <<"&srn="<<srn<<"&srp="<<srp<< "\n\n"; 
     1544          textout << flush; 
     1545           
     1546          return true; 
     1547        } 
     1548      } 
     1549     
    15541550      // There weren't enough (or any) matching documents 
    15551551      // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have