move stemlang from RclQuery to SearchData. Allow DocSequences to do the sorting/filtering themselves

This commit is contained in:
dockes
2008-09-29 11:33:55 +00:00
parent 828dff3bb1
commit f0538b15f2
16 changed files with 166 additions and 97 deletions
+46 -1
View File
@@ -16,7 +16,7 @@
*/
#ifndef _DOCSEQ_H_INCLUDED_
#define _DOCSEQ_H_INCLUDED_
/* @(#$Id: docseq.h,v 1.16 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: docseq.h,v 1.17 2008-09-29 11:33:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#include <vector>
@@ -34,10 +34,48 @@ struct ResListEntry {
string subHeader;
};
/** Sort specification. Will be made closer to the db interface one day */
class DocSeqSortSpec {
public:
DocSeqSortSpec() : sortdepth(0) {}
enum Field {RCLFLD_MIMETYPE, RCLFLD_MTIME};
void addCrit(Field fld, bool desc = false) {
crits.push_back(fld);
dirs.push_back(desc);
}
bool isNotNull() {return sortdepth > 0;}
int sortdepth; // We only re-sort the first sortdepth most relevant docs
std::vector<Field> crits;
std::vector<bool> dirs;
};
/** Filtering spec. This is only used to filter by doc category for now, hence
the rather specialized interface */
class DocSeqFiltSpec {
public:
DocSeqFiltSpec() {}
enum Crit {DSFS_MIMETYPE};
void orCrit(Crit crit, const string& value) {
crits.push_back(crit);
values.push_back(value);
}
std::vector<Crit> crits;
std::vector<string> values;
void reset() {crits.clear(); values.clear();}
bool isNotNull() {return crits.size() != 0;}
};
/** Interface for a list of documents coming from some source.
The result list display data may come from different sources (ie:
history or Db query), and be post-processed (DocSeqSorted).
Additional functionality like filtering/sorting can either be
obtained by stacking DocSequence objects (ie: sorting history), or
by native capability (ex: docseqdb can sort and filter). The
implementation might be nicer by using more sophisticated c++ with
multiple inheritance of sort and filter virtual interfaces, but
the current one will have to do for now...
*/
class DocSequence {
public:
@@ -83,6 +121,13 @@ class DocSequence {
terms.clear(); groups.clear(); gslks.clear(); return true;
}
virtual list<string> expand(Rcl::Doc &) {list<string> e; return e;}
/** Optional functionality. Yeah, not nice */
virtual bool canFilter() {return false;}
virtual bool setFiltSpec(DocSeqFiltSpec &) {return false;}
virtual bool canSort() {return false;}
virtual bool setSortSpec(DocSeqSortSpec &) {return false;}
private:
string m_title;
};
+41 -4
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.7 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.8 2008-09-29 11:33:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -22,10 +22,11 @@ static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.7 2008-09-29 08:59:20 dockes Exp
#include "docseqdb.h"
#include "rcldb.h"
#include "debuglog.h"
DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
RefCntr<Rcl::SearchData> sdata)
: DocSequence(t), m_q(q), m_sdata(sdata), m_rescnt(-1)
: DocSequence(t), m_q(q), m_sdata(sdata), m_rescnt(-1), m_filt(false)
{
}
@@ -37,12 +38,12 @@ bool DocSequenceDb::getTerms(vector<string>& terms,
vector<vector<string> >& groups,
vector<int>& gslks)
{
return m_sdata->getTerms(terms, groups, gslks);
return m_fsdata->getTerms(terms, groups, gslks);
}
string DocSequenceDb::getDescription()
{
return m_sdata->getDescription();
return m_fsdata->getDescription();
}
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh)
@@ -73,3 +74,39 @@ list<string> DocSequenceDb::expand(Rcl::Doc &doc)
return m_q->expand(doc);
}
bool DocSequenceDb::setFiltSpec(DocSeqFiltSpec &fs)
{
if (!fs.isNotNull()) {
m_fsdata = m_sdata;
m_filt = false;
return m_q->setQuery(m_sdata);
}
// We build a search spec by adding a filtering layer to the base one.
m_fsdata = RefCntr<Rcl::SearchData>(new Rcl::SearchData(Rcl::SCLT_AND));
Rcl::SearchDataClauseSub *cl =
new Rcl::SearchDataClauseSub(Rcl::SCLT_SUB, 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]);
}
}
m_filt = true;
return m_q->setQuery(m_fsdata);
}
// Need a way to access the translations for filtered ...
string DocSequenceDb::title()
{
LOGDEB(("DOcSequenceDb::title()\n"));
return m_filt ? DocSequence::title() + " (filtered)" : DocSequence::title();
}
// TBDone
bool DocSequenceDb::setSortSpec(DocSeqSortSpec &sortspec)
{
return true;
}
+8 -1
View File
@@ -16,7 +16,7 @@
*/
#ifndef _DOCSEQDB_H_INCLUDED_
#define _DOCSEQDB_H_INCLUDED_
/* @(#$Id: docseqdb.h,v 1.5 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: docseqdb.h,v 1.6 2008-09-29 11:33:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include "docseq.h"
#include "refcntr.h"
@@ -38,10 +38,17 @@ class DocSequenceDb : public DocSequence {
virtual string getAbstract(Rcl::Doc &doc);
virtual string getDescription();
virtual list<string> expand(Rcl::Doc &doc);
virtual bool canFilter() {return true;}
virtual bool setFiltSpec(DocSeqFiltSpec &filtspec);
virtual bool canSort() {return false;}
virtual bool setSortSpec(DocSeqSortSpec &sortspec);
virtual string title();
private:
RefCntr<Rcl::Query> m_q;
RefCntr<Rcl::SearchData> m_sdata;
RefCntr<Rcl::SearchData> m_fsdata; // Filtered
int m_rescnt;
bool m_filt;
};
#endif /* _DOCSEQDB_H_INCLUDED_ */
+7 -1
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: filtseq.cpp,v 1.2 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: filtseq.cpp,v 1.3 2008-09-29 11:33:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -47,6 +47,12 @@ DocSeqFiltered::DocSeqFiltered(RefCntr<DocSequence> iseq,
{
}
bool DocSeqFiltered::setFiltSpec(DocSeqFiltSpec &filtspec)
{
m_spec = filtspec;
m_dbindices.clear();
}
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
{
LOGDEB1(("DocSeqFiltered: fetching %d\n", idx));
+3 -14
View File
@@ -16,7 +16,7 @@
*/
#ifndef _FILTSEQ_H_INCLUDED_
#define _FILTSEQ_H_INCLUDED_
/* @(#$Id: filtseq.h,v 1.3 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: filtseq.h,v 1.4 2008-09-29 11:33:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
@@ -24,19 +24,6 @@
#include "refcntr.h"
#include "docseq.h"
class DocSeqFiltSpec {
public:
DocSeqFiltSpec() {}
enum Crit {DSFS_MIMETYPE};
void orCrit(Crit crit, const string& value) {
crits.push_back(crit);
values.push_back(value);
}
std::vector<Crit> crits;
std::vector<string> values;
void reset() {crits.clear(); values.clear();}
bool isNotNull() {return crits.size() != 0;}
};
/**
* A filtered sequence is created from another one by selecting entries
@@ -47,6 +34,8 @@ class DocSeqFiltered : public DocSequence {
DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec,
const std::string &t);
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();}
virtual string getAbstract(Rcl::Doc& doc) {
+3 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.18 2008-09-29 08:59:20 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.19 2008-09-29 11:33:55 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -221,13 +221,14 @@ int recollq(RclConfig **cfp, int argc, char **argv)
cerr << "Query string interpretation failed: " << reason << endl;
return 1;
}
sd->setStemlang("english");
RefCntr<Rcl::SearchData> rq(sd);
Rcl::Query query(&rcldb);
if (op_flags & OPT_S) {
query.setSortBy(sortfield, (op_flags & OPT_D) ? false : true);
}
query.setQuery(rq, Rcl::Query::QO_STEM);
query.setQuery(rq);
int cnt = query.getResCnt();
if (!(op_flags & OPT_b)) {
cout << "Recoll query: " << rq->getDescription() << endl;
+8 -16
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.13 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.14 2008-09-29 11:33:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -53,20 +53,6 @@ public:
return 0;
}
break;
case DocSeqSortSpec::RCLFLD_URL:
LOGDEB1((" URL\n"));
if (ss.dirs[i] ? x->url > y->url : x->url < y->url)
return 1;
else if (x->url != y->url)
return 0;
break;
case DocSeqSortSpec::RCLFLD_IPATH:
LOGDEB1((" IPATH\n"));
if (ss.dirs[i] ? x->ipath > y->ipath : x->ipath < y->ipath)
return 1;
else if (x->ipath != y->ipath)
return 0;
break;
case DocSeqSortSpec::RCLFLD_MIMETYPE:
LOGDEB1((" MIMETYPE\n"));
if (ss.dirs[i] ? x->mimetype > y->mimetype :
@@ -85,13 +71,18 @@ public:
DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
const std::string &t)
: DocSequence(t), m_seq(iseq)
{
setSortSpec(sortspec);
}
bool DocSeqSorted::setSortSpec(DocSeqSortSpec &sortspec)
{
m_spec = sortspec;
LOGDEB(("DocSeqSorted:: count %d\n", m_spec.sortdepth));
m_docs.resize(m_spec.sortdepth);
int i;
for (i = 0; i < m_spec.sortdepth; i++) {
if (!iseq->getDoc(i, m_docs[i])) {
if (!m_seq->getDoc(i, m_docs[i])) {
LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i));
break;
}
@@ -105,6 +96,7 @@ DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
CompareDocs cmp(sortspec);
sort(m_docsp.begin(), m_docsp.end(), cmp);
return true;
}
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *)
+3 -16
View File
@@ -16,7 +16,7 @@
*/
#ifndef _SORTSEQ_H_INCLUDED_
#define _SORTSEQ_H_INCLUDED_
/* @(#$Id: sortseq.h,v 1.12 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: sortseq.h,v 1.13 2008-09-29 11:33:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
@@ -24,21 +24,6 @@
#include "refcntr.h"
#include "docseq.h"
class DocSeqSortSpec {
public:
DocSeqSortSpec() : sortdepth(0) {}
enum Field {RCLFLD_URL, RCLFLD_IPATH, RCLFLD_MIMETYPE, RCLFLD_MTIME};
void addCrit(Field fld, bool desc = false) {
crits.push_back(fld);
dirs.push_back(desc);
}
bool isNotNull() {return sortdepth > 0;}
int sortdepth; // We only re-sort the first sortdepth most relevant docs
std::vector<Field> crits;
std::vector<bool> dirs;
};
/**
* A sorted sequence is created from the first N documents of another one,
* and sorts them according to the given criteria.
@@ -48,6 +33,8 @@ class DocSeqSorted : public DocSequence {
DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
const std::string &t);
virtual ~DocSeqSorted() {}
virtual bool canSort() {return true;}
virtual bool setSortSpec(DocSeqSortSpec &sortspec);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt() {return m_spec.sortdepth;}
virtual string getAbstract(Rcl::Doc& doc) {