GUI snippets window: add options for the max list length and for sorting the snippets by page number

This commit is contained in:
Jean-Francois Dockes
2019-07-21 19:09:51 +02:00
parent 049ba1e7e4
commit 736051fcd6
13 changed files with 290 additions and 224 deletions
+92 -106
View File
@@ -39,7 +39,7 @@ struct ResListEntry {
/** Sort specification. */
class DocSeqSortSpec {
public:
public:
DocSeqSortSpec() : desc(false) {}
bool isNotNull() const {return !field.empty();}
void reset() {field.erase();}
@@ -50,12 +50,12 @@ class DocSeqSortSpec {
/** Filtering spec. This is only used to filter by doc category for now, hence
the rather specialized interface */
class DocSeqFiltSpec {
public:
public:
DocSeqFiltSpec() {}
enum Crit {DSFS_MIMETYPE, DSFS_QLANG, DSFS_PASSALL};
void orCrit(Crit crit, const std::string& value) {
crits.push_back(crit);
values.push_back(value);
crits.push_back(crit);
values.push_back(value);
}
std::vector<Crit> crits;
std::vector<std::string> values;
@@ -75,7 +75,7 @@ class DocSeqFiltSpec {
the current one will have to do for now.
*/
class DocSequence {
public:
public:
DocSequence(const std::string &t) : m_title(t) {}
virtual ~DocSequence() {}
@@ -92,29 +92,26 @@ class DocSequence {
/** Get next page of documents. This accumulates entries into the result
* list parameter (doesn't reset it). */
virtual int getSeqSlice(int offs, int cnt,
std::vector<ResListEntry>& result);
std::vector<ResListEntry>& result);
/** Get abstract for document. This is special because it may take time.
* The default is to return the input doc's abstract fields, but some
* sequences can compute a better value (ie: docseqdb) */
virtual bool getAbstract(Rcl::Doc& doc, std::vector<std::string>& abs) {
abs.push_back(doc.meta[Rcl::Doc::keyabs]);
return true;
abs.push_back(doc.meta[Rcl::Doc::keyabs]);
return true;
}
virtual bool getAbstract(Rcl::Doc& doc,
std::vector<Rcl::Snippet>& abs)
{
abs.push_back(Rcl::Snippet(0, doc.meta[Rcl::Doc::keyabs]));
return true;
virtual bool getAbstract(Rcl::Doc& doc, std::vector<Rcl::Snippet>& abs,
int, bool) {
abs.push_back(Rcl::Snippet(0, doc.meta[Rcl::Doc::keyabs]));
return true;
}
virtual int getFirstMatchPage(Rcl::Doc&, std::string&)
{
return -1;
virtual int getFirstMatchPage(Rcl::Doc&, std::string&) {
return -1;
}
/** Get duplicates. */
virtual bool docDups(const Rcl::Doc&, std::vector<Rcl::Doc>&)
{
return false;
virtual bool docDups(const Rcl::Doc&, std::vector<Rcl::Doc>&) {
return false;
}
virtual bool getEnclosing(Rcl::Doc&, Rcl::Doc&);
@@ -124,43 +121,44 @@ class DocSequence {
/** Get title for result list */
virtual std::string title()
{
return m_title;
}
{
return m_title;
}
/** Can do snippets ? */
virtual bool snippetsCapable()
{
return false;
}
{
return false;
}
/** Get description for underlying query */
virtual std::string getDescription() = 0;
/** Get search terms (for highlighting abstracts). Some sequences
* may have no associated search terms. Implement this for them. */
virtual void getTerms(HighlightData& hld)
{
hld.clear();
}
virtual void getTerms(HighlightData& hld)
{
hld.clear();
}
virtual std::list<std::string> expand(Rcl::Doc &)
{
return std::list<std::string>();
}
{
return std::list<std::string>();
}
virtual std::string getReason()
{
return m_reason;
}
{
return m_reason;
}
/** Optional functionality. */
virtual bool canFilter() {return false;}
virtual bool canSort() {return false;}
virtual bool setFiltSpec(const DocSeqFiltSpec &) {return false;}
virtual bool setSortSpec(const DocSeqSortSpec &) {return false;}
virtual std::shared_ptr<DocSequence> getSourceSeq() {return std::shared_ptr<DocSequence>();}
virtual std::shared_ptr<DocSequence> getSourceSeq() {
return std::shared_ptr<DocSequence>();}
static void set_translations(const std::string& sort, const std::string& filt)
{
o_sort_trans = sort;
o_filt_trans = filt;
static void set_translations(const std::string& sort,
const std::string& filt) {
o_sort_trans = sort;
o_filt_trans = filt;
}
@@ -172,7 +170,7 @@ protected:
static std::string o_filt_trans;
std::string m_reason;
private:
private:
std::string m_title;
};
@@ -182,75 +180,65 @@ protected:
class DocSeqModifier : public DocSequence {
public:
DocSeqModifier(std::shared_ptr<DocSequence> iseq)
: DocSequence(""), m_seq(iseq)
{}
: DocSequence(""), m_seq(iseq)
{}
virtual ~DocSeqModifier() {}
virtual bool getAbstract(Rcl::Doc& doc, std::vector<std::string>& abs)
{
if (!m_seq)
return false;
return m_seq->getAbstract(doc, abs);
virtual bool getAbstract(Rcl::Doc& doc, std::vector<std::string>& abs) {
if (!m_seq)
return false;
return m_seq->getAbstract(doc, abs);
}
virtual bool getAbstract(Rcl::Doc& doc,
std::vector<Rcl::Snippet>& abs)
{
if (!m_seq)
return false;
return m_seq->getAbstract(doc, abs);
virtual bool getAbstract(Rcl::Doc& doc, std::vector<Rcl::Snippet>& abs,
int maxlen, bool bypage) override {
if (!m_seq)
return false;
return m_seq->getAbstract(doc, abs, maxlen, bypage);
}
/** Get duplicates. */
virtual bool docDups(const Rcl::Doc& doc, std::vector<Rcl::Doc>& dups)
{
if (!m_seq)
return false;
return m_seq->docDups(doc, dups);
virtual bool docDups(const Rcl::Doc& doc, std::vector<Rcl::Doc>& dups) {
if (!m_seq)
return false;
return m_seq->docDups(doc, dups);
}
virtual bool snippetsCapable()
{
if (!m_seq)
return false;
return m_seq->snippetsCapable();
virtual bool snippetsCapable() {
if (!m_seq)
return false;
return m_seq->snippetsCapable();
}
virtual std::string getDescription()
{
if (!m_seq)
return "";
return m_seq->getDescription();
virtual std::string getDescription() {
if (!m_seq)
return "";
return m_seq->getDescription();
}
virtual void getTerms(HighlightData& hld)
{
if (!m_seq)
return;
m_seq->getTerms(hld);
virtual void getTerms(HighlightData& hld) {
if (!m_seq)
return;
m_seq->getTerms(hld);
}
virtual bool getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
if (!m_seq)
return false;
return m_seq->getEnclosing(doc, pdoc);
virtual bool getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc) {
if (!m_seq)
return false;
return m_seq->getEnclosing(doc, pdoc);
}
virtual std::string getReason()
{
if (!m_seq)
return string();
return m_seq->getReason();
virtual std::string getReason() {
if (!m_seq)
return string();
return m_seq->getReason();
}
virtual std::string title()
{
return m_seq->title();
virtual std::string title() {
return m_seq->title();
}
virtual std::shared_ptr<DocSequence> getSourceSeq()
{
return m_seq;
virtual std::shared_ptr<DocSequence> getSourceSeq() {
return m_seq;
}
protected:
virtual std::shared_ptr<Rcl::Db> getDb() {
if (!m_seq)
return 0;
return m_seq->getDb();
if (!m_seq)
return 0;
return m_seq->getDb();
}
std::shared_ptr<DocSequence> m_seq;
@@ -263,23 +251,21 @@ class RclConfig;
class DocSource : public DocSeqModifier {
public:
DocSource(RclConfig *config, std::shared_ptr<DocSequence> iseq)
: DocSeqModifier(iseq), m_config(config)
{}
: DocSeqModifier(iseq), m_config(config)
{}
virtual bool canFilter() {return true;}
virtual bool canSort() {return true;}
virtual bool setFiltSpec(const DocSeqFiltSpec &);
virtual bool setSortSpec(const DocSeqSortSpec &);
virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0)
{
if (!m_seq)
return false;
return m_seq->getDoc(num, doc, sh);
virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0) {
if (!m_seq)
return false;
return m_seq->getDoc(num, doc, sh);
}
virtual int getResCnt()
{
if (!m_seq)
return 0;
return m_seq->getResCnt();
virtual int getResCnt() {
if (!m_seq)
return 0;
return m_seq->getResCnt();
}
virtual std::string title();
private:
@@ -290,4 +276,4 @@ private:
DocSeqSortSpec m_sspec;
};
#endif /* _DOCSEQ_H_INCLUDED_ */
#endif /* _DOCSEQ_H_ */
+75 -72
View File
@@ -30,7 +30,7 @@ using std::list;
DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Db> db,
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),
m_rescnt(-1),
m_queryBuildAbstract(true),
@@ -56,7 +56,7 @@ bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh)
{
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return false;
return false;
if (sh) sh->erase();
return m_q->getDoc(num, doc);
}
@@ -65,9 +65,9 @@ int DocSequenceDb::getResCnt()
{
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return false;
return false;
if (m_rescnt < 0) {
m_rescnt= m_q->getResCnt();
m_rescnt= m_q->getResCnt();
}
return m_rescnt;
}
@@ -76,32 +76,33 @@ static const string cstr_mre("[...]");
// This one only gets called to fill-up the snippets window
// We ignore most abstract/snippets preferences.
bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<Rcl::Snippet>& vpabs)
bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<Rcl::Snippet>& vpabs,
int maxlen, bool sortbypage)
{
LOGDEB("DocSequenceDb::getAbstract/pair\n" );
LOGDEB("DocSequenceDb::getAbstract/pair\n");
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return false;
return false;
// Have to put the limit somewhere.
int maxoccs = 1000;
int ret = Rcl::ABSRES_ERROR;
if (m_q->whatDb()) {
ret = m_q->makeDocAbstract(doc, vpabs, maxoccs,
m_q->whatDb()->getAbsCtxLen()+ 2);
ret = m_q->makeDocAbstract(
doc, vpabs, maxlen, m_q->whatDb()->getAbsCtxLen() + 2, sortbypage);
}
LOGDEB("DocSequenceDb::getAbstract: got ret " << (ret) << " vpabs len " << (vpabs.size()) << "\n" );
LOGDEB("DocSequenceDb::getAbstract: got ret " << ret << " vpabs len " <<
vpabs.size() << "\n");
if (vpabs.empty()) {
return true;
return true;
}
// If the list was probably truncated, indicate it.
if (ret & Rcl::ABSRES_TRUNC) {
vpabs.push_back(Rcl::Snippet(-1, cstr_mre));
vpabs.push_back(Rcl::Snippet(-1, cstr_mre));
}
if (ret & Rcl::ABSRES_TERMMISS) {
vpabs.insert(vpabs.begin(),
Rcl::Snippet(-1, "(Words missing in snippets)"));
vpabs.insert(vpabs.begin(),
Rcl::Snippet(-1, "(Words missing in snippets)"));
}
return true;
@@ -111,13 +112,13 @@ bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<string>& vabs)
{
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return false;
return false;
if (m_q->whatDb() &&
m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
m_q->makeDocAbstract(doc, vabs);
m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
m_q->makeDocAbstract(doc, vabs);
}
if (vabs.empty())
vabs.push_back(doc.meta[Rcl::Doc::keyabs]);
vabs.push_back(doc.meta[Rcl::Doc::keyabs]);
return true;
}
@@ -125,9 +126,9 @@ int DocSequenceDb::getFirstMatchPage(Rcl::Doc &doc, string& term)
{
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return false;
return false;
if (m_q->whatDb()) {
return m_q->getFirstMatchPage(doc, term);
return m_q->getFirstMatchPage(doc, term);
}
return -1;
}
@@ -136,7 +137,7 @@ list<string> DocSequenceDb::expand(Rcl::Doc &doc)
{
std::unique_lock<std::mutex> locker(o_dblock);
if (!setQuery())
return list<string>();
return list<string>();
vector<string> v = m_q->expand(doc);
return list<string>(v.begin(), v.end());
}
@@ -145,58 +146,58 @@ string DocSequenceDb::title()
{
string qual;
if (m_isFiltered && !m_isSorted)
qual = string(" (") + o_filt_trans + string(")");
qual = string(" (") + o_filt_trans + string(")");
else if (!m_isFiltered && m_isSorted)
qual = string(" (") + o_sort_trans + string(")");
qual = string(" (") + o_sort_trans + string(")");
else if (m_isFiltered && m_isSorted)
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans +
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans +
string(")");
return DocSequence::title() + qual;
}
bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
{
LOGDEB("DocSequenceDb::setFiltSpec\n" );
LOGDEB("DocSequenceDb::setFiltSpec\n");
std::unique_lock<std::mutex> locker(o_dblock);
if (fs.isNotNull()) {
// We build a search spec by adding a filtering layer to the base one.
m_fsdata = std::shared_ptr<Rcl::SearchData>(
new Rcl::SearchData(Rcl::SCLT_AND, m_sdata->getStemLang()));
Rcl::SearchDataClauseSub *cl =
new Rcl::SearchDataClauseSub(m_sdata);
m_fsdata->addClause(cl);
// We build a search spec by adding a filtering layer to the base one.
m_fsdata = std::shared_ptr<Rcl::SearchData>(
new Rcl::SearchData(Rcl::SCLT_AND, m_sdata->getStemLang()));
Rcl::SearchDataClauseSub *cl =
new Rcl::SearchDataClauseSub(m_sdata);
m_fsdata->addClause(cl);
for (unsigned int i = 0; i < fs.crits.size(); i++) {
switch (fs.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
m_fsdata->addFiletype(fs.values[i]);
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
if (!m_q)
break;
string reason;
Rcl::SearchData *sd =
wasaStringToRcl(m_q->whatDb()->getConf(),
m_sdata->getStemLang(),
fs.values[i], reason);
if (sd) {
Rcl::SearchDataClauseSub *cl1 =
new Rcl::SearchDataClauseSub(
std::shared_ptr<Rcl::SearchData>(sd));
m_fsdata->addClause(cl1);
}
}
break;
default:
break;
}
}
m_isFiltered = true;
for (unsigned int i = 0; i < fs.crits.size(); i++) {
switch (fs.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE:
m_fsdata->addFiletype(fs.values[i]);
break;
case DocSeqFiltSpec::DSFS_QLANG:
{
if (!m_q)
break;
string reason;
Rcl::SearchData *sd =
wasaStringToRcl(m_q->whatDb()->getConf(),
m_sdata->getStemLang(),
fs.values[i], reason);
if (sd) {
Rcl::SearchDataClauseSub *cl1 =
new Rcl::SearchDataClauseSub(
std::shared_ptr<Rcl::SearchData>(sd));
m_fsdata->addClause(cl1);
}
}
break;
default:
break;
}
}
m_isFiltered = true;
} else {
m_fsdata = m_sdata;
m_isFiltered = false;
m_fsdata = m_sdata;
m_isFiltered = false;
}
m_needSetQuery = true;
return true;
@@ -204,14 +205,15 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
{
LOGDEB("DocSequenceDb::setSortSpec: fld [" << (spec.field) << "] " << (spec.desc ? "desc" : "asc") << "\n" );
LOGDEB("DocSequenceDb::setSortSpec: fld [" << spec.field << "] " <<
(spec.desc ? "desc" : "asc") << "\n");
std::unique_lock<std::mutex> locker(o_dblock);
if (spec.isNotNull()) {
m_q->setSortBy(spec.field, !spec.desc);
m_isSorted = true;
m_q->setSortBy(spec.field, !spec.desc);
m_isSorted = true;
} else {
m_q->setSortBy(string(), true);
m_isSorted = false;
m_q->setSortBy(string(), true);
m_isSorted = false;
}
m_needSetQuery = true;
return true;
@@ -220,14 +222,15 @@ bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
bool DocSequenceDb::setQuery()
{
if (!m_needSetQuery)
return true;
return true;
m_needSetQuery = false;
m_rescnt = -1;
m_lastSQStatus = m_q->setQuery(m_fsdata);
if (!m_lastSQStatus) {
m_reason = m_q->getReason();
LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " << (m_reason) << "\n" );
m_reason = m_q->getReason();
LOGERR("DocSequenceDb::setQuery: rclquery::setQuery failed: " <<
m_reason << "\n");
}
return m_lastSQStatus;
}
@@ -236,9 +239,9 @@ bool DocSequenceDb::docDups(const Rcl::Doc& doc, std::vector<Rcl::Doc>& dups)
{
if (m_q->whatDb()) {
std::unique_lock<std::mutex> locker(o_dblock);
return m_q->whatDb()->docDups(doc, dups);
return m_q->whatDb()->docDups(doc, dups);
} else {
return false;
return false;
}
}
+9 -7
View File
@@ -16,9 +16,10 @@
*/
#ifndef _DOCSEQDB_H_INCLUDED_
#define _DOCSEQDB_H_INCLUDED_
#include "docseq.h"
#include <memory>
#include "docseq.h"
#include "searchdata.h"
#include "rclquery.h"
@@ -26,21 +27,22 @@
class DocSequenceDb : public DocSequence {
public:
DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const string &t,
std::shared_ptr<Rcl::Query> q, const std::string &t,
std::shared_ptr<Rcl::SearchData> sdata);
virtual ~DocSequenceDb() {}
virtual bool getDoc(int num, Rcl::Doc &doc, string * = 0);
virtual bool getDoc(int num, Rcl::Doc &doc, std::string * = 0);
virtual int getResCnt();
virtual void getTerms(HighlightData& hld);
// Called to fill-up the snippets window. Ignoers
// buildabstract/replaceabstract and syntabslen
virtual bool getAbstract(Rcl::Doc &doc, vector<Rcl::Snippet>&);
virtual bool getAbstract(Rcl::Doc &doc, std::vector<Rcl::Snippet>&,
int maxlen, bool sortbypage) override;
virtual bool getAbstract(Rcl::Doc &doc, vector<string>&);
virtual bool getAbstract(Rcl::Doc &doc, std::vector<std::string>&);
virtual int getFirstMatchPage(Rcl::Doc&, std::string& term);
virtual bool docDups(const Rcl::Doc& doc, std::vector<Rcl::Doc>& dups);
virtual string getDescription();
virtual std::string getDescription();
virtual std::list<std::string> expand(Rcl::Doc &doc);
virtual bool canFilter() {return true;}
virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec);
@@ -56,7 +58,7 @@ class DocSequenceDb : public DocSequence {
{
return true;
}
virtual string title();
virtual std::string title();
protected:
virtual std::shared_ptr<Rcl::Db> getDb() {