GUI restable: fix sorting by file and doc size
This commit is contained in:
parent
6b04fe7f2c
commit
48e86c99b5
@ -154,6 +154,16 @@ static string gengetter(const string& fld, const Rcl::Doc& doc)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string sizegetter(const string& fld, const Rcl::Doc& doc)
|
||||||
|
{
|
||||||
|
map<string, string>::const_iterator it = doc.meta.find(fld);
|
||||||
|
if (it == doc.meta.end()) {
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
off_t size = atoll(it->second.c_str());
|
||||||
|
return displayableBytes(size) + " (" + it->second + ")";
|
||||||
|
}
|
||||||
|
|
||||||
static string dategetter(const string&, const Rcl::Doc& doc)
|
static string dategetter(const string&, const Rcl::Doc& doc)
|
||||||
{
|
{
|
||||||
char datebuf[100];
|
char datebuf[100];
|
||||||
@ -162,7 +172,11 @@ static string dategetter(const string&, const Rcl::Doc& doc)
|
|||||||
time_t mtime = doc.dmtime.empty() ?
|
time_t mtime = doc.dmtime.empty() ?
|
||||||
atol(doc.fmtime.c_str()) : atol(doc.dmtime.c_str());
|
atol(doc.fmtime.c_str()) : atol(doc.dmtime.c_str());
|
||||||
struct tm *tm = localtime(&mtime);
|
struct tm *tm = localtime(&mtime);
|
||||||
|
#ifndef sun
|
||||||
|
strftime(datebuf, 99, "%Y-%m-%d", tm);
|
||||||
|
#else
|
||||||
strftime(datebuf, 99, "%x", tm);
|
strftime(datebuf, 99, "%x", tm);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return datebuf;
|
return datebuf;
|
||||||
}
|
}
|
||||||
@ -212,6 +226,8 @@ FieldGetter *RecollModel::chooseGetter(const string& field)
|
|||||||
return dategetter;
|
return dategetter;
|
||||||
else if (!stringlowercmp("datetime", field))
|
else if (!stringlowercmp("datetime", field))
|
||||||
return datetimegetter;
|
return datetimegetter;
|
||||||
|
else if (!stringlowercmp("bytes", field.substr(1)))
|
||||||
|
return sizegetter;
|
||||||
else
|
else
|
||||||
return gengetter;
|
return gengetter;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,12 +138,6 @@ static inline string make_parentterm(const string& udi)
|
|||||||
return pterm;
|
return pterm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void leftzeropad(string& s, unsigned len)
|
|
||||||
{
|
|
||||||
if (s.length() && s.length() < len)
|
|
||||||
s = s.insert(0, len - s.length(), '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See comment in class declaration: return all subdocuments of a
|
/* See comment in class declaration: return all subdocuments of a
|
||||||
* document given by its unique id.
|
* document given by its unique id.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -54,13 +54,17 @@ static const string& docfToDatf(const string& df)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort helper class
|
// Sort helper class. As Xapian sorting is lexicographic, we do some
|
||||||
|
// special processing for special fields like dates and sizes. User
|
||||||
|
// custom field data will have to be processed before insertion to
|
||||||
|
// achieve equivalent results.
|
||||||
class QSorter : public Xapian::Sorter {
|
class QSorter : public Xapian::Sorter {
|
||||||
public:
|
public:
|
||||||
QSorter(const string& f)
|
QSorter(const string& f)
|
||||||
: m_fld(docfToDatf(f) + "=")
|
: m_fld(docfToDatf(f) + "=")
|
||||||
{
|
{
|
||||||
m_ismtime = !m_fld.compare("dmtime=");
|
m_ismtime = !m_fld.compare("dmtime=");
|
||||||
|
m_issize = !m_fld.compare("fbytes=") || !m_fld.compare("dbytes=");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string operator()(const Xapian::Document& xdoc) const
|
virtual std::string operator()(const Xapian::Document& xdoc) const
|
||||||
@ -89,13 +93,21 @@ public:
|
|||||||
if (i2 == string::npos)
|
if (i2 == string::npos)
|
||||||
return string();
|
return string();
|
||||||
|
|
||||||
|
string term = data.substr(i1, i2-i1);
|
||||||
|
if (m_ismtime) {
|
||||||
|
return term;
|
||||||
|
} else if (m_issize) {
|
||||||
|
// Left zeropad values for appropriate numeric sorting
|
||||||
|
leftzeropad(term, 12);
|
||||||
|
return term;
|
||||||
|
}
|
||||||
|
|
||||||
// Process data for better sorting. We should actually do the
|
// Process data for better sorting. We should actually do the
|
||||||
// unicode thing
|
// unicode thing
|
||||||
// (http://unicode.org/reports/tr10/#Introduction), but just
|
// (http://unicode.org/reports/tr10/#Introduction), but just
|
||||||
// removing accents and majuscules will remove the most
|
// removing accents and majuscules will remove the most
|
||||||
// glaring weirdnesses (or not, depending on your national
|
// glaring weirdnesses (or not, depending on your national
|
||||||
// approach to collating...)
|
// approach to collating...)
|
||||||
string term = data.substr(i1, i2-i1);
|
|
||||||
string sortterm;
|
string sortterm;
|
||||||
// We're not even sure the term is utf8 here (ie: url)
|
// We're not even sure the term is utf8 here (ie: url)
|
||||||
if (!unacmaybefold(term, sortterm, "UTF-8", true)) {
|
if (!unacmaybefold(term, sortterm, "UTF-8", true)) {
|
||||||
@ -114,6 +126,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
string m_fld;
|
string m_fld;
|
||||||
bool m_ismtime;
|
bool m_ismtime;
|
||||||
|
bool m_issize;
|
||||||
};
|
};
|
||||||
|
|
||||||
Query::Query(Db *db)
|
Query::Query(Db *db)
|
||||||
|
|||||||
@ -562,16 +562,22 @@ bool pcSubst(const string& in, string& out, map<string, string>& subs)
|
|||||||
// Convert byte count into unit (KB/MB...) appropriate for display
|
// Convert byte count into unit (KB/MB...) appropriate for display
|
||||||
string displayableBytes(off_t size)
|
string displayableBytes(off_t size)
|
||||||
{
|
{
|
||||||
char sizebuf[30];
|
char sizebuf[50];
|
||||||
const char * unit = " B ";
|
const char *unit;
|
||||||
|
|
||||||
if (size > 1024 && size < 1024*1024) {
|
if (size < 1024) {
|
||||||
|
unit = " B ";
|
||||||
|
} else if (size < 1024*1024) {
|
||||||
unit = " KB ";
|
unit = " KB ";
|
||||||
size /= 1024;
|
size /= 1024;
|
||||||
} else if (size >= 1024*1204) {
|
} else if (size < 1024*1024*1024) {
|
||||||
unit = " MB ";
|
unit = " MB ";
|
||||||
size /= (1024*1024);
|
size /= (1024*1024);
|
||||||
|
} else {
|
||||||
|
unit = " GB ";
|
||||||
|
size /= (1024*1024*1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(sizebuf, OFFTPC "%s", size, unit);
|
sprintf(sizebuf, OFFTPC "%s", size, unit);
|
||||||
return string(sizebuf);
|
return string(sizebuf);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,6 +178,12 @@ struct TempBuf {
|
|||||||
char *m_buf;
|
char *m_buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void leftzeropad(string& s, unsigned len)
|
||||||
|
{
|
||||||
|
if (s.length() && s.length() < len)
|
||||||
|
s = s.insert(0, len - s.length(), '0');
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef deleteZ
|
#ifndef deleteZ
|
||||||
#define deleteZ(X) {delete X;X = 0;}
|
#define deleteZ(X) {delete X;X = 0;}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user