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; 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; if (m_seq.isNull())
while (!m_seq.isNull() && !(m_seq->getSourceSeq()).isNull()) { return;
base = m_seq->getSourceSeq(); while (m_seq->getSourceSeq().isNotNull()) {
m_seq = m_seq->getSourceSeq();
} }
m_seq = base;
} }
bool DocSource::buildStack() bool DocSource::buildStack()
{ {
LOGDEB2(("DocSource::buildStack()\n")); LOGDEB2(("DocSource::buildStack()\n"));
unwind(); stripStack();
if (m_seq.isNull()) if (m_seq.isNull())
return false; return false;

View File

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