Index: trunk/gsdl/src/recpt/queryaction.cpp
===================================================================
--- trunk/gsdl/src/recpt/queryaction.cpp	(revision 12785)
+++ trunk/gsdl/src/recpt/queryaction.cpp	(revision 12786)
@@ -672,5 +672,4 @@
 
 
-
 void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args, 
 					  recptprotolistclass *protos, ostream &logout) {
@@ -737,8 +736,12 @@
       it = response.filterOptions.find("IndexField");
       if (it!=end) {
-	if (args["qto"]=="2" || args["qt"]=="1") { // form search
-	  set_option_macro ("fqf", args["fqf"], true, true, (*it).second, disp);
-	} else {
-	  set_option_macro ("fqf", args["fqf"], true, false, (*it).second, disp);
+	bool form_search = false;
+	if (args["qto"]=="2" || args["qt"]=="1") { 
+	  form_search = true;
+	}
+	set_option_macro ("fqf", args["fqf"], true, form_search, (*it).second, disp);
+	if (args["ct"] == "2") {// lucene
+	  // set the sort field macro
+	  set_sfselection_macro(args["sf"], (*it).second, disp);
 	}
       }
@@ -746,5 +749,45 @@
   }
 } // define external macros
-    
+  
+void queryaction::set_sfselection_macro(text_t current_value, 
+				       const FilterOption_t &option, 
+				       displayclass &disp) {
+
+  // we need two or more options to continue
+  if (option.validValues.size() <= 2) {
+    return;
+  }
+
+  text_t macrovalue = "<select name=\"sf\">\n";
+  
+  if (current_value.empty()) current_value = "";
+  
+  // we give a rank option first
+  macrovalue += "<option value=\"\"";
+  if (current_value == "") {
+    macrovalue += " selected";
+  }
+  macrovalue += ">_query:textsortbyrank_\n";
+
+  text_tarray::const_iterator thisvalue = option.validValues.begin();
+  text_tarray::const_iterator endvalue = option.validValues.end();
+  int valid_count = 0;
+  while (thisvalue != endvalue) {
+    if (*thisvalue != "ZZ" && *thisvalue != "TX") {
+      ++valid_count;
+      macrovalue += "<option value=\"by" + *thisvalue + "\"";
+      if (current_value == "by"+*thisvalue)
+	macrovalue += " selected";
+      macrovalue += ">_" + *thisvalue + "_\n";
+    }
+    ++thisvalue;
+  }
+  macrovalue += "</select>";
+  if (valid_count > 0) {
+    disp.setmacro ("sfselection", displayclass::defaultpackage, macrovalue);
+  }
+  
+}
+ 
 // sets the selection box macro _gformselection_.
 // the default for _gformselection_ is _gselection_
@@ -809,12 +852,11 @@
     return; // dont need these macros
 
-  // mgpp & form query only needs the macros defined
   text_t form = "";
   int argfqn = args.getintarg("fqn");
   
   if (args["b"] == "1") { // advanced form
-    form += "<tr>_firstadvformelement_</tr>\n";
+    form += "_firstadvformelement_\n";
     for (int i=1; i<argfqn; ++i) {      
-	form += "<tr>_advformelement_</tr>\n";
+	form += "_advformelement_\n";
     }
     disp.setmacro("advformlist", "query", form);
@@ -822,5 +864,5 @@
   else { // simple form
     for (int i=0; i<argfqn; ++i) {
-      form += "<tr>_regformelement_</tr>\n"; 
+      form += "_regformelement_\n"; 
     }
     disp.setmacro("regformlist", "query", form);
@@ -1365,5 +1407,5 @@
   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!
@@ -1452,5 +1494,6 @@
     format_querystring (formattedstring, args.getintarg("b"), segment);
     if (args["ct"]!=0) { // mgpp and lucene - need to add in tag info if appropriate
-      format_field_info(formattedstring, args);
+      format_field_info(formattedstring, args["fqf"], args.getintarg("ct"), 
+			args.getintarg("t"), args.getintarg("b"));
     }
 
@@ -1468,8 +1511,8 @@
     else { // form search
       if (args["b"]=="0") { // regular form
-	parse_reg_query_form(formattedstring, args);
+	parse_reg_query_form(formattedstring, args, segment);
       }
       else  { // advanced form
-	parse_adv_query_form(formattedstring, args);
+	parse_adv_query_form(formattedstring, args, segment);
       }
       args["q"] = formattedstring;
