Implement the gui category filters as query language fragments instead of hard-coding them. This allows implementing other kinds of filtering (ie:on directory) just by changing a configuration file
This commit is contained in:
@@ -62,7 +62,7 @@ bool DocSource::buildStack()
|
||||
} else {
|
||||
if (m_fspec.isNotNull()) {
|
||||
m_seq =
|
||||
RefCntr<DocSequence>(new DocSeqFiltered(m_seq, m_fspec));
|
||||
RefCntr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -49,7 +49,7 @@ class DocSeqSortSpec {
|
||||
class DocSeqFiltSpec {
|
||||
public:
|
||||
DocSeqFiltSpec() {}
|
||||
enum Crit {DSFS_MIMETYPE};
|
||||
enum Crit {DSFS_MIMETYPE, DSFS_QLANG, DSFS_PASSALL};
|
||||
void orCrit(Crit crit, const string& value) {
|
||||
crits.push_back(crit);
|
||||
values.push_back(value);
|
||||
@@ -191,12 +191,13 @@ protected:
|
||||
RefCntr<DocSequence> m_seq;
|
||||
};
|
||||
|
||||
class RclConfig;
|
||||
// A DocSource can juggle docseqs of different kinds to implement
|
||||
// sorting and filtering in ways depending on the base seqs capabilities
|
||||
class DocSource : public DocSeqModifier {
|
||||
public:
|
||||
DocSource(RefCntr<DocSequence> iseq)
|
||||
: DocSeqModifier(iseq)
|
||||
DocSource(RclConfig *config, RefCntr<DocSequence> iseq)
|
||||
: DocSeqModifier(iseq), m_config(config)
|
||||
{}
|
||||
virtual bool canFilter() {return true;}
|
||||
virtual bool canSort() {return true;}
|
||||
@@ -218,6 +219,7 @@ public:
|
||||
private:
|
||||
bool buildStack();
|
||||
void stripStack();
|
||||
RclConfig *m_config;
|
||||
DocSeqFiltSpec m_fspec;
|
||||
DocSeqSortSpec m_sspec;
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "rcldb.h"
|
||||
#include "debuglog.h"
|
||||
#include "internfile.h"
|
||||
#include "wasatorcl.h"
|
||||
|
||||
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
|
||||
RefCntr<Rcl::SearchData> sdata)
|
||||
@@ -126,6 +127,26 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
|
||||
switch (fs.crits[i]) {
|
||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
||||
m_fsdata->addFiletype(fs.values[i]);
|
||||
break;
|
||||
case DocSeqFiltSpec::DSFS_QLANG:
|
||||
{
|
||||
if (m_q.isNull())
|
||||
break;
|
||||
|
||||
string reason;
|
||||
Rcl::SearchData *sd =
|
||||
wasaStringToRcl(m_q->whatDb()->getConf(),
|
||||
fs.values[i], reason);
|
||||
if (sd) {
|
||||
Rcl::SearchDataClauseSub *cl1 =
|
||||
new Rcl::SearchDataClauseSub(Rcl::SCLT_SUB,
|
||||
RefCntr<Rcl::SearchData>(sd));
|
||||
m_fsdata->addClause(cl1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_isFiltered = true;
|
||||
|
||||
+54
-6
@@ -14,39 +14,87 @@
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "filtseq.h"
|
||||
#include "rclconfig.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
|
||||
{
|
||||
LOGDEB2((" Filter: ncrits %d\n", fs.crits.size()));
|
||||
// Compare using each criterion in term. We're doing an or:
|
||||
// 1st ok ends
|
||||
for (unsigned int i = 0; i < fs.crits.size(); i++) {
|
||||
switch (fs.crits[i]) {
|
||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
||||
LOGDEB1((" MIMETYPE\n"));
|
||||
LOGDEB2((" filter: MIMETYPE: me [%s] doc [%s]\n",
|
||||
fs.values[i].c_str(), x->mimetype.c_str()));
|
||||
if (x->mimetype == fs.values[i])
|
||||
return 1;
|
||||
return true;
|
||||
break;
|
||||
case DocSeqFiltSpec::DSFS_QLANG:
|
||||
{
|
||||
LOGDEB((" filter: QLANG [%s]!!\n", fs.values[i].c_str()));
|
||||
}
|
||||
break;
|
||||
case DocSeqFiltSpec::DSFS_PASSALL:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Did all comparisons
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
DocSeqFiltered::DocSeqFiltered(RclConfig *conf, RefCntr<DocSequence> iseq,
|
||||
DocSeqFiltSpec &filtspec)
|
||||
: DocSeqModifier(iseq), m_config(conf)
|
||||
{
|
||||
setFiltSpec(filtspec);
|
||||
}
|
||||
|
||||
bool DocSeqFiltered::setFiltSpec(DocSeqFiltSpec &filtspec)
|
||||
{
|
||||
m_spec = filtspec;
|
||||
LOGDEB0(("DocSeqFiltered::setFiltSpec\n"));
|
||||
for (unsigned int i = 0; i < filtspec.crits.size(); i++) {
|
||||
switch (filtspec.crits[i]) {
|
||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
||||
m_spec.orCrit(filtspec.crits[i], filtspec.values[i]);
|
||||
break;
|
||||
case DocSeqFiltSpec::DSFS_QLANG:
|
||||
{
|
||||
// There are very few lang constructs that we can
|
||||
// interpret. The default config uses rclcat:value
|
||||
// only. That will be all for now...
|
||||
string val = filtspec.values[i];
|
||||
if (val.find("rclcat:") == 0) {
|
||||
string catg = val.substr(7);
|
||||
list<string> tps;
|
||||
m_config->getMimeCatTypes(catg, tps);
|
||||
for (list<string>::const_iterator it = tps.begin();
|
||||
it != tps.end(); it++) {
|
||||
LOGDEB2(("Adding mime: [%s]\n", it->c_str()));
|
||||
m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If m_spec ends up empty, pass everything, better than filtering all.
|
||||
if (m_spec.crits.empty()) {
|
||||
m_spec.orCrit(DocSeqFiltSpec::DSFS_PASSALL, "");
|
||||
}
|
||||
m_dbindices.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
|
||||
{
|
||||
LOGDEB1(("DocSeqFiltered: fetching %d\n", idx));
|
||||
LOGDEB2(("DocSeqFiltered::getDoc() fetching %d\n", idx));
|
||||
|
||||
if (idx >= (int)m_dbindices.size()) {
|
||||
// Have to fetch docs and filter until we get enough or
|
||||
|
||||
+8
-5
@@ -19,10 +19,13 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
#include "refcntr.h"
|
||||
#include "docseq.h"
|
||||
|
||||
class RclConfig;
|
||||
|
||||
/**
|
||||
* A filtered sequence is created from another one by selecting entries
|
||||
@@ -30,17 +33,17 @@
|
||||
*/
|
||||
class DocSeqFiltered : public DocSeqModifier {
|
||||
public:
|
||||
DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec)
|
||||
: DocSeqModifier(iseq), m_spec(filtspec)
|
||||
{}
|
||||
DocSeqFiltered(RclConfig *conf, RefCntr<DocSequence> iseq,
|
||||
DocSeqFiltSpec &filtspec);
|
||||
virtual ~DocSeqFiltered() {}
|
||||
virtual bool canFilter() {return true;}
|
||||
virtual bool setFiltSpec(DocSeqFiltSpec &filtspec);
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
|
||||
virtual int getResCnt() {return m_seq->getResCnt();}
|
||||
private:
|
||||
DocSeqFiltSpec m_spec;
|
||||
vector<int> m_dbindices;
|
||||
RclConfig *m_config;
|
||||
DocSeqFiltSpec m_spec;
|
||||
vector<int> m_dbindices;
|
||||
};
|
||||
|
||||
#endif /* _FILTSEQ_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user