implemented advanced search history feature

This commit is contained in:
Jean-Francois Dockes
2012-10-16 13:37:56 +02:00
parent 9ccb862666
commit 816980a1c4
20 changed files with 736 additions and 97 deletions
+108
View File
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
#include "xapian.h"
@@ -44,6 +45,7 @@ using namespace std;
#include "synfamily.h"
#include "stemdb.h"
#include "expansiondbs.h"
#include "base64.h"
namespace Rcl {
@@ -253,6 +255,112 @@ bool SearchData::clausesToQuery(Rcl::Db &db, SClType tp,
return true;
}
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 << "<SD>" << endl;
// Clause list
os << "<CL>" << endl;
if (m_tp != SCLT_AND)
os << "<CLT>" << tpToString(m_tp) << "</CLT>" << 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<SearchDataClauseSimple*>(c);
os << "<C>" << endl;
if (cl->getTp() != SCLT_AND) {
os << "<CT>" << tpToString(cl->getTp()) << "</CT>" << endl;
}
if (cl->getTp() != SCLT_FILENAME && !cl->getfield().empty()) {
os << "<F>" << base64_encode(cl->getfield()) << "</F>" << endl;
}
os << "<T>" << base64_encode(cl->gettext()) << "</T>" << endl;
if (cl->getTp() == SCLT_NEAR || cl->getTp() == SCLT_PHRASE) {
SearchDataClauseDist *cld =
dynamic_cast<SearchDataClauseDist*>(cl);
os << "<S>" << cld->getslack() << "</S>" << endl;
}
os << "</C>" << endl;
}
os << "</CL>" << endl;
if (m_haveDates) {
if (m_dates.y1 > 0) {
os << "<DMI>" <<
"<D>" << m_dates.d1 << "</D>" <<
"<M>" << m_dates.m1 << "</M>" <<
"<Y>" << m_dates.y1 << "</Y>"
<< "</DMI>" << endl;
}
if (m_dates.y2 > 0) {
os << "<DMA>" <<
"<D>" << m_dates.d2 << "</D>" <<
"<M>" << m_dates.m2 << "</M>" <<
"<Y>" << m_dates.y2 << "</Y>"
<< "</DMA>" << endl;
}
}
if (m_minSize != size_t(-1)) {
os << "<MIS>" << m_minSize << "</MIS>" << endl;
}
if (m_maxSize != size_t(-1)) {
os << "<MAS>" << m_maxSize << "</MAS>" << endl;
}
if (!m_filetypes.empty()) {
os << "<ST>";
for (vector<string>::iterator it = m_filetypes.begin();
it != m_filetypes.end(); it++) {
os << *it << " ";
}
os << "</ST>" << endl;
}
if (!m_nfiletypes.empty()) {
os << "<IT>";
for (vector<string>::iterator it = m_nfiletypes.begin();
it != m_nfiletypes.end(); it++) {
os << *it << " ";
}
os << "</IT>" << endl;
}
for (vector<DirSpec>::const_iterator dit = m_dirspecs.begin();
dit != m_dirspecs.end(); dit++) {
if (dit->exclude) {
os << "<ND>" << base64_encode(dit->dir) << "</ND>" << endl;
} else {
os << "<YD>" << base64_encode(dit->dir) << "</YD>" << endl;
}
}
os << "</SD>";
return os.str();
}
bool SearchData::toNativeQuery(Rcl::Db &db, void *d, int maxexp, int maxcl)
{
LOGDEB(("SearchData::toNativeQuery: stemlang [%s]\n", m_stemlang.c_str()));
+18 -1
View File
@@ -34,6 +34,7 @@
#include "hldata.h"
class RclConfig;
class AdvSearch;
namespace Rcl {
@@ -77,6 +78,12 @@ public:
if (m_tp != SCLT_OR && m_tp != SCLT_AND)
m_tp = SCLT_OR;
}
SearchData()
: m_tp(SCLT_AND), m_haveDates(false), m_maxSize(size_t(-1)),
m_minSize(size_t(-1)), m_haveWildCards(false), m_stemlang("english")
{
}
~SearchData() {erase();}
/** Make pristine */
@@ -136,6 +143,12 @@ public:
std::string getDescription() {return m_description;}
void setDescription(const std::string& d) {m_description = d;}
virtual string asXML();
void setTp(SClType tp)
{
m_tp = tp;
}
friend class ::AdvSearch;
private:
// Combine type. Only SCLT_AND or SCLT_OR here
SClType m_tp;
@@ -196,7 +209,7 @@ public:
virtual std::string getReason() const {return m_reason;}
virtual void getTerms(HighlightData & hldata) const = 0;
SClType getTp()
SClType getTp() const
{
return m_tp;
}
@@ -326,6 +339,10 @@ public:
}
virtual bool toNativeQuery(Rcl::Db &, void *, int maxexp, int maxcl);
virtual int getslack() const
{
return m_slack;
}
private:
int m_slack;
};