1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*
* Copyright (C) 2005 Laurent Sansonetti <lrz@chopine.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rbzoom.h"
#ifdef MAKING_RDOC_HAPPY
mZoom = rb_define_module("ZOOM");
#endif
/* Class: ZOOM::Query
* Search queries.
*/
static VALUE cZoomQuery;
static VALUE
rbz_query_make (ZOOM_query query)
{
return query != NULL
? Data_Wrap_Struct (cZoomQuery,
NULL,
ZOOM_query_destroy,
query)
: Qnil;
}
ZOOM_query
rbz_query_get (VALUE obj)
{
ZOOM_query query;
Data_Get_Struct (obj, struct ZOOM_query_p, query);
assert (query != NULL);
return query;
}
/*
* call-seq: new_prefix(prefix)
*
* prefix: PQF notation.
*
* Creates a RPN query using the given PQF notation.
*
* Returns: a newly created ZOOM::Query object.
*/
static VALUE
rbz_query_new_prefix (VALUE self, VALUE prefix)
{
ZOOM_query query;
query = ZOOM_query_create ();
ZOOM_query_prefix (query, RVAL2CSTR (prefix));
return rbz_query_make (query);
}
/* call-seq:
* new_cql(prefix)
*
* prefix: CQL notation.
*
* Creates a CQL query using the given CQL notation.
*
* Returns: a newly created ZOOM::Query object.
*/
static VALUE
rbz_query_new_cql (VALUE self, VALUE cql)
{
ZOOM_query query;
query = ZOOM_query_create ();
ZOOM_query_cql (query, RVAL2CSTR (cql));
return rbz_query_make (query);
}
/*
* call-seq: new_sort_by(criteria)
*
* criteria: a sort criteria.
*
* Creates a sort query from the YAZ sorting notation.
*
* Returns: a newly created ZOOM::Query object.
*/
static VALUE
rbz_query_new_sort_by (VALUE self, VALUE criteria)
{
ZOOM_query query;
query = ZOOM_query_create ();
ZOOM_query_sortby (rbz_query_get (self), RVAL2CSTR (criteria));
return rbz_query_make (query);
}
void
Init_zoom_query (VALUE mZoom)
{
VALUE c;
c = rb_define_class_under (mZoom, "Query", rb_cObject);
rb_define_singleton_method (c, "new_prefix", rbz_query_new_prefix, 1);
rb_define_singleton_method (c, "new_cql", rbz_query_new_cql, 1);
rb_define_singleton_method (c, "new_sort_by", rbz_query_new_sort_by, 1);
cZoomQuery = c;
}
|