mirror of https://github.com/djcb/mu.git
* make size, date ranges work even if specified e->b. add unit tests.
This commit is contained in:
parent
e607aed8de
commit
fa3ee3c058
|
@ -51,9 +51,21 @@ public:
|
||||||
|
|
||||||
normalize_date (begin);
|
normalize_date (begin);
|
||||||
normalize_date (end);
|
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);
|
begin = complete_date12(begin,true);
|
||||||
complete_date (end, 12, false);
|
end = complete_date12(end, false);
|
||||||
|
|
||||||
return (Xapian::valueno)MU_MSG_PSEUDO_FIELD_ID_DATESTR;
|
return (Xapian::valueno)MU_MSG_PSEUDO_FIELD_ID_DATESTR;
|
||||||
}
|
}
|
||||||
|
@ -106,25 +118,23 @@ private:
|
||||||
char k = date[i];
|
char k = date[i];
|
||||||
if (std::isdigit(k))
|
if (std::isdigit(k))
|
||||||
cleanup += date[i];
|
cleanup += date[i];
|
||||||
// else if (k != ':' && k != '-' && k != '/' && k != '.' &&
|
|
||||||
// k != ',' && k != '_')
|
|
||||||
// throw std::runtime_error ("error in date str");
|
|
||||||
}
|
}
|
||||||
date = cleanup;
|
date = cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void complete_date (std::string& date, size_t len,
|
std::string complete_date12 (const std::string date, bool is_begin) const {
|
||||||
bool is_begin) const {
|
|
||||||
|
|
||||||
|
std::string compdate;
|
||||||
const std::string bsuffix ("00000101000000");
|
const std::string bsuffix ("00000101000000");
|
||||||
const std::string esuffix ("99991231235959");
|
const std::string esuffix ("99991231235959");
|
||||||
|
const size_t size = 12;
|
||||||
|
|
||||||
if (is_begin)
|
if (is_begin)
|
||||||
date = std::string (date + bsuffix.substr (date.length()));
|
compdate = std::string (date + bsuffix.substr (date.length()));
|
||||||
else
|
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))
|
if (!substitute_size (begin) || !substitute_size (end))
|
||||||
return Xapian::BAD_VALUENO;
|
return Xapian::BAD_VALUENO;
|
||||||
|
|
||||||
begin = Xapian::sortable_serialise(atol(begin.c_str()));
|
/* swap if b > e */
|
||||||
end = Xapian::sortable_serialise(atol(end.c_str()));
|
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;
|
return (Xapian::valueno)MU_MSG_FIELD_ID_SIZE;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -311,11 +311,12 @@ test_mu_query_dates (void)
|
||||||
|
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "date:20080731..20080804", 5},
|
{ "date:20080731..20080804", 5},
|
||||||
/* { "date:20080804..20080731", 5}, */
|
{ "date:20080804..20080731", 5},
|
||||||
{ "date:2008-07/31..2008@08:04", 5},
|
{ "date:2008-07/31..2008@08:04", 5},
|
||||||
{ "date:2008-0731..20080804 s:gcc", 1},
|
{ "date:2008-0731..20080804 s:gcc", 1},
|
||||||
{ "date:2008-08-11-08-03..now", 1},
|
{ "date:2008-08-11-08-03..now", 1},
|
||||||
{ "date:2008-08-11-08-05..now", 0}
|
{ "date:2008-08-11-08-03..today", 1},
|
||||||
|
{ "date:2008-08-11-08-05..now", 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database ();
|
xpath = fill_database ();
|
||||||
|
@ -339,7 +340,7 @@ test_mu_query_sizes (void)
|
||||||
QResults queries[] = {
|
QResults queries[] = {
|
||||||
{ "size:0b..2m", 12},
|
{ "size:0b..2m", 12},
|
||||||
{ "size:2k..4k", 2},
|
{ "size:2k..4k", 2},
|
||||||
/* { "size:2m..0b", 12}, */
|
{ "size:2m..0b", 12}
|
||||||
};
|
};
|
||||||
|
|
||||||
xpath = fill_database ();
|
xpath = fill_database ();
|
||||||
|
@ -373,10 +374,10 @@ main (int argc, char *argv[])
|
||||||
test_mu_query_accented_chars_02);
|
test_mu_query_accented_chars_02);
|
||||||
g_test_add_func ("/mu-query/test-mu-query-wildcards",
|
g_test_add_func ("/mu-query/test-mu-query-wildcards",
|
||||||
test_mu_query_wildcards);
|
test_mu_query_wildcards);
|
||||||
|
g_test_add_func ("/mu-query/test-mu-query-sizes",
|
||||||
|
test_mu_query_sizes);
|
||||||
g_test_add_func ("/mu-query/test-mu-query-dates",
|
g_test_add_func ("/mu-query/test-mu-query-dates",
|
||||||
test_mu_query_dates);
|
test_mu_query_dates);
|
||||||
g_test_add_func ("/mu-query/test-mu-query-sizes",
|
|
||||||
test_mu_query_sizes);
|
|
||||||
|
|
||||||
g_log_set_handler (NULL,
|
g_log_set_handler (NULL,
|
||||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
|
|
Loading…
Reference in New Issue