store/query: update for new store/query api
Update to the new API.
This commit is contained in:
@ -57,13 +57,14 @@ constexpr auto LastOutput{OutputInfo{0, false, true}};
|
||||
using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*, GError**)>;
|
||||
|
||||
static gboolean
|
||||
print_internal(const Query& query,
|
||||
print_internal(const Store& store,
|
||||
const std::string& expr,
|
||||
gboolean xapian,
|
||||
gboolean warn,
|
||||
GError** err)
|
||||
{
|
||||
std::cout << query.parse(expr, xapian) << "\n";
|
||||
std::cout << store.parse_query(expr, xapian) << "\n";
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -88,7 +89,7 @@ sort_field_from_string(const char* fieldstr, GError** err)
|
||||
}
|
||||
|
||||
static Option<QueryResults>
|
||||
run_query(const Query& q, const std::string& expr, const MuConfig* opts, GError** err)
|
||||
run_query(const Store& store, const std::string& expr, const MuConfig* opts, GError** err)
|
||||
{
|
||||
MuMsgFieldId sortid;
|
||||
|
||||
@ -109,7 +110,7 @@ run_query(const Query& q, const std::string& expr, const MuConfig* opts, GError*
|
||||
if (opts->threads)
|
||||
qflags |= QueryFlags::Threading;
|
||||
|
||||
return q.run(expr, sortid, qflags, opts->maxnum);
|
||||
return store.run_query(expr, sortid, qflags, opts->maxnum);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -196,20 +197,6 @@ get_query(const MuConfig* opts, GError** err)
|
||||
return q;
|
||||
}
|
||||
|
||||
static Mu::Query
|
||||
get_query_obj(const Store& store, GError** err)
|
||||
{
|
||||
const auto count{store.size()};
|
||||
|
||||
if (count == (unsigned)-1)
|
||||
throw Mu::Error(Error::Code::Store, "invalid store");
|
||||
|
||||
if (count == 0)
|
||||
throw Mu::Error(Error::Code::Store, "store is empty");
|
||||
|
||||
return Mu::Query{store};
|
||||
}
|
||||
|
||||
static gboolean
|
||||
prepare_links(const MuConfig* opts, GError** err)
|
||||
{
|
||||
@ -391,7 +378,9 @@ thread_indent(const QueryMatch& info, const MuConfig* opts)
|
||||
::fputs("/", stdout);
|
||||
else
|
||||
::fputs(" ", stdout);
|
||||
::fputs(empty_parent ? "*> " : is_dup ? "=> " : "-> ", stdout);
|
||||
::fputs(empty_parent ? "*> " : is_dup ? "=> "
|
||||
: "-> ",
|
||||
stdout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -616,9 +605,9 @@ output_query_results(const QueryResults& qres, const MuConfig* opts, GError** er
|
||||
}
|
||||
|
||||
static gboolean
|
||||
process_query(const Query& q, const std::string& expr, const MuConfig* opts, GError** err)
|
||||
process_query(const Store& store, const std::string& expr, const MuConfig* opts, GError** err)
|
||||
{
|
||||
auto qres{run_query(q, expr, opts, err)};
|
||||
auto qres{run_query(store, expr, opts, err)};
|
||||
if (!qres)
|
||||
return FALSE;
|
||||
|
||||
@ -633,17 +622,16 @@ process_query(const Query& q, const std::string& expr, const MuConfig* opts, GEr
|
||||
static gboolean
|
||||
execute_find(const Store& store, const MuConfig* opts, GError** err)
|
||||
{
|
||||
auto q{get_query_obj(store, err)};
|
||||
auto expr{get_query(opts, err)};
|
||||
if (!expr)
|
||||
return FALSE;
|
||||
|
||||
if (opts->format == MU_CONFIG_FORMAT_XQUERY)
|
||||
return print_internal(q, *expr, TRUE, FALSE, err);
|
||||
return print_internal(store, *expr, TRUE, FALSE, err);
|
||||
else if (opts->format == MU_CONFIG_FORMAT_MQUERY)
|
||||
return print_internal(q, *expr, FALSE, opts->verbose, err);
|
||||
return print_internal(store, *expr, FALSE, opts->verbose, err);
|
||||
else
|
||||
return process_query(q, *expr, opts, err);
|
||||
return process_query(store, *expr, opts, err);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
||||
@ -91,16 +91,15 @@ run_and_count_matches(const std::string& xpath,
|
||||
Mu::QueryFlags flags = Mu::QueryFlags::None)
|
||||
{
|
||||
Mu::Store store{xpath};
|
||||
Mu::Query query{store};
|
||||
|
||||
if (g_test_verbose()) {
|
||||
std::cout << "==> mquery: " << query.parse(expr, false) << "\n";
|
||||
std::cout << "==> xquery: " << query.parse(expr, true) << "\n";
|
||||
std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
|
||||
std::cout << "==> xquery: " << store.parse_query(expr, true) << "\n";
|
||||
}
|
||||
|
||||
Mu::allow_warnings();
|
||||
|
||||
auto qres{query.run(expr, MU_MSG_FIELD_ID_NONE, flags)};
|
||||
auto qres{store.run_query(expr, MU_MSG_FIELD_ID_NONE, flags)};
|
||||
g_assert_true(!!qres);
|
||||
assert_no_dups(*qres);
|
||||
|
||||
@ -236,9 +235,8 @@ static void
|
||||
test_mu_query_accented_chars_01(void)
|
||||
{
|
||||
Store store{DB_PATH1};
|
||||
Query q{store};
|
||||
|
||||
auto qres{q.run("fünkÿ")};
|
||||
auto qres{store.run_query("fünkÿ")};
|
||||
g_assert_true(!!qres);
|
||||
g_assert_false(qres->empty());
|
||||
|
||||
@ -571,31 +569,29 @@ test_mu_query_cjk(void)
|
||||
g_unsetenv("XAPIAN_CJK_NGRAM");
|
||||
const auto xpath = make_database(MU_TESTMAILDIR_CJK);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 1);
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 1);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
g_setenv("XAPIAN_CJK_NGRAM", "1", TRUE);
|
||||
const auto xpath = make_database(MU_TESTMAILDIR_CJK);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバがダウンしました",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
"サーバ",
|
||||
QueryFlags::None),
|
||||
==, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user