diff --git a/src/query/docseq.cpp b/src/query/docseq.cpp index 81aa688e..a658816f 100644 --- a/src/query/docseq.cpp +++ b/src/query/docseq.cpp @@ -81,8 +81,7 @@ bool DocSource::buildStack() } } else { if (m_fspec.isNotNull()) { - m_seq = - std::shared_ptr(new DocSeqFiltered(m_config, m_seq, m_fspec)); + m_seq = std::shared_ptr(new DocSeqFiltered(m_config, m_seq, m_fspec)); } } diff --git a/src/query/docseqdb.cpp b/src/query/docseqdb.cpp index c92f25af..fab028bd 100644 --- a/src/query/docseqdb.cpp +++ b/src/query/docseqdb.cpp @@ -31,14 +31,7 @@ using std::list; DocSequenceDb::DocSequenceDb(std::shared_ptr db, std::shared_ptr q, const string &t, std::shared_ptr 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) + : DocSequence(t), m_db(db), m_q(q), m_sdata(sdata), m_fsdata(sdata) { } @@ -161,8 +154,7 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs) std::unique_lock locker(o_dblock); if (fs.isNotNull()) { // We build a search spec by adding a filtering layer to the base one. - m_fsdata = std::make_shared( - Rcl::SCLT_AND, m_sdata->getStemLang()); + m_fsdata = std::make_shared(Rcl::SCLT_AND, m_sdata->getStemLang()); Rcl::SearchDataClauseSub *cl = new Rcl::SearchDataClauseSub(m_sdata); m_fsdata->addClause(cl); @@ -171,22 +163,19 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs) case DocSeqFiltSpec::DSFS_MIMETYPE: m_fsdata->addFiletype(fs.values[i]); break; - case DocSeqFiltSpec::DSFS_QLANG: - { + case DocSeqFiltSpec::DSFS_QLANG: { if (!m_q) break; string reason; - auto sd = wasaStringToRcl(m_q->whatDb()->getConf(), - m_sdata->getStemLang(), - fs.values[i], reason); + auto sd = wasaStringToRcl( + m_q->whatDb()->getConf(), m_sdata->getStemLang(), fs.values[i], reason); if (sd) { - Rcl::SearchDataClauseSub *cl1 = - new Rcl::SearchDataClauseSub(sd); + Rcl::SearchDataClauseSub *cl1 = new Rcl::SearchDataClauseSub(sd); m_fsdata->addClause(cl1); } } - break; + break; default: break; } @@ -226,8 +215,7 @@ bool DocSequenceDb::setQuery() m_lastSQStatus = m_q->setQuery(m_fsdata); if (!m_lastSQStatus) { m_reason = m_q->getReason(); - LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " << - m_reason << "\n"); + LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " << m_reason << "\n"); } return m_lastSQStatus; } @@ -241,4 +229,3 @@ bool DocSequenceDb::docDups(const Rcl::Doc& doc, std::vector& dups) return false; } } - diff --git a/src/query/docseqdb.h b/src/query/docseqdb.h index c76c8eef..0c9f395c 100644 --- a/src/query/docseqdb.h +++ b/src/query/docseqdb.h @@ -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 * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -25,10 +25,10 @@ /** A DocSequence from a Db query */ class DocSequenceDb : public DocSequence { - public: +public: DocSequenceDb(std::shared_ptr db, std::shared_ptr q, const std::string &t, - std::shared_ptr sdata); + std::shared_ptr sdata); virtual ~DocSequenceDb() {} virtual bool getDoc(int num, Rcl::Doc &doc, std::string * = 0) override; virtual int getResCnt() override; @@ -55,7 +55,7 @@ class DocSequenceDb : public DocSequence { } virtual bool snippetsCapable() override { - return true; + return true; } virtual std::string title() override; @@ -68,13 +68,13 @@ private: std::shared_ptr m_q; std::shared_ptr m_sdata; std::shared_ptr m_fsdata; // Filtered - int m_rescnt; - bool m_queryBuildAbstract; - bool m_queryReplaceAbstract; - bool m_isFiltered; - bool m_isSorted; - bool m_needSetQuery; // search data changed, need to reapply before fetch - bool m_lastSQStatus; + int m_rescnt{-1}; + bool m_queryBuildAbstract{true}; + bool m_queryReplaceAbstract{false}; + bool m_isFiltered{false}; + bool m_isSorted{false}; + bool m_needSetQuery{false}; // search data changed, need to reapply before fetch + bool m_lastSQStatus{true}; bool setQuery(); }; diff --git a/src/query/docseqhist.cpp b/src/query/docseqhist.cpp index 51edc68e..2d260723 100644 --- a/src/query/docseqhist.cpp +++ b/src/query/docseqhist.cpp @@ -125,31 +125,31 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) { // Retrieve history list if (!m_hist) - return false; + return false; if (m_history.empty()) - m_history = getDocHistory(m_hist); + m_history = getDocHistory(m_hist); if (num < 0 || num >= (int)m_history.size()) - return false; + return false; // We get the history oldest first, but our users expect newest first RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num]; if (sh) { - if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) { - m_prevtime = hentry.unixtime; - time_t t = (time_t)(hentry.unixtime); - *sh = string(ctime(&t)); - // Get rid of the final \n in ctime - sh->erase(sh->length()-1); - } else { - sh->erase(); + if (m_prevtime < 0 || abs(m_prevtime - hentry.unixtime) > 86400) { + m_prevtime = hentry.unixtime; + time_t t = (time_t)(hentry.unixtime); + *sh = string(ctime(&t)); + // Get rid of the final \n in ctime + sh->erase(sh->length()-1); + } else { + sh->erase(); } } bool ret = m_db->getDoc(hentry.udi, hentry.dbdir, doc); if (!ret || doc.pc == -1) { - doc.url = "UNKNOWN"; + doc.url = "UNKNOWN"; doc.ipath = ""; } @@ -163,7 +163,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh) int DocSequenceHistory::getResCnt() { if (m_history.empty()) - m_history = getDocHistory(m_hist); + m_history = getDocHistory(m_hist); return int(m_history.size()); } diff --git a/src/query/filtseq.cpp b/src/query/filtseq.cpp index a722acb6..e1a910ad 100644 --- a/src/query/filtseq.cpp +++ b/src/query/filtseq.cpp @@ -36,7 +36,7 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x) case DocSeqFiltSpec::DSFS_QLANG: { LOGDEB(" filter: QLANG [" << fs.values[i] << "]!!\n"); } - break; + break; case DocSeqFiltSpec::DSFS_PASSALL: return true; } @@ -74,7 +74,7 @@ bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec) } } } - break; + break; default: break; } diff --git a/src/query/filtseq.h b/src/query/filtseq.h index 3e3f5165..d89e2bb6 100644 --- a/src/query/filtseq.h +++ b/src/query/filtseq.h @@ -29,20 +29,22 @@ class RclConfig; /** * A filtered sequence is created from another one by selecting entries * 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 { public: - DocSeqFiltered(RclConfig *conf, std::shared_ptr iseq, - DocSeqFiltSpec &filtspec); + DocSeqFiltered(RclConfig *conf, std::shared_ptr iseq, DocSeqFiltSpec &filtspec); virtual ~DocSeqFiltered() {} virtual bool canFilter() {return true;} virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec); virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0); virtual int getResCnt() {return m_seq->getResCnt();} - private: +private: RclConfig *m_config; DocSeqFiltSpec m_spec; - std::vector m_dbindices; + std::vector m_dbindices; }; #endif /* _FILTSEQ_H_INCLUDED_ */