/* Copyright (C) 2006 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Handle translation from rcl's SearchData structures to Xapian Queries #include "autoconfig.h" #include #include #include #include using namespace std; #include "searchdata.h" #include "debuglog.h" #include "base64.h" namespace Rcl { static string tpToString(SClType tp) { switch (tp) { case SCLT_AND: return "AND"; case SCLT_OR: return "OR"; case SCLT_EXCL: return "EX"; case SCLT_FILENAME: return "FN"; case SCLT_PHRASE: return "PH"; case SCLT_NEAR: return "NE"; case SCLT_SUB: return "SU"; // Unsupported actually default: return "UN"; } } string SearchData::asXML() { LOGDEB(("SearchData::asXML\n")); ostringstream os; // Searchdata os << "" << endl; // Clause list os << "" << endl; if (m_tp != SCLT_AND) os << "" << tpToString(m_tp) << "" << endl; for (unsigned int i = 0; i < m_query.size(); i++) { SearchDataClause *c = m_query[i]; if (c->getTp() == SCLT_SUB) { LOGERR(("SearchData::asXML: can't do subclauses !\n")); continue; } SearchDataClauseSimple *cl = dynamic_cast(c); os << "" << endl; if (cl->getTp() != SCLT_AND) { os << "" << tpToString(cl->getTp()) << "" << endl; } if (cl->getTp() != SCLT_FILENAME && !cl->getfield().empty()) { os << "" << base64_encode(cl->getfield()) << "" << endl; } os << "" << base64_encode(cl->gettext()) << "" << endl; if (cl->getTp() == SCLT_NEAR || cl->getTp() == SCLT_PHRASE) { SearchDataClauseDist *cld = dynamic_cast(cl); os << "" << cld->getslack() << "" << endl; } os << "" << endl; } os << "" << endl; if (m_haveDates) { if (m_dates.y1 > 0) { os << "" << "" << m_dates.d1 << "" << "" << m_dates.m1 << "" << "" << m_dates.y1 << "" << "" << endl; } if (m_dates.y2 > 0) { os << "" << "" << m_dates.d2 << "" << "" << m_dates.m2 << "" << "" << m_dates.y2 << "" << "" << endl; } } if (m_minSize != size_t(-1)) { os << "" << m_minSize << "" << endl; } if (m_maxSize != size_t(-1)) { os << "" << m_maxSize << "" << endl; } if (!m_filetypes.empty()) { os << ""; for (vector::iterator it = m_filetypes.begin(); it != m_filetypes.end(); it++) { os << *it << " "; } os << "" << endl; } if (!m_nfiletypes.empty()) { os << ""; for (vector::iterator it = m_nfiletypes.begin(); it != m_nfiletypes.end(); it++) { os << *it << " "; } os << "" << endl; } for (vector::const_iterator dit = m_dirspecs.begin(); dit != m_dirspecs.end(); dit++) { if (dit->exclude) { os << "" << base64_encode(dit->dir) << "" << endl; } else { os << "" << base64_encode(dit->dir) << "" << endl; } } os << ""; return os.str(); } }