Index: main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp	(revision 23378)
+++ main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp	(revision 23379)
@@ -626,8 +626,4 @@
 
 
-
-// **** check to see if this version is identical to that in 
-// queryaction.cpp and remove queryaction.cpp version if it is
-
 bool basequeryaction::search_single_collection (cgiargsclass& args, 
 						const text_t& collection,
@@ -653,4 +649,28 @@
   }
 
+  comerror_t err;
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
+  
+  if (cinfo == NULL) {
+    logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
+    return false;
+  }
+    
+  bool segment = cinfo->isSegmented;
+
+  // get the formatted query string
+  text_t formattedstring = "";
+  get_formatted_query_string(formattedstring, segment, args, disp, logout);
+
+  if (formattedstring.empty()) {
+    // no point carrying on if we have no query
+    define_history_macros (disp, args, protos, logout);
+    textout << outconvert << disp << "_query:header_\n"
+	  << "_query:content_";
+    textout << outconvert << disp << "_query:footer_";
+
+    return true;
+  }
+    
   // (.*)queryaction uses "VList" browser to display results,
   // a queries clasification is "Search"
@@ -658,13 +678,4 @@
   text_t classification = "Search";
 
-  comerror_t err;
-  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
-  
-  if (cinfo == NULL) {
-    logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
-    return false;
-  }
-    
-  bool segment = cinfo->isSegmented;
   browserclass *bptr = browsers->getbrowser (browsertype);
 
@@ -695,105 +706,113 @@
   parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
     
+  request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
+  // note! formattedstring is in unicode! mg and mgpp must convert!
+  set_queryfilter_options (request, formattedstring, args);
+  
   // do the query
-  request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
-  text_t formattedstring = "";
-  get_formatted_query_string(formattedstring, segment, args, disp, logout);
-
-
-  if (!formattedstring.empty()) { // do the query
-    // note! formattedstring is in unicode! mg and mgpp must convert!
-    set_queryfilter_options (request, formattedstring, args);
-
-    collectproto->filter (collection, request, response, err, logout);
-
-    if (err != noError) {
-      outconvertclass text_t2ascii;
-      logout << text_t2ascii
-	     << "basequeryaction::search_single_collections: call to "
-	     << query_filter_name() << " failed "
-	     << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
-     
+  collectproto->filter (collection, request, response, err, logout);
+
+  // we had an error
+  if (err != noError) {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "basequeryaction::search_single_collections: call to "
+	   << query_filter_name() << " failed "
+	   << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
+    
+    disp.setmacro("resultline", "query", "_textnodocs_");
+    if (err == syntaxError) {
+      disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
+    } else {
+      disp.setmacro ("freqmsg", "query", "");
     }
-
-    // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
-    if (err == noError && !args["ifl"].empty()) {
-      //Restore the "r" and "o" arg
-      args["r"] = start_results_from_old;
-      args["o"] = hits_per_page_old;
+    // restore r and o args in case they have changed
+    args["r"] = start_results_from_old;
+    args["o"] = hits_per_page_old;
+    
+    define_history_macros (disp, args, protos, logout);
+    
+    textout << outconvert << disp << "_query:header_\n"
+	    << "_query:content_";
+    textout << outconvert << disp << "_query:footer_";
+    delete (formatlistptr);
+    return true;
+  }
+  
+  // ok, so no error, lets output the results
+  
+  // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
+  if (!args["ifl"].empty()) {
+    //Restore the "r" and "o" arg
+    args["r"] = start_results_from_old;
+    args["o"] = hits_per_page_old;
+    
+    //Find whether DocumentSearchResultLinks is enabled
+    bool show_links = false;
+    text_tmap::const_iterator format_here = cinfo->format.begin();
+    text_tmap::const_iterator format_end = cinfo->format.end();
+    
+    while (format_here != format_end) {
+      if (((*format_here).first == "DocumentSearchResultLinks") && 
+	  ((*format_here).second == "true")){
+	show_links = true;
+	break;
+      }
+      ++format_here;
+    } 
+    
+    if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
       
-      //Find whether DocumentSearchResultLinks is enabled
-      bool show_links = false;
-      text_tmap::const_iterator format_here = cinfo->format.begin();
-      text_tmap::const_iterator format_end = cinfo->format.end();
-      
-      while (format_here != format_end) {
-	if (((*format_here).first == "DocumentSearchResultLinks") && 
-	    ((*format_here).second == "true")){
-	  show_links = true;
-	  break;
+      // The first search result is the one we want
+      if (response.docInfo.begin() != response.docInfo.end()) {
+	
+	ResultDocInfo_tarray::iterator section = response.docInfo.begin();
+	
+	// We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
+	int srn = 0;
+	int srp = 0;
+	if (show_links) {
+	  int ifln = args["ifln"].getint();
+	  srn = ifln + 1;
+	  if (srn > response.numDocs) {
+	    srn = 0;
+	  }
+	  srp = ifln - 1;
+	  if (srp < 0) {
+	    srp = 0;
+	  }
 	}
-	++format_here;
-      } 
-      
-      if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
 	
-	// The first search result is the one we want
-	if (response.docInfo.begin() != response.docInfo.end()) {
-	  
-	  ResultDocInfo_tarray::iterator section = response.docInfo.begin();
-	  
-	  // We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
-	  int srn = 0;
-	  int srp = 0;
-	  if (show_links) {
-	    int ifln = args["ifln"].getint();
-	    srn = ifln + 1;
-	    if (srn > response.numDocs) {
-	      srn = 0;
-	    }
-	    srp = ifln - 1;
-	    if (srp < 0) {
-	      srp = 0;
-	    }
-	  }
-	  
-	  textout << outconvert << disp 
-		  << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" 
-		  << collection << "&cl=search&d=" << (*section).OID 
-		  << "&srn=" << srn << "&srp=" << srp << "\n\n";
-	  textout << flush;
-	  
-	  return true;
-	}
+	textout << outconvert << disp 
+		<< "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" 
+		<< collection << "&cl=search&d=" << (*section).OID 
+		<< "&srn=" << srn << "&srp=" << srp << "\n\n";
+	textout << flush;
+	
+	return true;
       }
-    
-      // There weren't enough (or any) matching documents
-      // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
-      // done the right thing (because ifl was set), so we need to make sure the output is html
-      textout << "Content-type: text/html\n\n";
-      
     }
-
-    if (err != noError) {
-      disp.setmacro("resultline", "query", "_textnodocs_");
-      if (err == syntaxError) {
-	disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
-      } else {
-	disp.setmacro ("freqmsg", "query", "");
-      }
-    } else {
-      
-      define_query_macros (args, disp, response.numDocs, response.isApprox);
-      define_single_query_macros(args, disp, response);
-      // save the query if appropriate
-      save_search_history(args, response.numDocs, response.isApprox);
-    }
-
-    // If Lucene threw a TooManyClauses exception, tell the user about it
-    if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
-      disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
-    }
-  }
-  
+    
+    // There weren't enough (or any) matching documents
+    // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
+    // done the right thing (because ifl was set), so we need to make sure the output is html
+    textout << "Content-type: text/html\n\n";
+    
+  }
+
+  define_query_macros (args, disp, response.numDocs, response.isApprox);
+  define_single_query_macros(args, disp, response);
+  // save the query if appropriate
+  save_search_history(args, response.numDocs, response.isApprox);
+  
+  
+  // would this result in an error  in err???
+  // If Lucene threw a TooManyClauses exception, tell the user about it
+  if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
+    cerr << "too many clauses\n";
+    disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
+  }
+  
+
   //Restore the "r" and "o" arg in case they have been changed and we still get here
   args["r"] = start_results_from_old;
@@ -805,14 +824,13 @@
 	  << "_query:content_";
   
-  if (err == noError) {
-    // output the results
-    text_t numdocs_t = response.numDocs;  
-    args["nmd"] = numdocs_t;
-    bool use_table = is_table_content (formatlistptr);
-    bptr->output_section_group (response, args, collection, 0, formatlistptr, 
-				use_table, request.fields, request.getParents, 
-				collectproto, disp, outconvert, textout, logout);
-  }
-
+  // output the results
+  text_t numdocs_t = response.numDocs;  
+  args["nmd"] = numdocs_t;
+  bool use_table = is_table_content (formatlistptr);
+  bptr->output_section_group (response, args, collection, 0, formatlistptr, 
+			      use_table, request.fields, request.getParents, 
+			      collectproto, disp, outconvert, textout, logout);
+  
+  
   textout << outconvert << disp << "_query:footer_";
   
