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:
parent
fab69fc3a1
commit
ef00bfae70
@ -576,6 +576,24 @@ string RclConfig::getMimeHandlerDef(const string &mtype, bool filtertypes)
|
|||||||
return hs;
|
return hs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RclConfig::getGuiFilterNames(list<string>& cats)
|
||||||
|
{
|
||||||
|
if (!mimeconf)
|
||||||
|
return false;
|
||||||
|
cats = mimeconf->getNamesShallow("guifilters");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RclConfig::getGuiFilter(const string& catfiltername, string& frag)
|
||||||
|
{
|
||||||
|
frag.clear();
|
||||||
|
if (!mimeconf)
|
||||||
|
return false;
|
||||||
|
if (!mimeconf->get(catfiltername, frag, "guifilters"))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool RclConfig::valueSplitAttributes(const string& whole, string& value,
|
bool RclConfig::valueSplitAttributes(const string& whole, string& value,
|
||||||
ConfSimple& attrs)
|
ConfSimple& attrs)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -202,6 +202,11 @@ class RclConfig {
|
|||||||
/** mimeconf: get list of mime types for category */
|
/** mimeconf: get list of mime types for category */
|
||||||
bool getMimeCatTypes(const string& cat, list<string>&);
|
bool getMimeCatTypes(const string& cat, list<string>&);
|
||||||
|
|
||||||
|
/** mimeconf: get list of gui filters (doc cats by default */
|
||||||
|
bool getGuiFilterNames(list<string>&);
|
||||||
|
/** mimeconf: get query lang frag for named filter */
|
||||||
|
bool getGuiFilter(const string& filtername, string& frag);
|
||||||
|
|
||||||
/** fields: get field prefix from field name */
|
/** fields: get field prefix from field name */
|
||||||
bool getFieldTraits(const string& fldname, const FieldTraits **);
|
bool getFieldTraits(const string& fldname, const FieldTraits **);
|
||||||
const set<string>& getStoredFields() {return m_storedFields;}
|
const set<string>& getStoredFields() {return m_storedFields;}
|
||||||
|
|||||||
@ -176,7 +176,7 @@ void RclMain::init()
|
|||||||
connect(bgrp, SIGNAL(buttonClicked(int)), this, SLOT(catgFilter(int)));
|
connect(bgrp, SIGNAL(buttonClicked(int)), this, SLOT(catgFilter(int)));
|
||||||
allRDB->setChecked(true);
|
allRDB->setChecked(true);
|
||||||
list<string> cats;
|
list<string> cats;
|
||||||
theconfig->getMimeCategories(cats);
|
theconfig->getGuiFilterNames(cats);
|
||||||
// Text for button 0 is not used. Next statement just avoids unused
|
// Text for button 0 is not used. Next statement just avoids unused
|
||||||
// variable compiler warning for catg_strings
|
// variable compiler warning for catg_strings
|
||||||
m_catgbutvec.push_back(catg_strings[0]);
|
m_catgbutvec.push_back(catg_strings[0]);
|
||||||
@ -1626,7 +1626,7 @@ void RclMain::showDocHistory()
|
|||||||
new DocSequenceHistory(rcldb, g_dynconf,
|
new DocSequenceHistory(rcldb, g_dynconf,
|
||||||
string(tr("Document history").toUtf8()));
|
string(tr("Document history").toUtf8()));
|
||||||
src->setDescription((const char *)tr("History data").toUtf8());
|
src->setDescription((const char *)tr("History data").toUtf8());
|
||||||
DocSource *source = new DocSource(RefCntr<DocSequence>(src));
|
DocSource *source = new DocSource(theconfig, RefCntr<DocSequence>(src));
|
||||||
m_source = RefCntr<DocSequence>(source);
|
m_source = RefCntr<DocSequence>(source);
|
||||||
m_source->setSortSpec(m_sortspec);
|
m_source->setSortSpec(m_sortspec);
|
||||||
m_source->setFiltSpec(m_filtspec);
|
m_source->setFiltSpec(m_filtspec);
|
||||||
@ -1695,7 +1695,8 @@ void RclMain::showQueryDetails()
|
|||||||
return;
|
return;
|
||||||
string oq = breakIntoLines(m_source->getDescription(), 100, 50);
|
string oq = breakIntoLines(m_source->getDescription(), 100, 50);
|
||||||
QString str;
|
QString str;
|
||||||
QString desc = tr("Result count (est.)") + ": " + str.setNum(m_source->getResCnt()) + "<br>";
|
QString desc = tr("Result count (est.)") + ": " +
|
||||||
|
str.setNum(m_source->getResCnt()) + "<br>";
|
||||||
desc += tr("Query details") + ": " + QString::fromUtf8(oq.c_str());
|
desc += tr("Query details") + ": " + QString::fromUtf8(oq.c_str());
|
||||||
QMessageBox::information(this, tr("Query details"), desc);
|
QMessageBox::information(this, tr("Query details"), desc);
|
||||||
}
|
}
|
||||||
@ -1711,12 +1712,11 @@ void RclMain::catgFilter(int id)
|
|||||||
|
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
string catg = m_catgbutvec[id];
|
string catg = m_catgbutvec[id];
|
||||||
list<string> tps;
|
string frag;
|
||||||
theconfig->getMimeCatTypes(catg, tps);
|
theconfig->getGuiFilter(catg, frag);
|
||||||
for (list<string>::const_iterator it = tps.begin();
|
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_QLANG, frag);
|
||||||
it != tps.end(); it++)
|
|
||||||
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
|
|
||||||
}
|
}
|
||||||
|
LOGDEB(("RclMain::catgFilter: calling setFiltSpec\n"));
|
||||||
if (m_source.isNotNull())
|
if (m_source.isNotNull())
|
||||||
m_source->setFiltSpec(m_filtspec);
|
m_source->setFiltSpec(m_filtspec);
|
||||||
initiateQuery();
|
initiateQuery();
|
||||||
|
|||||||
@ -315,7 +315,7 @@ extern "C" int XFlush(void *);
|
|||||||
void ResList::setDocSource(RefCntr<DocSequence> nsource)
|
void ResList::setDocSource(RefCntr<DocSequence> nsource)
|
||||||
{
|
{
|
||||||
LOGDEB(("ResList::setDocSource()\n"));
|
LOGDEB(("ResList::setDocSource()\n"));
|
||||||
m_source = RefCntr<DocSequence>(new DocSource(nsource));
|
m_source = RefCntr<DocSequence>(new DocSource(theconfig, nsource));
|
||||||
}
|
}
|
||||||
|
|
||||||
// A query was executed, or the filtering/sorting parameters changed,
|
// A query was executed, or the filtering/sorting parameters changed,
|
||||||
|
|||||||
@ -298,7 +298,7 @@ void RecollModel::setDocSource(RefCntr<DocSequence> nsource)
|
|||||||
if (nsource.isNull()) {
|
if (nsource.isNull()) {
|
||||||
m_source = RefCntr<DocSequence>();
|
m_source = RefCntr<DocSequence>();
|
||||||
} else {
|
} else {
|
||||||
m_source = RefCntr<DocSequence>(new DocSource(nsource));
|
m_source = RefCntr<DocSequence>(new DocSource(theconfig, nsource));
|
||||||
m_hdata.reset();
|
m_hdata.reset();
|
||||||
m_source->getTerms(m_hdata.terms, m_hdata.groups, m_hdata.gslks);
|
m_source->getTerms(m_hdata.terms, m_hdata.groups, m_hdata.gslks);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ bool DocSource::buildStack()
|
|||||||
} else {
|
} else {
|
||||||
if (m_fspec.isNotNull()) {
|
if (m_fspec.isNotNull()) {
|
||||||
m_seq =
|
m_seq =
|
||||||
RefCntr<DocSequence>(new DocSeqFiltered(m_seq, m_fspec));
|
RefCntr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class DocSeqSortSpec {
|
|||||||
class DocSeqFiltSpec {
|
class DocSeqFiltSpec {
|
||||||
public:
|
public:
|
||||||
DocSeqFiltSpec() {}
|
DocSeqFiltSpec() {}
|
||||||
enum Crit {DSFS_MIMETYPE};
|
enum Crit {DSFS_MIMETYPE, DSFS_QLANG, DSFS_PASSALL};
|
||||||
void orCrit(Crit crit, const string& value) {
|
void orCrit(Crit crit, const string& value) {
|
||||||
crits.push_back(crit);
|
crits.push_back(crit);
|
||||||
values.push_back(value);
|
values.push_back(value);
|
||||||
@ -191,12 +191,13 @@ protected:
|
|||||||
RefCntr<DocSequence> m_seq;
|
RefCntr<DocSequence> m_seq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RclConfig;
|
||||||
// A DocSource can juggle docseqs of different kinds to implement
|
// A DocSource can juggle docseqs of different kinds to implement
|
||||||
// sorting and filtering in ways depending on the base seqs capabilities
|
// sorting and filtering in ways depending on the base seqs capabilities
|
||||||
class DocSource : public DocSeqModifier {
|
class DocSource : public DocSeqModifier {
|
||||||
public:
|
public:
|
||||||
DocSource(RefCntr<DocSequence> iseq)
|
DocSource(RclConfig *config, RefCntr<DocSequence> iseq)
|
||||||
: DocSeqModifier(iseq)
|
: DocSeqModifier(iseq), m_config(config)
|
||||||
{}
|
{}
|
||||||
virtual bool canFilter() {return true;}
|
virtual bool canFilter() {return true;}
|
||||||
virtual bool canSort() {return true;}
|
virtual bool canSort() {return true;}
|
||||||
@ -218,6 +219,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool buildStack();
|
bool buildStack();
|
||||||
void stripStack();
|
void stripStack();
|
||||||
|
RclConfig *m_config;
|
||||||
DocSeqFiltSpec m_fspec;
|
DocSeqFiltSpec m_fspec;
|
||||||
DocSeqSortSpec m_sspec;
|
DocSeqSortSpec m_sspec;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include "rcldb.h"
|
#include "rcldb.h"
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "internfile.h"
|
#include "internfile.h"
|
||||||
|
#include "wasatorcl.h"
|
||||||
|
|
||||||
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
|
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
|
||||||
RefCntr<Rcl::SearchData> sdata)
|
RefCntr<Rcl::SearchData> sdata)
|
||||||
@ -126,6 +127,26 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
|
|||||||
switch (fs.crits[i]) {
|
switch (fs.crits[i]) {
|
||||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
||||||
m_fsdata->addFiletype(fs.values[i]);
|
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;
|
m_isFiltered = true;
|
||||||
|
|||||||
@ -14,39 +14,87 @@
|
|||||||
* Free Software Foundation, Inc.,
|
* Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "filtseq.h"
|
#include "filtseq.h"
|
||||||
|
#include "rclconfig.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
|
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:
|
// Compare using each criterion in term. We're doing an or:
|
||||||
// 1st ok ends
|
// 1st ok ends
|
||||||
for (unsigned int i = 0; i < fs.crits.size(); i++) {
|
for (unsigned int i = 0; i < fs.crits.size(); i++) {
|
||||||
switch (fs.crits[i]) {
|
switch (fs.crits[i]) {
|
||||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
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])
|
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
|
// 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)
|
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();
|
m_dbindices.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
|
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()) {
|
if (idx >= (int)m_dbindices.size()) {
|
||||||
// Have to fetch docs and filter until we get enough or
|
// Have to fetch docs and filter until we get enough or
|
||||||
|
|||||||
@ -19,10 +19,13 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
#include "refcntr.h"
|
#include "refcntr.h"
|
||||||
#include "docseq.h"
|
#include "docseq.h"
|
||||||
|
|
||||||
|
class RclConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filtered sequence is created from another one by selecting entries
|
* A filtered sequence is created from another one by selecting entries
|
||||||
@ -30,17 +33,17 @@
|
|||||||
*/
|
*/
|
||||||
class DocSeqFiltered : public DocSeqModifier {
|
class DocSeqFiltered : public DocSeqModifier {
|
||||||
public:
|
public:
|
||||||
DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec)
|
DocSeqFiltered(RclConfig *conf, RefCntr<DocSequence> iseq,
|
||||||
: DocSeqModifier(iseq), m_spec(filtspec)
|
DocSeqFiltSpec &filtspec);
|
||||||
{}
|
|
||||||
virtual ~DocSeqFiltered() {}
|
virtual ~DocSeqFiltered() {}
|
||||||
virtual bool canFilter() {return true;}
|
virtual bool canFilter() {return true;}
|
||||||
virtual bool setFiltSpec(DocSeqFiltSpec &filtspec);
|
virtual bool setFiltSpec(DocSeqFiltSpec &filtspec);
|
||||||
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
|
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
|
||||||
virtual int getResCnt() {return m_seq->getResCnt();}
|
virtual int getResCnt() {return m_seq->getResCnt();}
|
||||||
private:
|
private:
|
||||||
DocSeqFiltSpec m_spec;
|
RclConfig *m_config;
|
||||||
vector<int> m_dbindices;
|
DocSeqFiltSpec m_spec;
|
||||||
|
vector<int> m_dbindices;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _FILTSEQ_H_INCLUDED_ */
|
#endif /* _FILTSEQ_H_INCLUDED_ */
|
||||||
|
|||||||
@ -194,7 +194,12 @@ text/x-purple-html-log = pidgin
|
|||||||
text/x-python = text-x-python
|
text/x-python = text-x-python
|
||||||
|
|
||||||
[categories]
|
[categories]
|
||||||
|
# Categories group mime types by "kind". They can be used from the query
|
||||||
|
# language as an "rclcat" clause. This is fully dynamic, you can change the
|
||||||
|
# names and groups as you wish, only the mime types are stored in the index.
|
||||||
|
#
|
||||||
|
# If you add/remove categories, you may also want to change the
|
||||||
|
# "guifilters" section below.
|
||||||
text = \
|
text = \
|
||||||
application/msword \
|
application/msword \
|
||||||
application/pdf \
|
application/pdf \
|
||||||
@ -280,3 +285,26 @@ other = application/vnd.sun.xml.draw \
|
|||||||
application/x-rar \
|
application/x-rar \
|
||||||
application/x-webarchive \
|
application/x-webarchive \
|
||||||
application/zip \
|
application/zip \
|
||||||
|
|
||||||
|
[guifilters]
|
||||||
|
# This defines the top level filters in the GUI (accessed by the the
|
||||||
|
# radiobuttons above the results area, or a toolbar combobox).
|
||||||
|
# Each entry defines a label and a query language fragment that will be
|
||||||
|
# applied to filter the current query if the option is activated.
|
||||||
|
#
|
||||||
|
# This does not really belong in mimeconf, but it does belong in the index
|
||||||
|
# config (not the GUI one), because it's not necessarily the same in all
|
||||||
|
# configs, it has to go somewhere, and it's not worth a separate config
|
||||||
|
# file...
|
||||||
|
#
|
||||||
|
# By default this filters by document category (see above), but any
|
||||||
|
# language fragment should be ok. Be aware though that the "document
|
||||||
|
# history" queries only know about simple "rclcat" filtering.
|
||||||
|
|
||||||
|
text = rclcat:text
|
||||||
|
spreadsheet = rclcat:spreadsheet
|
||||||
|
presentation = rclcat:presentation
|
||||||
|
media = rclcat:media
|
||||||
|
message = rclcat:message
|
||||||
|
other = rclcat:other
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user