mu: support 'raw' query (internally)

Allow for passing 'raw' queries to xapian, without any parsing.
This commit is contained in:
djcb
2017-12-03 22:16:32 +02:00
parent f840d0deaa
commit 620912c62b
2 changed files with 29 additions and 28 deletions

View File

@ -194,22 +194,20 @@ private:
}; };
static const Xapian::Query static const Xapian::Query
get_query (MuQuery *mqx, const char* searchexpr, GError **err) get_query (MuQuery *mqx, const char* searchexpr, bool raw, GError **err) try {
{
try {
Mux::WarningVec warns;
const auto tree = Mux::parse (searchexpr, warns,
std::make_unique<MuProc>(mqx->db()));
for (const auto w: warns)
std::cerr << w << std::endl;
return Mux::xapian_query (tree); Mux::WarningVec warns;
const auto tree = Mux::parse (searchexpr, warns,
std::make_unique<MuProc>(mqx->db()));
for (const auto w: warns)
std::cerr << w << std::endl;
} catch (...) { return Mux::xapian_query (tree);
mu_util_g_set_error (err,MU_ERROR_XAPIAN_QUERY,
"parse error in query"); } catch (...) {
throw; mu_util_g_set_error (err,MU_ERROR_XAPIAN_QUERY,
} "parse error in query");
throw;
} }
MuQuery* MuQuery*
@ -279,16 +277,17 @@ msg_iter_flags (MuQueryFlags flags)
static Xapian::Enquire static Xapian::Enquire
get_enquire (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid, get_enquire (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
bool descending, GError **err) bool descending, bool raw, GError **err)
{ {
Xapian::Enquire enq (self->db()); Xapian::Enquire enq (self->db());
try { try {
/* empty or "" means "matchall" */ if (raw)
if (!mu_str_is_empty(searchexpr) && enq.set_query(Xapian::Query(Xapian::Query(searchexpr)));
else if (!mu_str_is_empty(searchexpr) &&
g_strcmp0 (searchexpr, "\"\"") != 0) /* NULL or "" or """" */ g_strcmp0 (searchexpr, "\"\"") != 0) /* NULL or "" or """" */
enq.set_query(get_query (self, searchexpr, err)); enq.set_query(get_query (self, searchexpr, raw, err));
else else/* empty or "" means "matchall" */
enq.set_query(Xapian::Query::MatchAll); enq.set_query(Xapian::Query::MatchAll);
} catch (...) { } catch (...) {
mu_util_g_set_error (err, MU_ERROR_XAPIAN_QUERY, mu_util_g_set_error (err, MU_ERROR_XAPIAN_QUERY,
@ -413,15 +412,16 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid,
try { try {
MuMsgIter *iter; MuMsgIter *iter;
MuQueryFlags first_flags; MuQueryFlags first_flags;
bool inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED; const auto inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED;
bool descending = flags & MU_QUERY_FLAG_DESCENDING; const auto descending = flags & MU_QUERY_FLAG_DESCENDING;
const auto raw = flags & MU_QUERY_FLAG_RAW;
Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid, Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid,
descending, err)); descending, raw, err));
/* when we're doing a 'include-related query', we're /* when we're doing a 'include-related query', wea're actually
* actually doing /two/ queries; one to get the * doing /two/ queries; one to get the initial matches, and
* initial matches, and based on that one to get all * based on that one to get all messages in threads in those
* messages in threads in those matches. * matches.
*/ */
/* get the 'real' maxnum if it was specified as < 0 */ /* get the 'real' maxnum if it was specified as < 0 */
@ -470,7 +470,7 @@ mu_query_internal_xapian (MuQuery *self, const char *searchexpr, GError **err)
g_return_val_if_fail (searchexpr, NULL); g_return_val_if_fail (searchexpr, NULL);
try { try {
Xapian::Query query (get_query(self, searchexpr, err)); Xapian::Query query (get_query(self, searchexpr, false, err));
return g_strdup(query.get_description().c_str()); return g_strdup(query.get_description().c_str());
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL); } MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);

View File

@ -70,7 +70,8 @@ typedef enum {
MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 1, /**< skip unreadable msgs */ MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 1, /**< skip unreadable msgs */
MU_QUERY_FLAG_SKIP_DUPS = 1 << 2, /**< skip duplicate msgs */ MU_QUERY_FLAG_SKIP_DUPS = 1 << 2, /**< skip duplicate msgs */
MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3, /**< include related msgs */ MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3, /**< include related msgs */
MU_QUERY_FLAG_THREADS = 1 << 4 /**< calculate threading info */ MU_QUERY_FLAG_THREADS = 1 << 4, /**< calculate threading info */
MU_QUERY_FLAG_RAW = 1 << 5 /**< don't parse the query */
} MuQueryFlags; } MuQueryFlags;
/** /**