--- a/src/qtgui/ssearch_w.cpp
+++ b/src/qtgui/ssearch_w.cpp
@@ -14,6 +14,9 @@
  *   Free Software Foundation, Inc.,
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
+#include <sstream>
+#include <set>
+
 #include <qapplication.h>
 #include <qinputdialog.h>
 #include <qvariant.h>
@@ -35,6 +38,10 @@
 #include "textsplit.h"
 #include "wasatorcl.h"
 #include "rclhelp.h"
+#include "xmltosd.h"
+#include "smallut.h"
+
+using namespace std;
 
 // Typing interval after which we consider starting autosearch: no sense to do
 // this is user is typing fast and continuously
@@ -226,21 +233,36 @@
     }
 }
 
+string SSearch::asXML()
+{
+    return m_xml;
+}
+
 bool SSearch::startSimpleSearch(const string& u8, int maxexp)
 {
     LOGDEB(("SSearch::startSimpleSearch(%s)\n", u8.c_str()));
     string stemlang = prefs.stemlang();
 
+    ostringstream xml;
+    xml << "<SD type='ssearch'>\n";
+    xml << "  <SL>" << stemlang << "</SL>\n";
+    xml << "  <T>" << base64_encode(u8) << "</T>\n";
+
     SSearchType tp = (SSearchType)searchTypCMB->currentIndex();
     Rcl::SearchData *sdata = 0;
 
     if (tp == SST_LANG) {
+        xml << "  <SM>QL</SM>\n";
 	string reason;
-        if (prefs.autoSuffsEnable)
+        if (prefs.autoSuffsEnable) {
             sdata = wasaStringToRcl(theconfig, stemlang, u8, reason, 
 				    (const char *)prefs.autoSuffs.toUtf8());
-        else
+            if (!prefs.autoSuffs.isEmpty()) {
+                xml <<  "  <AS>" << qs2utf8s(prefs.autoSuffs) << "</AS>\n";
+            }
+        } else {
             sdata = wasaStringToRcl(theconfig, stemlang, u8, reason);
+        }
 	if (sdata == 0) {
 	    QMessageBox::warning(0, "Recoll", tr("Bad query string") + ": " +
 				 QString::fromUtf8(reason.c_str()));
@@ -254,12 +276,15 @@
 	}
 	Rcl::SearchDataClause *clp = 0;
 	if (tp == SST_FNM) {
+            xml << "  <SM>FN</SM>\n";
 	    clp = new Rcl::SearchDataClauseFilename(u8);
 	} else {
 	    // ANY or ALL, several words.
 	    if (tp == SST_ANY) {
+                xml << "  <SM>OR</SM>\n";
 		clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8);
 	    } else {
+                xml << "  <SM>AND</SM>\n";
 		clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8);
 	    }
 	}
@@ -267,14 +292,79 @@
     }
 
     if (prefs.ssearchAutoPhrase && rcldb) {
+        xml << "  <AP/>\n";
 	sdata->maybeAddAutoPhrase(*rcldb, 
 				  prefs.ssearchAutoPhraseThreshPC / 100.0);
     }
     if (maxexp != -1) {
 	sdata->setMaxExpand(maxexp);
     }
+
+    for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
+	 it != prefs.activeExtraDbs.end(); it++) {
+        xml << "  <EX>" << base64_encode(*it) << "</EX>";
+    }
+
+    xml << "</SD>\n";
+    m_xml = xml.str();
+    LOGDEB(("SSearch::startSimpleSearch:xml:[%s]\n", m_xml.c_str()));
+
     RefCntr<Rcl::SearchData> rsdata(sdata);
     emit startSearch(rsdata, true);
+    return true;
+}
+
+bool SSearch::fromXML(const SSearchDef& fxml)
+{
+    string asString;
+    set<string> cur;
+    set<string> stored;
+
+    // Retrieve current list of stemlangs. prefs returns a
+    // space-separated list Warn if stored differs from current,
+    // but don't change the latter.
+    stringToStrings(prefs.stemlang(), cur);
+    stored = set<string>(fxml.stemlangs.begin(), fxml.stemlangs.end());
+    stringsToString(fxml.stemlangs, asString);
+    if (cur != stored) {
+        QMessageBox::warning(
+            0, "Recoll", tr("Stemming languages for stored query: ") + 
+            QString::fromUtf8(asString.c_str()) + 
+            tr(" differ from current preferences (kept)"));
+    }
+
+    // Same for autosuffs
+    stringToStrings(qs2utf8s(prefs.autoSuffs), cur);
+    stored = set<string>(fxml.autosuffs.begin(), fxml.autosuffs.end());
+    stringsToString(fxml.stemlangs, asString);
+    if (cur != stored) {
+        QMessageBox::warning(
+            0, "Recoll", tr("Auto suffixes for stored query: ") + 
+            QString::fromUtf8(asString.c_str()) + 
+            tr(" differ from current preferences (kept)"));
+    }
+
+    cur = set<string>(prefs.activeExtraDbs.begin(), prefs.activeExtraDbs.end());
+    stored = set<string>(fxml.extindexes.begin(), fxml.extindexes.end());
+    stringsToString(fxml.extindexes, asString);
+    if (cur != stored) {
+        QMessageBox::warning(
+            0, "Recoll", tr("External indexes for stored query: ") + 
+            QString::fromUtf8(asString.c_str()) + 
+            tr(" differ from current preferences (kept)"));
+    }
+
+    if (prefs.ssearchAutoPhrase && !fxml.autophrase) {
+        QMessageBox::warning(
+            0, "Recoll", 
+            tr("Autophrase is set but it was unset for stored query"));
+    } else if (!prefs.ssearchAutoPhrase && fxml.autophrase) {
+        QMessageBox::warning(
+            0, "Recoll", 
+            tr("Autophrase is unset but it was set for stored query"));
+    }
+    setSearchString(QString::fromUtf8(fxml.text.c_str()));
+    searchTypCMB->setCurrentIndex(prefs.ssearchTyp);
     return true;
 }