mirror of https://github.com/djcb/mu.git
* rename MuQueryXapian => MuQuery
This commit is contained in:
parent
ba2cb41585
commit
0c04143bbc
|
@ -80,8 +80,8 @@ libmu_la_SOURCES= \
|
|||
mu-msg-str.c \
|
||||
mu-msg-str.h \
|
||||
mu-msg.h \
|
||||
mu-query-xapian.cc \
|
||||
mu-query-xapian.h \
|
||||
mu-query.cc \
|
||||
mu-query.h \
|
||||
mu-result.h \
|
||||
mu-store-xapian.cc \
|
||||
mu-store-xapian.h \
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "mu-msg.h"
|
||||
#include "mu-maildir.h"
|
||||
#include "mu-index.h"
|
||||
#include "mu-query-xapian.h"
|
||||
#include "mu-query.h"
|
||||
#include "mu-msg-iter.h"
|
||||
#include "mu-msg-str.h"
|
||||
|
||||
|
@ -51,13 +51,13 @@ update_warning (void)
|
|||
|
||||
|
||||
static gboolean
|
||||
print_xapian_query (MuQueryXapian *xapian, const gchar *query)
|
||||
print_xapian_query (MuQuery *xapian, const gchar *query)
|
||||
{
|
||||
char *querystr;
|
||||
|
||||
MU_WRITE_LOG ("query: '%s' (xquery)", query);
|
||||
|
||||
querystr = mu_query_xapian_as_string (xapian, query);
|
||||
querystr = mu_query_as_string (xapian, query);
|
||||
g_print ("%s\n", querystr);
|
||||
g_free (querystr);
|
||||
|
||||
|
@ -236,7 +236,7 @@ make_links (MuMsgIter *iter, const char* linksdir, gboolean clearlinks)
|
|||
|
||||
|
||||
static gboolean
|
||||
run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||
run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts)
|
||||
{
|
||||
MuMsgIter *iter;
|
||||
const MuMsgField *sortfield;
|
||||
|
@ -251,7 +251,7 @@ run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
iter = mu_query_xapian_run (xapian, query, sortfield,
|
||||
iter = mu_query_run (xapian, query, sortfield,
|
||||
!opts->descending, 0);
|
||||
if (!iter) {
|
||||
g_printerr ("error: running query failed\n");
|
||||
|
@ -273,7 +273,7 @@ run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
|||
|
||||
|
||||
static gboolean
|
||||
do_output (MuQueryXapian *xapian, MuConfigOptions* opts,
|
||||
do_output (MuQuery *xapian, MuConfigOptions* opts,
|
||||
const gchar **params)
|
||||
{
|
||||
gchar *query;
|
||||
|
@ -320,7 +320,7 @@ query_params_valid (MuConfigOptions *opts)
|
|||
gboolean
|
||||
mu_cmd_find (MuConfigOptions *opts)
|
||||
{
|
||||
MuQueryXapian *xapian;
|
||||
MuQuery *xapian;
|
||||
gboolean rv;
|
||||
const gchar **params;
|
||||
|
||||
|
@ -345,7 +345,7 @@ mu_cmd_find (MuConfigOptions *opts)
|
|||
|
||||
mu_msg_init();
|
||||
|
||||
xapian = mu_query_xapian_new (opts->xpath);
|
||||
xapian = mu_query_new (opts->xpath);
|
||||
if (!xapian) {
|
||||
g_printerr ("Failed to create a Xapian query\n");
|
||||
mu_msg_uninit ();
|
||||
|
@ -354,7 +354,7 @@ mu_cmd_find (MuConfigOptions *opts)
|
|||
|
||||
rv = do_output (xapian, opts, params);
|
||||
|
||||
mu_query_xapian_destroy (xapian);
|
||||
mu_query_destroy (xapian);
|
||||
mu_msg_uninit();
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
|
@ -23,7 +23,7 @@
|
|||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "mu-query-xapian.h"
|
||||
#include "mu-query.h"
|
||||
|
||||
#include "mu-msg-iter.h"
|
||||
#include "mu-msg-iter-priv.hh"
|
||||
|
@ -35,14 +35,14 @@
|
|||
static void add_prefix (const MuMsgField* field,
|
||||
Xapian::QueryParser* qparser);
|
||||
|
||||
struct _MuQueryXapian {
|
||||
struct _MuQuery {
|
||||
Xapian::Database* _db;
|
||||
Xapian::QueryParser* _qparser;
|
||||
Xapian::Sorter* _sorters[MU_MSG_FIELD_TYPE_NUM];
|
||||
};
|
||||
|
||||
gboolean
|
||||
init_mu_query_xapian (MuQueryXapian *mqx, const char* dbpath)
|
||||
init_mu_query (MuQuery *mqx, const char* dbpath)
|
||||
{
|
||||
mqx->_db = 0;
|
||||
mqx->_qparser = 0;
|
||||
|
@ -74,7 +74,7 @@ init_mu_query_xapian (MuQueryXapian *mqx, const char* dbpath)
|
|||
|
||||
|
||||
static void
|
||||
uninit_mu_query_xapian (MuQueryXapian *mqx)
|
||||
uninit_mu_query (MuQuery *mqx)
|
||||
{
|
||||
try {
|
||||
delete mqx->_db;
|
||||
|
@ -87,7 +87,7 @@ uninit_mu_query_xapian (MuQueryXapian *mqx)
|
|||
}
|
||||
|
||||
static Xapian::Query
|
||||
get_query (MuQueryXapian * mqx, const char* searchexpr, int *err = 0) {
|
||||
get_query (MuQuery * mqx, const char* searchexpr, int *err = 0) {
|
||||
|
||||
try {
|
||||
return mqx->_qparser->parse_query
|
||||
|
@ -125,10 +125,10 @@ add_prefix (const MuMsgField* field, Xapian::QueryParser* qparser)
|
|||
qparser->add_prefix ("", prefix);
|
||||
}
|
||||
|
||||
MuQueryXapian*
|
||||
mu_query_xapian_new (const char* xpath)
|
||||
MuQuery*
|
||||
mu_query_new (const char* xpath)
|
||||
{
|
||||
MuQueryXapian *mqx;
|
||||
MuQuery *mqx;
|
||||
|
||||
g_return_val_if_fail (xpath, NULL);
|
||||
|
||||
|
@ -148,9 +148,9 @@ mu_query_xapian_new (const char* xpath)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mqx = g_new (MuQueryXapian, 1);
|
||||
mqx = g_new (MuQuery, 1);
|
||||
|
||||
if (!init_mu_query_xapian (mqx, xpath)) {
|
||||
if (!init_mu_query (mqx, xpath)) {
|
||||
g_warning ("failed to initialize the Xapian query");
|
||||
g_free (mqx);
|
||||
return NULL;
|
||||
|
@ -161,19 +161,19 @@ mu_query_xapian_new (const char* xpath)
|
|||
|
||||
|
||||
void
|
||||
mu_query_xapian_destroy (MuQueryXapian *self)
|
||||
mu_query_destroy (MuQuery *self)
|
||||
{
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
uninit_mu_query_xapian (self);
|
||||
uninit_mu_query (self);
|
||||
|
||||
g_free (self);
|
||||
}
|
||||
|
||||
|
||||
MuMsgIter*
|
||||
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
||||
mu_query_run (MuQuery *self, const char* searchexpr,
|
||||
const MuMsgField* sortfield, gboolean ascending,
|
||||
size_t batchsize)
|
||||
{
|
||||
|
@ -208,7 +208,7 @@ mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
|||
}
|
||||
|
||||
char*
|
||||
mu_query_xapian_as_string (MuQueryXapian *self, const char* searchexpr)
|
||||
mu_query_as_string (MuQuery *self, const char* searchexpr)
|
||||
{
|
||||
g_return_val_if_fail (self, NULL);
|
||||
g_return_val_if_fail (searchexpr, NULL);
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,54 +17,51 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_QUERY_XAPIAN_H__
|
||||
#define __MU_QUERY_XAPIAN_H__
|
||||
#ifndef __MU_QUERY_H__
|
||||
#define __MU_QUERY_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "mu-msg-iter.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/*
|
||||
* MuQueryXapian
|
||||
*/
|
||||
|
||||
struct _MuQueryXapian;
|
||||
typedef struct _MuQueryXapian MuQueryXapian;
|
||||
struct _MuQuery;
|
||||
typedef struct _MuQuery MuQuery;
|
||||
|
||||
/**
|
||||
* create a new MuQueryXapian instance.
|
||||
/**
|
||||
* create a new MuQuery instance.
|
||||
*
|
||||
* @param path path to the xapian db to search
|
||||
* @param err receives error information (if there is any)
|
||||
*
|
||||
* @return a new MuQueryXapian instance, or NULL in case of error.
|
||||
* when the instance is no longer needed, use mu_query_xapian_destroy
|
||||
* @return a new MuQuery instance, or NULL in case of error.
|
||||
* when the instance is no longer needed, use mu_query_destroy
|
||||
* to free it
|
||||
*/
|
||||
MuQueryXapian *mu_query_xapian_new (const char* path) G_GNUC_WARN_UNUSED_RESULT;
|
||||
MuQuery *mu_query_new (const char* path) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
* destroy the MuQueryXapian instance
|
||||
/**
|
||||
* destroy the MuQuery instance
|
||||
*
|
||||
* @param self a MuQueryXapian instance, or NULL
|
||||
* @param self a MuQuery instance, or NULL
|
||||
*/
|
||||
void mu_query_xapian_destroy (MuQueryXapian *self);
|
||||
void mu_query_destroy (MuQuery *self);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* get a version string for the database
|
||||
*
|
||||
* @param store a valid MuQueryXapian
|
||||
* @param store a valid MuQuery
|
||||
*
|
||||
* @return the version string (free with g_free), or NULL in case of error
|
||||
*/
|
||||
char* mu_query_xapian_version (MuQueryXapian *store) G_GNUC_WARN_UNUSED_RESULT;
|
||||
char* mu_query_version (MuQuery *store) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
/**
|
||||
* run a Xapian query; for the syntax, please refer to the mu-find
|
||||
* manpage, or http://xapian.org/docs/queryparser.html
|
||||
*
|
||||
* @param self a valid MuQueryXapian instance
|
||||
* @param self a valid MuQuery instance
|
||||
* @param expr the search expression
|
||||
* @param sortfield the field to sort by
|
||||
* @param ascending if TRUE sort in ascending (A-Z) order, otherwise,
|
||||
|
@ -77,26 +74,25 @@ char* mu_query_xapian_version (MuQueryXapian *store) G_GNUC_WARN_UNUSED_RESULT;
|
|||
* @return a MuMsgIter instance you can iterate over, or NULL in
|
||||
* case of error
|
||||
*/
|
||||
MuMsgIter* mu_query_xapian_run (MuQueryXapian *self,
|
||||
MuMsgIter* mu_query_run (MuQuery *self,
|
||||
const char* expr,
|
||||
const MuMsgField* sortfield,
|
||||
gboolean ascending,
|
||||
size_t batchsize) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* get a string representation of the Xapian search query
|
||||
*
|
||||
* @param self a MuQueryXapian instance
|
||||
* @param self a MuQuery instance
|
||||
* @param searchexpr a xapian search expression
|
||||
*
|
||||
* @return the string representation of the xapian query, or NULL in case of
|
||||
* error; free the returned value with g_free
|
||||
*/
|
||||
char* mu_query_xapian_as_string (MuQueryXapian *self,
|
||||
const char* searchexpr) G_GNUC_WARN_UNUSED_RESULT;
|
||||
char* mu_query_as_string (MuQuery *self,
|
||||
const char* searchexpr) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_QUERY_XAPIAN_H__*/
|
||||
#endif /*__MU_QUERY_H__*/
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
|
||||
#include "test-mu-common.h"
|
||||
#include "src/mu-query-xapian.h"
|
||||
#include "src/mu-query.h"
|
||||
|
||||
|
||||
static void shutup (void) {}
|
||||
|
@ -78,7 +78,7 @@ typedef struct {
|
|||
static void
|
||||
test_mu_query_01 (void)
|
||||
{
|
||||
MuQueryXapian *query;
|
||||
MuQuery *query;
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
||||
|
@ -94,19 +94,19 @@ test_mu_query_01 (void)
|
|||
xpath = fill_database ();
|
||||
g_assert (xpath != NULL);
|
||||
|
||||
query = mu_query_xapian_new (xpath);
|
||||
query = mu_query_new (xpath);
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||
int count = 0;
|
||||
MuMsgIter *iter =
|
||||
mu_query_xapian_run (query, queries[i].query, NULL,
|
||||
mu_query_run (query, queries[i].query, NULL,
|
||||
FALSE, 1);
|
||||
|
||||
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
||||
mu_msg_iter_destroy (iter);
|
||||
}
|
||||
|
||||
mu_query_xapian_destroy (query);
|
||||
mu_query_destroy (query);
|
||||
g_free (xpath);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ static void
|
|||
test_mu_query_02 (void)
|
||||
{
|
||||
MuMsgIter *iter;
|
||||
MuQueryXapian *query;
|
||||
MuQuery *query;
|
||||
const char* q;
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
@ -123,16 +123,16 @@ test_mu_query_02 (void)
|
|||
xpath = fill_database ();
|
||||
g_assert (xpath != NULL);
|
||||
|
||||
query = mu_query_xapian_new (xpath);
|
||||
query = mu_query_new (xpath);
|
||||
g_assert (query);
|
||||
|
||||
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com";
|
||||
iter = mu_query_xapian_run (query, q, NULL, FALSE, 0);
|
||||
iter = mu_query_run (query, q, NULL, FALSE, 0);
|
||||
|
||||
g_assert (iter);
|
||||
g_assert_cmpuint (count_matches(iter), ==, 1);
|
||||
|
||||
mu_query_xapian_destroy (query);
|
||||
mu_query_destroy (query);
|
||||
g_free (xpath);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ test_mu_query_02 (void)
|
|||
static void
|
||||
test_mu_query_03 (void)
|
||||
{
|
||||
MuQueryXapian *query;
|
||||
MuQuery *query;
|
||||
gchar *xpath;
|
||||
int i;
|
||||
|
||||
|
@ -150,19 +150,19 @@ test_mu_query_03 (void)
|
|||
xpath = fill_database ();
|
||||
g_assert (xpath != NULL);
|
||||
|
||||
query = mu_query_xapian_new (xpath);
|
||||
query = mu_query_new (xpath);
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||
int count = 0;
|
||||
MuMsgIter *iter =
|
||||
mu_query_xapian_run (query, queries[i].query, NULL,
|
||||
mu_query_run (query, queries[i].query, NULL,
|
||||
FALSE, 1);
|
||||
|
||||
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
||||
mu_msg_iter_destroy (iter);
|
||||
}
|
||||
|
||||
mu_query_xapian_destroy (query);
|
||||
mu_query_destroy (query);
|
||||
g_free (xpath);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue