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

reordered code in search_single_collection so its hopefully slightly more efficient, and easier to understand

File:
1 edited

Legend:

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

    r22984 r23379  
    626626
    627627
    628 
    629 // **** check to see if this version is identical to that in
    630 // queryaction.cpp and remove queryaction.cpp version if it is
    631 
    632628bool basequeryaction::search_single_collection (cgiargsclass& args,
    633629                        const text_t& collection,
     
    653649  }
    654650
     651  comerror_t err;
     652  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
     653 
     654  if (cinfo == NULL) {
     655    logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
     656    return false;
     657  }
     658   
     659  bool segment = cinfo->isSegmented;
     660
     661  // get the formatted query string
     662  text_t formattedstring = "";
     663  get_formatted_query_string(formattedstring, segment, args, disp, logout);
     664
     665  if (formattedstring.empty()) {
     666    // no point carrying on if we have no query
     667    define_history_macros (disp, args, protos, logout);
     668    textout << outconvert << disp << "_query:header_\n"
     669      << "_query:content_";
     670    textout << outconvert << disp << "_query:footer_";
     671
     672    return true;
     673  }
     674   
    655675  // (.*)queryaction uses "VList" browser to display results,
    656676  // a queries clasification is "Search"
     
    658678  text_t classification = "Search";
    659679
    660   comerror_t err;
    661   ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
    662  
    663   if (cinfo == NULL) {
    664     logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
    665     return false;
    666   }
    667    
    668   bool segment = cinfo->isSegmented;
    669680  browserclass *bptr = browsers->getbrowser (browsertype);
    670681
     
    695706  parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
    696707   
     708  request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
     709  // note! formattedstring is in unicode! mg and mgpp must convert!
     710  set_queryfilter_options (request, formattedstring, args);
     711 
    697712  // do the query
    698   request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
    699   text_t formattedstring = "";
    700   get_formatted_query_string(formattedstring, segment, args, disp, logout);
    701 
    702 
    703   if (!formattedstring.empty()) { // do the query
    704     // note! formattedstring is in unicode! mg and mgpp must convert!
    705     set_queryfilter_options (request, formattedstring, args);
    706 
    707     collectproto->filter (collection, request, response, err, logout);
    708 
    709     if (err != noError) {
    710       outconvertclass text_t2ascii;
    711       logout << text_t2ascii
    712          << "basequeryaction::search_single_collections: call to "
    713          << query_filter_name() << " failed "
    714          << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
    715      
     713  collectproto->filter (collection, request, response, err, logout);
     714
     715  // we had an error
     716  if (err != noError) {
     717    outconvertclass text_t2ascii;
     718    logout << text_t2ascii
     719       << "basequeryaction::search_single_collections: call to "
     720       << query_filter_name() << " failed "
     721       << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
     722   
     723    disp.setmacro("resultline", "query", "_textnodocs_");
     724    if (err == syntaxError) {
     725      disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
     726    } else {
     727      disp.setmacro ("freqmsg", "query", "");
    716728    }
    717 
    718     // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
    719     if (err == noError && !args["ifl"].empty()) {
    720       //Restore the "r" and "o" arg
    721       args["r"] = start_results_from_old;
    722       args["o"] = hits_per_page_old;
     729    // restore r and o args in case they have changed
     730    args["r"] = start_results_from_old;
     731    args["o"] = hits_per_page_old;
     732   
     733    define_history_macros (disp, args, protos, logout);
     734   
     735    textout << outconvert << disp << "_query:header_\n"
     736        << "_query:content_";
     737    textout << outconvert << disp << "_query:footer_";
     738    delete (formatlistptr);
     739    return true;
     740  }
     741 
     742  // ok, so no error, lets output the results
     743 
     744  // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
     745  if (!args["ifl"].empty()) {
     746    //Restore the "r" and "o" arg
     747    args["r"] = start_results_from_old;
     748    args["o"] = hits_per_page_old;
     749   
     750    //Find whether DocumentSearchResultLinks is enabled
     751    bool show_links = false;
     752    text_tmap::const_iterator format_here = cinfo->format.begin();
     753    text_tmap::const_iterator format_end = cinfo->format.end();
     754   
     755    while (format_here != format_end) {
     756      if (((*format_here).first == "DocumentSearchResultLinks") &&
     757      ((*format_here).second == "true")){
     758    show_links = true;
     759    break;
     760      }
     761      ++format_here;
     762    }
     763   
     764    if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
    723765     
    724       //Find whether DocumentSearchResultLinks is enabled
    725       bool show_links = false;
    726       text_tmap::const_iterator format_here = cinfo->format.begin();
    727       text_tmap::const_iterator format_end = cinfo->format.end();
    728      
    729       while (format_here != format_end) {
    730     if (((*format_here).first == "DocumentSearchResultLinks") &&
    731         ((*format_here).second == "true")){
    732       show_links = true;
    733       break;
     766      // The first search result is the one we want
     767      if (response.docInfo.begin() != response.docInfo.end()) {
     768   
     769    ResultDocInfo_tarray::iterator section = response.docInfo.begin();
     770   
     771    // We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
     772    int srn = 0;
     773    int srp = 0;
     774    if (show_links) {
     775      int ifln = args["ifln"].getint();
     776      srn = ifln + 1;
     777      if (srn > response.numDocs) {
     778        srn = 0;
     779      }
     780      srp = ifln - 1;
     781      if (srp < 0) {
     782        srp = 0;
     783      }
    734784    }
    735     ++format_here;
    736       }
    737      
    738       if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
    739785   
    740     // The first search result is the one we want
    741     if (response.docInfo.begin() != response.docInfo.end()) {
    742      
    743       ResultDocInfo_tarray::iterator section = response.docInfo.begin();
    744      
    745       // We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
    746       int srn = 0;
    747       int srp = 0;
    748       if (show_links) {
    749         int ifln = args["ifln"].getint();
    750         srn = ifln + 1;
    751         if (srn > response.numDocs) {
    752           srn = 0;
    753         }
    754         srp = ifln - 1;
    755         if (srp < 0) {
    756           srp = 0;
    757         }
    758       }
    759      
    760       textout << outconvert << disp
    761           << "Location: _gwcgi_?e=_compressedoptions_&a=d&c="
    762           << collection << "&cl=search&d=" << (*section).OID
    763           << "&srn=" << srn << "&srp=" << srp << "\n\n";
    764       textout << flush;
    765      
    766       return true;
    767     }
     786    textout << outconvert << disp
     787        << "Location: _gwcgi_?e=_compressedoptions_&a=d&c="
     788        << collection << "&cl=search&d=" << (*section).OID
     789        << "&srn=" << srn << "&srp=" << srp << "\n\n";
     790    textout << flush;
     791   
     792    return true;
    768793      }
    769    
    770       // There weren't enough (or any) matching documents
    771       // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
    772       // done the right thing (because ifl was set), so we need to make sure the output is html
    773       textout << "Content-type: text/html\n\n";
    774      
    775794    }
    776 
    777     if (err != noError) {
    778       disp.setmacro("resultline", "query", "_textnodocs_");
    779       if (err == syntaxError) {
    780     disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
    781       } else {
    782     disp.setmacro ("freqmsg", "query", "");
    783       }
    784     } else {
    785      
    786       define_query_macros (args, disp, response.numDocs, response.isApprox);
    787       define_single_query_macros(args, disp, response);
    788       // save the query if appropriate
    789       save_search_history(args, response.numDocs, response.isApprox);
    790     }
    791 
    792     // If Lucene threw a TooManyClauses exception, tell the user about it
    793     if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
    794       disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
    795     }
    796   }
    797  
     795   
     796    // There weren't enough (or any) matching documents
     797    // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
     798    // done the right thing (because ifl was set), so we need to make sure the output is html
     799    textout << "Content-type: text/html\n\n";
     800   
     801  }
     802
     803  define_query_macros (args, disp, response.numDocs, response.isApprox);
     804  define_single_query_macros(args, disp, response);
     805  // save the query if appropriate
     806  save_search_history(args, response.numDocs, response.isApprox);
     807 
     808 
     809  // would this result in an error  in err???
     810  // If Lucene threw a TooManyClauses exception, tell the user about it
     811  if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
     812    cerr << "too many clauses\n";
     813    disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
     814  }
     815 
     816
    798817  //Restore the "r" and "o" arg in case they have been changed and we still get here
    799818  args["r"] = start_results_from_old;
     
    805824      << "_query:content_";
    806825 
    807   if (err == noError) {
    808     // output the results
    809     text_t numdocs_t = response.numDocs; 
    810     args["nmd"] = numdocs_t;
    811     bool use_table = is_table_content (formatlistptr);
    812     bptr->output_section_group (response, args, collection, 0, formatlistptr,
    813                 use_table, request.fields, request.getParents,
    814                 collectproto, disp, outconvert, textout, logout);
    815   }
    816 
     826  // output the results
     827  text_t numdocs_t = response.numDocs; 
     828  args["nmd"] = numdocs_t;
     829  bool use_table = is_table_content (formatlistptr);
     830  bptr->output_section_group (response, args, collection, 0, formatlistptr,
     831                  use_table, request.fields, request.getParents,
     832                  collectproto, disp, outconvert, textout, logout);
     833 
     834 
    817835  textout << outconvert << disp << "_query:footer_";
    818836 
Note: See TracChangeset for help on using the changeset viewer.