Index: trunk/gsdl/src/recpt/querytools.cpp
===================================================================
--- trunk/gsdl/src/recpt/querytools.cpp	(revision 11986)
+++ trunk/gsdl/src/recpt/querytools.cpp	(revision 11987)
@@ -28,4 +28,59 @@
 #include "unitool.h" // for is_unicode_letdig
 
+void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args) {
+
+  if (args["ct"].empty()) {
+    text_t build_type = cinfo->buildType;
+    if (build_type == "mgpp") {
+      args["ct"] = "1";
+    } else if (build_type == "lucene") {
+      args["ct"] = "2";
+    } else {
+      args["ct"] = "0";
+    }
+  }
+  text_t arg_ct = args["ct"];
+  if (arg_ct == "0") {
+    // mg
+    args["qt"] = "0";
+    args["qto"] = "0";
+    return;
+  }
+
+  if (!args["qt"].empty() && !args["qto"].empty()) {
+    return;
+  }
+  
+  text_tmap::iterator check = cinfo->format.find("SearchTypes");
+  text_t search_types = "plain,form";
+  if(check != cinfo->format.end()){
+    search_types = (*check).second;
+    if (search_types.empty()) {
+      search_types = "plain,form";
+    }
+  }
+  
+  if (args["qto"].empty()) {
+    unsigned int type = 0;
+    if (findword(search_types.begin(), search_types.end(), "form") != search_types.end()) {
+      type |= 2;
+    }
+    if (findword(search_types.begin(), search_types.end(), "plain") != search_types.end()) {
+      type |= 1;
+    }
+    args.setintarg("qto", type);
+  } 
+  
+  if (args["qt"].empty()) {
+    bool form_default = false;
+    int arg_qto = args.getintarg("qto");
+    if (arg_qto == 2 || (arg_qto == 3 && starts_with(search_types, "form"))) {
+      args["qt"] = "1";
+    } else {
+      args["qt"] = "0";
+    }
+  }
+}
+
 // request.filterResultOptions and request.fields (if required) should
 // be set from the calling code
@@ -157,4 +212,17 @@
   //  option.value = endresults;
   //  request.filterOptions.push_back (option);
+}
+
+bool is_special_character(int indexer_type, unsigned short character) {
+  // mgpp
+  if (indexer_type == 1) {
+    return (character == '#' || character == '/' || character == '*');
+  }
+  // lucene
+  else if (indexer_type ==2) {
+    return (character == '?' || character == '*' || character == '~' || 
+	    character == '^');
+  }
+  return false;
 }
 
@@ -386,5 +454,5 @@
 	}
       }
-      text_t term = addstemcase(values[i], stems[i], folds[i]);
+      text_t term = addstemcase(values[i], stems[i], folds[i], ct);
       mgpp_addqueryelem(querystring, fields[i], term, combine);
     }
@@ -393,5 +461,6 @@
 }
 
-text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold) {
+text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold,
+		   const int indexer_type) {
   
   text_t outtext;
@@ -403,5 +472,5 @@
   while (here !=end) {
 
-    if (is_unicode_letdig(*here)) {
+    if (is_unicode_letdig(*here) || is_special_character(indexer_type, *here)) {
       // not word boundary
       word.push_back(*here);
@@ -598,16 +667,4 @@
 }
 
-bool is_special_character(int indexer_type, unsigned short character) {
-  // mgpp
-  if (indexer_type == 1) {
-    return (character == '#' || character == '/' || character == '*');
-  }
-  // lucene
-  else if (indexer_type ==2) {
-    return (character == '?' || character == '*' || character == '~' || 
-	    character == '^');
-  }
-  return false;
-}
 
 void format_field_info_lucene(text_t &querystring, cgiargsclass &args) {
@@ -691,5 +748,4 @@
 
 void format_field_info_mgpp(text_t &querystring, cgiargsclass &args) {
-  
   text_t tag = args["fqf"];
   if (tag == "ZZ") tag = ""; // ZZ is a special tag meaning no tag (all fields)
Index: trunk/gsdl/src/recpt/querytools.h
===================================================================
--- trunk/gsdl/src/recpt/querytools.h	(revision 11986)
+++ trunk/gsdl/src/recpt/querytools.h	(revision 11987)
@@ -30,4 +30,6 @@
 #include "cgiargs.h"
 #include "recptproto.h"
+
+void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args);
 
 void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring,
@@ -64,5 +66,6 @@
 		     const text_t &terms, const text_t &stem, const text_t &fold,
 		     const text_t& combine, const text_t& word_combine);
-text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold);
+text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold,
+		   const int indexer_type);
 text_t formatelem(text_t &text);
 void format_field_info(text_t &querystring, cgiargsclass &args);
