* rename MuQueryXapian => MuQuery

This commit is contained in:
djcb
2010-08-25 21:46:16 +03:00
parent ba2cb41585
commit 0c04143bbc
5 changed files with 64 additions and 68 deletions

View File

@ -80,8 +80,8 @@ libmu_la_SOURCES= \
mu-msg-str.c \ mu-msg-str.c \
mu-msg-str.h \ mu-msg-str.h \
mu-msg.h \ mu-msg.h \
mu-query-xapian.cc \ mu-query.cc \
mu-query-xapian.h \ mu-query.h \
mu-result.h \ mu-result.h \
mu-store-xapian.cc \ mu-store-xapian.cc \
mu-store-xapian.h \ mu-store-xapian.h \

View File

@ -31,7 +31,7 @@
#include "mu-msg.h" #include "mu-msg.h"
#include "mu-maildir.h" #include "mu-maildir.h"
#include "mu-index.h" #include "mu-index.h"
#include "mu-query-xapian.h" #include "mu-query.h"
#include "mu-msg-iter.h" #include "mu-msg-iter.h"
#include "mu-msg-str.h" #include "mu-msg-str.h"
@ -51,13 +51,13 @@ update_warning (void)
static gboolean static gboolean
print_xapian_query (MuQueryXapian *xapian, const gchar *query) print_xapian_query (MuQuery *xapian, const gchar *query)
{ {
char *querystr; char *querystr;
MU_WRITE_LOG ("query: '%s' (xquery)", query); 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_print ("%s\n", querystr);
g_free (querystr); g_free (querystr);
@ -236,7 +236,7 @@ make_links (MuMsgIter *iter, const char* linksdir, gboolean clearlinks)
static gboolean static gboolean
run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts) run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts)
{ {
MuMsgIter *iter; MuMsgIter *iter;
const MuMsgField *sortfield; const MuMsgField *sortfield;
@ -251,7 +251,7 @@ run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
return FALSE; return FALSE;
} }
iter = mu_query_xapian_run (xapian, query, sortfield, iter = mu_query_run (xapian, query, sortfield,
!opts->descending, 0); !opts->descending, 0);
if (!iter) { if (!iter) {
g_printerr ("error: running query failed\n"); g_printerr ("error: running query failed\n");
@ -273,7 +273,7 @@ run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
static gboolean static gboolean
do_output (MuQueryXapian *xapian, MuConfigOptions* opts, do_output (MuQuery *xapian, MuConfigOptions* opts,
const gchar **params) const gchar **params)
{ {
gchar *query; gchar *query;
@ -320,7 +320,7 @@ query_params_valid (MuConfigOptions *opts)
gboolean gboolean
mu_cmd_find (MuConfigOptions *opts) mu_cmd_find (MuConfigOptions *opts)
{ {
MuQueryXapian *xapian; MuQuery *xapian;
gboolean rv; gboolean rv;
const gchar **params; const gchar **params;
@ -345,7 +345,7 @@ mu_cmd_find (MuConfigOptions *opts)
mu_msg_init(); mu_msg_init();
xapian = mu_query_xapian_new (opts->xpath); xapian = mu_query_new (opts->xpath);
if (!xapian) { if (!xapian) {
g_printerr ("Failed to create a Xapian query\n"); g_printerr ("Failed to create a Xapian query\n");
mu_msg_uninit (); mu_msg_uninit ();
@ -354,7 +354,7 @@ mu_cmd_find (MuConfigOptions *opts)
rv = do_output (xapian, opts, params); rv = do_output (xapian, opts, params);
mu_query_xapian_destroy (xapian); mu_query_destroy (xapian);
mu_msg_uninit(); mu_msg_uninit();
return rv; return rv;

View File

@ -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 ** 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 ** it under the terms of the GNU General Public License as published by
@ -23,7 +23,7 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include "mu-query-xapian.h" #include "mu-query.h"
#include "mu-msg-iter.h" #include "mu-msg-iter.h"
#include "mu-msg-iter-priv.hh" #include "mu-msg-iter-priv.hh"
@ -35,14 +35,14 @@
static void add_prefix (const MuMsgField* field, static void add_prefix (const MuMsgField* field,
Xapian::QueryParser* qparser); Xapian::QueryParser* qparser);
struct _MuQueryXapian { struct _MuQuery {
Xapian::Database* _db; Xapian::Database* _db;
Xapian::QueryParser* _qparser; Xapian::QueryParser* _qparser;
Xapian::Sorter* _sorters[MU_MSG_FIELD_TYPE_NUM]; Xapian::Sorter* _sorters[MU_MSG_FIELD_TYPE_NUM];
}; };
gboolean gboolean
init_mu_query_xapian (MuQueryXapian *mqx, const char* dbpath) init_mu_query (MuQuery *mqx, const char* dbpath)
{ {
mqx->_db = 0; mqx->_db = 0;
mqx->_qparser = 0; mqx->_qparser = 0;
@ -74,7 +74,7 @@ init_mu_query_xapian (MuQueryXapian *mqx, const char* dbpath)
static void static void
uninit_mu_query_xapian (MuQueryXapian *mqx) uninit_mu_query (MuQuery *mqx)
{ {
try { try {
delete mqx->_db; delete mqx->_db;
@ -87,7 +87,7 @@ uninit_mu_query_xapian (MuQueryXapian *mqx)
} }
static Xapian::Query static Xapian::Query
get_query (MuQueryXapian * mqx, const char* searchexpr, int *err = 0) { get_query (MuQuery * mqx, const char* searchexpr, int *err = 0) {
try { try {
return mqx->_qparser->parse_query return mqx->_qparser->parse_query
@ -125,10 +125,10 @@ add_prefix (const MuMsgField* field, Xapian::QueryParser* qparser)
qparser->add_prefix ("", prefix); qparser->add_prefix ("", prefix);
} }
MuQueryXapian* MuQuery*
mu_query_xapian_new (const char* xpath) mu_query_new (const char* xpath)
{ {
MuQueryXapian *mqx; MuQuery *mqx;
g_return_val_if_fail (xpath, NULL); g_return_val_if_fail (xpath, NULL);
@ -148,9 +148,9 @@ mu_query_xapian_new (const char* xpath)
return NULL; 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_warning ("failed to initialize the Xapian query");
g_free (mqx); g_free (mqx);
return NULL; return NULL;
@ -161,19 +161,19 @@ mu_query_xapian_new (const char* xpath)
void void
mu_query_xapian_destroy (MuQueryXapian *self) mu_query_destroy (MuQuery *self)
{ {
if (!self) if (!self)
return; return;
uninit_mu_query_xapian (self); uninit_mu_query (self);
g_free (self); g_free (self);
} }
MuMsgIter* MuMsgIter*
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr, mu_query_run (MuQuery *self, const char* searchexpr,
const MuMsgField* sortfield, gboolean ascending, const MuMsgField* sortfield, gboolean ascending,
size_t batchsize) size_t batchsize)
{ {
@ -208,7 +208,7 @@ mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
} }
char* 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 (self, NULL);
g_return_val_if_fail (searchexpr, NULL); g_return_val_if_fail (searchexpr, NULL);

View File

@ -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 ** 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 ** it under the terms of the GNU General Public License as published by
@ -17,54 +17,51 @@
** **
*/ */
#ifndef __MU_QUERY_XAPIAN_H__ #ifndef __MU_QUERY_H__
#define __MU_QUERY_XAPIAN_H__ #define __MU_QUERY_H__
#include <glib.h> #include <glib.h>
#include "mu-msg-iter.h" #include "mu-msg-iter.h"
G_BEGIN_DECLS G_BEGIN_DECLS
/*
* MuQueryXapian
*/
struct _MuQueryXapian; struct _MuQuery;
typedef struct _MuQueryXapian MuQueryXapian; typedef struct _MuQuery MuQuery;
/** /**
* create a new MuQueryXapian instance. * create a new MuQuery instance.
* *
* @param path path to the xapian db to search * @param path path to the xapian db to search
* @param err receives error information (if there is any) * @param err receives error information (if there is any)
* *
* @return a new MuQueryXapian instance, or NULL in case of error. * @return a new MuQuery instance, or NULL in case of error.
* when the instance is no longer needed, use mu_query_xapian_destroy * when the instance is no longer needed, use mu_query_destroy
* to free it * 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 * 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 * @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 * run a Xapian query; for the syntax, please refer to the mu-find
* manpage, or http://xapian.org/docs/queryparser.html * 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 expr the search expression
* @param sortfield the field to sort by * @param sortfield the field to sort by
* @param ascending if TRUE sort in ascending (A-Z) order, otherwise, * @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 * @return a MuMsgIter instance you can iterate over, or NULL in
* case of error * case of error
*/ */
MuMsgIter* mu_query_xapian_run (MuQueryXapian *self, MuMsgIter* mu_query_run (MuQuery *self,
const char* expr, const char* expr,
const MuMsgField* sortfield, const MuMsgField* sortfield,
gboolean ascending, gboolean ascending,
size_t batchsize) G_GNUC_WARN_UNUSED_RESULT; size_t batchsize) G_GNUC_WARN_UNUSED_RESULT;
/** /**
* get a string representation of the Xapian search query * 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 * @param searchexpr a xapian search expression
* *
* @return the string representation of the xapian query, or NULL in case of * @return the string representation of the xapian query, or NULL in case of
* error; free the returned value with g_free * error; free the returned value with g_free
*/ */
char* mu_query_xapian_as_string (MuQueryXapian *self, char* mu_query_as_string (MuQuery *self,
const char* searchexpr) G_GNUC_WARN_UNUSED_RESULT; const char* searchexpr) G_GNUC_WARN_UNUSED_RESULT;
G_END_DECLS G_END_DECLS
#endif /*__MU_QUERY_XAPIAN_H__*/ #endif /*__MU_QUERY_H__*/

View File

@ -30,7 +30,7 @@
#include "test-mu-common.h" #include "test-mu-common.h"
#include "src/mu-query-xapian.h" #include "src/mu-query.h"
static void shutup (void) {} static void shutup (void) {}
@ -78,7 +78,7 @@ typedef struct {
static void static void
test_mu_query_01 (void) test_mu_query_01 (void)
{ {
MuQueryXapian *query; MuQuery *query;
gchar *xpath; gchar *xpath;
int i; int i;
@ -94,19 +94,19 @@ test_mu_query_01 (void)
xpath = fill_database (); xpath = fill_database ();
g_assert (xpath != NULL); g_assert (xpath != NULL);
query = mu_query_xapian_new (xpath); query = mu_query_new (xpath);
for (i = 0; i != G_N_ELEMENTS(queries); ++i) { for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
int count = 0; int count = 0;
MuMsgIter *iter = MuMsgIter *iter =
mu_query_xapian_run (query, queries[i].query, NULL, mu_query_run (query, queries[i].query, NULL,
FALSE, 1); FALSE, 1);
g_assert_cmpuint (queries[i].count, ==, count_matches(iter)); g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
mu_msg_iter_destroy (iter); mu_msg_iter_destroy (iter);
} }
mu_query_xapian_destroy (query); mu_query_destroy (query);
g_free (xpath); g_free (xpath);
} }
@ -115,7 +115,7 @@ static void
test_mu_query_02 (void) test_mu_query_02 (void)
{ {
MuMsgIter *iter; MuMsgIter *iter;
MuQueryXapian *query; MuQuery *query;
const char* q; const char* q;
gchar *xpath; gchar *xpath;
int i; int i;
@ -123,16 +123,16 @@ test_mu_query_02 (void)
xpath = fill_database (); xpath = fill_database ();
g_assert (xpath != NULL); g_assert (xpath != NULL);
query = mu_query_xapian_new (xpath); query = mu_query_new (xpath);
g_assert (query); g_assert (query);
q = "i:f7ccd24b0808061357t453f5962w8b61f9a453b684d0@mail.gmail.com"; 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 (iter);
g_assert_cmpuint (count_matches(iter), ==, 1); g_assert_cmpuint (count_matches(iter), ==, 1);
mu_query_xapian_destroy (query); mu_query_destroy (query);
g_free (xpath); g_free (xpath);
} }
@ -140,7 +140,7 @@ test_mu_query_02 (void)
static void static void
test_mu_query_03 (void) test_mu_query_03 (void)
{ {
MuQueryXapian *query; MuQuery *query;
gchar *xpath; gchar *xpath;
int i; int i;
@ -150,19 +150,19 @@ test_mu_query_03 (void)
xpath = fill_database (); xpath = fill_database ();
g_assert (xpath != NULL); g_assert (xpath != NULL);
query = mu_query_xapian_new (xpath); query = mu_query_new (xpath);
for (i = 0; i != G_N_ELEMENTS(queries); ++i) { for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
int count = 0; int count = 0;
MuMsgIter *iter = MuMsgIter *iter =
mu_query_xapian_run (query, queries[i].query, NULL, mu_query_run (query, queries[i].query, NULL,
FALSE, 1); FALSE, 1);
g_assert_cmpuint (queries[i].count, ==, count_matches(iter)); g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
mu_msg_iter_destroy (iter); mu_msg_iter_destroy (iter);
} }
mu_query_xapian_destroy (query); mu_query_destroy (query);
g_free (xpath); g_free (xpath);
} }