change sortspec to use a single field name

This commit is contained in:
Jean-Francois Dockes 2010-12-21 10:54:27 +01:00
parent 796d4b521d
commit 1668fd92d6
3 changed files with 19 additions and 53 deletions

View File

@ -124,17 +124,7 @@ bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &sortspec)
{ {
LOGDEB(("DocSequenceDb::setSortSpec\n")); LOGDEB(("DocSequenceDb::setSortSpec\n"));
if (sortspec.isNotNull()) { if (sortspec.isNotNull()) {
bool ascending = false; m_q->setSortBy(sortspec.field, !sortspec.desc);
for (unsigned int i = 0; i < sortspec.crits.size(); i++) {
switch (sortspec.crits[i]) {
case DocSeqSortSpec::RCLFLD_MTIME:
ascending = !sortspec.dirs[i];
break;
default:
break;
}
}
m_q->setSortBy("mtime", ascending);
} else { } else {
m_q->setSortBy(string(), true); m_q->setSortBy(string(), true);
} }

View File

@ -35,56 +35,33 @@ public:
{ {
LOGDEB1(("Comparing .. \n")); LOGDEB1(("Comparing .. \n"));
// Compare using each criterion in term. Further comparisons must only map<string,string>::const_iterator xit, yit;
// be made if previous order ones are equal. xit = x->meta.find(ss.field);
for (unsigned int i = 0; i < ss.crits.size(); i++) { yit = y->meta.find(ss.field);
switch (ss.crits[i]) { if (xit == x->meta.end() || yit == y->meta.end())
case DocSeqSortSpec::RCLFLD_MTIME: return 0;
{ return ss.desc ? yit->second < xit->second : xit->second < yit->second;
long xmtime = x->dmtime.empty() ? atol(x->fmtime.c_str()) :
atol(x->dmtime.c_str());
long ymtime = y->dmtime.empty() ? atol(y->fmtime.c_str()) :
atol(y->dmtime.c_str());
LOGDEB1((" MTIME %ld %ld\n", xmtime, ymtime));
if (ss.dirs[i] ? xmtime > ymtime : xmtime < ymtime)
return 1;
else if (xmtime != ymtime)
return 0;
}
break;
case DocSeqSortSpec::RCLFLD_MIMETYPE:
LOGDEB1((" MIMETYPE\n"));
if (ss.dirs[i] ? x->mimetype > y->mimetype :
x->mimetype < y->mimetype)
return 1;
else if (x->mimetype != y->mimetype)
return 0;
break;
}
}
// Did all comparisons
return 0;
} }
}; };
bool DocSeqSorted::setSortSpec(DocSeqSortSpec &sortspec) bool DocSeqSorted::setSortSpec(DocSeqSortSpec &sortspec)
{ {
LOGDEB(("DocSeqSorted::setSortSpec\n"));
m_spec = sortspec; m_spec = sortspec;
LOGDEB(("DocSeqSorted:: count %d\n", m_spec.sortdepth)); int count = m_seq->getResCnt();
m_docs.resize(m_spec.sortdepth); LOGDEB(("DocSeqSorted:: count %d\n", count));
m_docs.resize(count);
int i; int i;
for (i = 0; i < m_spec.sortdepth; i++) { for (i = 0; i < count; i++) {
if (!m_seq->getDoc(i, m_docs[i])) { if (!m_seq->getDoc(i, m_docs[i])) {
LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i)); LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i));
count = i;
break; break;
} }
} }
m_spec.sortdepth = i; m_docs.resize(count);
LOGDEB(("DocSeqSorted:: m_count %d\n", m_spec.sortdepth)); m_docsp.resize(count);
m_docs.resize(m_spec.sortdepth); for (i = 0; i < count; i++)
m_docsp.resize(m_spec.sortdepth);
for (i = 0; i < m_spec.sortdepth; i++)
m_docsp[i] = &m_docs[i]; m_docsp[i] = &m_docs[i];
CompareDocs cmp(sortspec); CompareDocs cmp(sortspec);
@ -94,9 +71,8 @@ bool DocSeqSorted::setSortSpec(DocSeqSortSpec &sortspec)
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *) bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *)
{ {
LOGDEB1(("DocSeqSorted: fetching %d\n", num)); LOGDEB(("DocSeqSorted::getDoc(%d)\n", num));
if (num < 0 || num >= int(m_docsp.size()))
if (num >= m_spec.sortdepth)
return false; return false;
doc = *m_docsp[num]; doc = *m_docsp[num];
return true; return true;

View File

@ -39,7 +39,7 @@ class DocSeqSorted : public DocSeqModifier {
virtual bool canSort() {return true;} virtual bool canSort() {return true;}
virtual bool setSortSpec(DocSeqSortSpec &sortspec); virtual bool setSortSpec(DocSeqSortSpec &sortspec);
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_spec.sortdepth;} virtual int getResCnt() {return m_docsp.size();}
private: private:
DocSeqSortSpec m_spec; DocSeqSortSpec m_spec;
std::vector<Rcl::Doc> m_docs; std::vector<Rcl::Doc> m_docs;