indents etc.

This commit is contained in:
Jean-Francois Dockes 2021-04-23 09:07:20 +02:00
parent d207d4f1c5
commit 9abaf84be6
6 changed files with 41 additions and 53 deletions

View File

@ -81,8 +81,7 @@ bool DocSource::buildStack()
} }
} else { } else {
if (m_fspec.isNotNull()) { if (m_fspec.isNotNull()) {
m_seq = m_seq = std::shared_ptr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
std::shared_ptr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
} }
} }

View File

@ -31,14 +31,7 @@ using std::list;
DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Db> db, DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const string &t, std::shared_ptr<Rcl::Query> q, const string &t,
std::shared_ptr<Rcl::SearchData> sdata) std::shared_ptr<Rcl::SearchData> sdata)
: DocSequence(t), m_db(db), m_q(q), m_sdata(sdata), m_fsdata(sdata), : DocSequence(t), m_db(db), m_q(q), m_sdata(sdata), m_fsdata(sdata)
m_rescnt(-1),
m_queryBuildAbstract(true),
m_queryReplaceAbstract(false),
m_isFiltered(false),
m_isSorted(false),
m_needSetQuery(false),
m_lastSQStatus(true)
{ {
} }
@ -161,8 +154,7 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
std::unique_lock<std::mutex> locker(o_dblock); std::unique_lock<std::mutex> locker(o_dblock);
if (fs.isNotNull()) { if (fs.isNotNull()) {
// We build a search spec by adding a filtering layer to the base one. // We build a search spec by adding a filtering layer to the base one.
m_fsdata = std::make_shared<Rcl::SearchData>( m_fsdata = std::make_shared<Rcl::SearchData>(Rcl::SCLT_AND, m_sdata->getStemLang());
Rcl::SCLT_AND, m_sdata->getStemLang());
Rcl::SearchDataClauseSub *cl = new Rcl::SearchDataClauseSub(m_sdata); Rcl::SearchDataClauseSub *cl = new Rcl::SearchDataClauseSub(m_sdata);
m_fsdata->addClause(cl); m_fsdata->addClause(cl);
@ -171,22 +163,19 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
case DocSeqFiltSpec::DSFS_MIMETYPE: case DocSeqFiltSpec::DSFS_MIMETYPE:
m_fsdata->addFiletype(fs.values[i]); m_fsdata->addFiletype(fs.values[i]);
break; break;
case DocSeqFiltSpec::DSFS_QLANG: case DocSeqFiltSpec::DSFS_QLANG: {
{
if (!m_q) if (!m_q)
break; break;
string reason; string reason;
auto sd = wasaStringToRcl(m_q->whatDb()->getConf(), auto sd = wasaStringToRcl(
m_sdata->getStemLang(), m_q->whatDb()->getConf(), m_sdata->getStemLang(), fs.values[i], reason);
fs.values[i], reason);
if (sd) { if (sd) {
Rcl::SearchDataClauseSub *cl1 = Rcl::SearchDataClauseSub *cl1 = new Rcl::SearchDataClauseSub(sd);
new Rcl::SearchDataClauseSub(sd);
m_fsdata->addClause(cl1); m_fsdata->addClause(cl1);
} }
} }
break; break;
default: default:
break; break;
} }
@ -226,8 +215,7 @@ bool DocSequenceDb::setQuery()
m_lastSQStatus = m_q->setQuery(m_fsdata); m_lastSQStatus = m_q->setQuery(m_fsdata);
if (!m_lastSQStatus) { if (!m_lastSQStatus) {
m_reason = m_q->getReason(); m_reason = m_q->getReason();
LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " << LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " << m_reason << "\n");
m_reason << "\n");
} }
return m_lastSQStatus; return m_lastSQStatus;
} }
@ -241,4 +229,3 @@ bool DocSequenceDb::docDups(const Rcl::Doc& doc, std::vector<Rcl::Doc>& dups)
return false; return false;
} }
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2004 J.F.Dockes /* Copyright (C) 2004-2021 J.F.Dockes
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -25,10 +25,10 @@
/** A DocSequence from a Db query */ /** A DocSequence from a Db query */
class DocSequenceDb : public DocSequence { class DocSequenceDb : public DocSequence {
public: public:
DocSequenceDb(std::shared_ptr<Rcl::Db> db, DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const std::string &t, std::shared_ptr<Rcl::Query> q, const std::string &t,
std::shared_ptr<Rcl::SearchData> sdata); std::shared_ptr<Rcl::SearchData> sdata);
virtual ~DocSequenceDb() {} virtual ~DocSequenceDb() {}
virtual bool getDoc(int num, Rcl::Doc &doc, std::string * = 0) override; virtual bool getDoc(int num, Rcl::Doc &doc, std::string * = 0) override;
virtual int getResCnt() override; virtual int getResCnt() override;
@ -55,7 +55,7 @@ class DocSequenceDb : public DocSequence {
} }
virtual bool snippetsCapable() override { virtual bool snippetsCapable() override {
return true; return true;
} }
virtual std::string title() override; virtual std::string title() override;
@ -68,13 +68,13 @@ private:
std::shared_ptr<Rcl::Query> m_q; std::shared_ptr<Rcl::Query> m_q;
std::shared_ptr<Rcl::SearchData> m_sdata; std::shared_ptr<Rcl::SearchData> m_sdata;
std::shared_ptr<Rcl::SearchData> m_fsdata; // Filtered std::shared_ptr<Rcl::SearchData> m_fsdata; // Filtered
int m_rescnt; int m_rescnt{-1};
bool m_queryBuildAbstract; bool m_queryBuildAbstract{true};
bool m_queryReplaceAbstract; bool m_queryReplaceAbstract{false};
bool m_isFiltered; bool m_isFiltered{false};
bool m_isSorted; bool m_isSorted{false};
bool m_needSetQuery; // search data changed, need to reapply before fetch bool m_needSetQuery{false}; // search data changed, need to reapply before fetch
bool m_lastSQStatus; bool m_lastSQStatus{true};
bool setQuery(); bool setQuery();
}; };

View File

@ -125,31 +125,31 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
{ {
// Retrieve history list // Retrieve history list
if (!m_hist) if (!m_hist)
return false; return false;
if (m_history.empty()) if (m_history.empty())
m_history = getDocHistory(m_hist); m_history = getDocHistory(m_hist);
if (num < 0 || num >= (int)m_history.size()) if (num < 0 || num >= (int)m_history.size())
return false; return false;
// We get the history oldest first, but our users expect newest first // We get the history oldest first, but our users expect newest first
RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num]; RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num];
if (sh) { if (sh) {
if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) { if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) {
m_prevtime = hentry.unixtime; m_prevtime = hentry.unixtime;
time_t t = (time_t)(hentry.unixtime); time_t t = (time_t)(hentry.unixtime);
*sh = string(ctime(&t)); *sh = string(ctime(&t));
// Get rid of the final \n in ctime // Get rid of the final \n in ctime
sh->erase(sh->length()-1); sh->erase(sh->length()-1);
} else { } else {
sh->erase(); sh->erase();
} }
} }
bool ret = m_db->getDoc(hentry.udi, hentry.dbdir, doc); bool ret = m_db->getDoc(hentry.udi, hentry.dbdir, doc);
if (!ret || doc.pc == -1) { if (!ret || doc.pc == -1) {
doc.url = "UNKNOWN"; doc.url = "UNKNOWN";
doc.ipath = ""; doc.ipath = "";
} }
@ -163,7 +163,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
int DocSequenceHistory::getResCnt() int DocSequenceHistory::getResCnt()
{ {
if (m_history.empty()) if (m_history.empty())
m_history = getDocHistory(m_hist); m_history = getDocHistory(m_hist);
return int(m_history.size()); return int(m_history.size());
} }

View File

@ -36,7 +36,7 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
case DocSeqFiltSpec::DSFS_QLANG: { case DocSeqFiltSpec::DSFS_QLANG: {
LOGDEB(" filter: QLANG [" << fs.values[i] << "]!!\n"); LOGDEB(" filter: QLANG [" << fs.values[i] << "]!!\n");
} }
break; break;
case DocSeqFiltSpec::DSFS_PASSALL: case DocSeqFiltSpec::DSFS_PASSALL:
return true; return true;
} }
@ -74,7 +74,7 @@ bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec)
} }
} }
} }
break; break;
default: default:
break; break;
} }

View File

@ -29,20 +29,22 @@ class RclConfig;
/** /**
* A filtered sequence is created from another one by selecting entries * A filtered sequence is created from another one by selecting entries
* according to the given criteria. * according to the given criteria.
* Note that this class can only filter on mime type (or rclcatg) at the moment,
* and is only used for history. Normal query filtering is performed by adding a
* clause to the Xapian query.
*/ */
class DocSeqFiltered : public DocSeqModifier { class DocSeqFiltered : public DocSeqModifier {
public: public:
DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> iseq, DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> iseq, DocSeqFiltSpec &filtspec);
DocSeqFiltSpec &filtspec);
virtual ~DocSeqFiltered() {} virtual ~DocSeqFiltered() {}
virtual bool canFilter() {return true;} virtual bool canFilter() {return true;}
virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec); virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec);
virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0); virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0);
virtual int getResCnt() {return m_seq->getResCnt();} virtual int getResCnt() {return m_seq->getResCnt();}
private: private:
RclConfig *m_config; RclConfig *m_config;
DocSeqFiltSpec m_spec; DocSeqFiltSpec m_spec;
std::vector<int> m_dbindices; std::vector<int> m_dbindices;
}; };
#endif /* _FILTSEQ_H_INCLUDED_ */ #endif /* _FILTSEQ_H_INCLUDED_ */