stripping filt/sort could loop

This commit is contained in:
Jean-Francois Dockes 2010-12-21 10:53:43 +01:00
parent 45c08165f5
commit 796d4b521d
2 changed files with 14 additions and 19 deletions

View File

@ -35,19 +35,20 @@ int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
return ret;
}
void DocSource::unwind()
// Remove stacked modifying sources (sort, filter) until we get to a real one
void DocSource::stripStack()
{
RefCntr<DocSequence> base = m_seq;
while (!m_seq.isNull() && !(m_seq->getSourceSeq()).isNull()) {
base = m_seq->getSourceSeq();
if (m_seq.isNull())
return;
while (m_seq->getSourceSeq().isNotNull()) {
m_seq = m_seq->getSourceSeq();
}
m_seq = base;
}
bool DocSource::buildStack()
{
LOGDEB2(("DocSource::buildStack()\n"));
unwind();
stripStack();
if (m_seq.isNull())
return false;

View File

@ -35,20 +35,14 @@ struct ResListEntry {
string subHeader;
};
/** Sort specification. Will be made closer to the db interface one day */
/** Sort specification. */
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() const {return sortdepth > 0;}
void reset() {crits.clear(); dirs.clear();sortdepth = 0;}
int sortdepth; // We only re-sort the first sortdepth most relevant docs
std::vector<Field> crits;
std::vector<bool> dirs;
DocSeqSortSpec() : desc(false) {}
bool isNotNull() const {return !field.empty();}
void reset() {field.erase();}
string field;
bool desc;
};
/** Filtering spec. This is only used to filter by doc category for now, hence
@ -203,7 +197,7 @@ public:
virtual string title();
private:
bool buildStack();
void unwind();
void stripStack();
DocSeqFiltSpec m_fspec;
DocSeqSortSpec m_sspec;
static string o_sort_trans;