* make size, date ranges work even if specified e->b. add unit tests.
This commit is contained in:
@ -51,9 +51,21 @@ public:
|
||||
|
||||
normalize_date (begin);
|
||||
normalize_date (end);
|
||||
|
||||
// note, we'll have to compare the *completed*
|
||||
// versions of begin and end to if the were specified
|
||||
// in the opposite order; however, if that is true, we
|
||||
// have to complete begin, end 'for real', as the
|
||||
// begin date is completed to the begin of the
|
||||
// interval, and the to the end of the interval
|
||||
// ie. begin: 2008 -> 200801010000
|
||||
// end: 2008 -> 200812312359
|
||||
if (complete_date12(begin,true) >
|
||||
complete_date12(end, false))
|
||||
std::swap (begin, end);
|
||||
|
||||
complete_date (begin, 12, true);
|
||||
complete_date (end, 12, false);
|
||||
begin = complete_date12(begin,true);
|
||||
end = complete_date12(end, false);
|
||||
|
||||
return (Xapian::valueno)MU_MSG_PSEUDO_FIELD_ID_DATESTR;
|
||||
}
|
||||
@ -106,25 +118,23 @@ private:
|
||||
char k = date[i];
|
||||
if (std::isdigit(k))
|
||||
cleanup += date[i];
|
||||
// else if (k != ':' && k != '-' && k != '/' && k != '.' &&
|
||||
// k != ',' && k != '_')
|
||||
// throw std::runtime_error ("error in date str");
|
||||
}
|
||||
date = cleanup;
|
||||
}
|
||||
|
||||
void complete_date (std::string& date, size_t len,
|
||||
bool is_begin) const {
|
||||
std::string complete_date12 (const std::string date, bool is_begin) const {
|
||||
|
||||
std::string compdate;
|
||||
const std::string bsuffix ("00000101000000");
|
||||
const std::string esuffix ("99991231235959");
|
||||
|
||||
const size_t size = 12;
|
||||
|
||||
if (is_begin)
|
||||
date = std::string (date + bsuffix.substr (date.length()));
|
||||
compdate = std::string (date + bsuffix.substr (date.length()));
|
||||
else
|
||||
date = std::string (date + esuffix.substr (date.length()));
|
||||
compdate = std::string (date + esuffix.substr (date.length()));
|
||||
|
||||
date = date.substr (0, len);
|
||||
return compdate.substr (0, size);
|
||||
}
|
||||
};
|
||||
|
||||
@ -143,9 +153,13 @@ public:
|
||||
if (!substitute_size (begin) || !substitute_size (end))
|
||||
return Xapian::BAD_VALUENO;
|
||||
|
||||
begin = Xapian::sortable_serialise(atol(begin.c_str()));
|
||||
end = Xapian::sortable_serialise(atol(end.c_str()));
|
||||
|
||||
/* swap if b > e */
|
||||
if (begin > end)
|
||||
std::swap (begin, end);
|
||||
|
||||
begin = Xapian::sortable_serialise (atol(begin.c_str()));
|
||||
end = Xapian::sortable_serialise (atol(end.c_str()));
|
||||
|
||||
return (Xapian::valueno)MU_MSG_FIELD_ID_SIZE;
|
||||
}
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user