Object
A BooleanClause holes a single query within a BooleanQuery specifying wither the query :must match, :should match or :must_not match. BooleanClauses can be used to pass a clause from one BooleanQuery to another although it is generally easier just to add a query directly to a BooleanQuery using the BooleanQuery#add_query method.
clause1 = BooleanClause.new(query1, :should) clause2 = BooleanClause.new(query2, :should) query = BooleanQuery.new query << clause1 << clause2
Create a new BooleanClause object, wrapping the query query. occur must be one of :must, :should or :must_not.
static VALUE
frb_bc_init(int argc, VALUE *argv, VALUE self)
{
BooleanClause *bc;
VALUE rquery, roccur;
unsigned int occur = BC_SHOULD;
Query *sub_q;
if (rb_scan_args(argc, argv, "11", &rquery, &roccur) == 2) {
occur = frb_get_occur(roccur);
}
Data_Get_Struct(rquery, Query, sub_q);
REF(sub_q);
bc = bc_new(sub_q, occur);
Frt_Wrap_Struct(self, &frb_bc_mark, &frb_bc_free, bc);
object_add(bc, self);
return self;
}
Set the occur value for this BooleanClause. occur must be one of :must, :should or :must_not.
static VALUE
frb_bc_set_occur(VALUE self, VALUE roccur)
{
GET_BC();
BCType occur = frb_get_occur(roccur);
bc_set_occur(bc, occur);
return roccur;
}
Return true if this clause is prohibited. ie, this will be true if occur was equal to :must_not.
static VALUE
frb_bc_is_prohibited(VALUE self)
{
GET_BC();
return bc->is_prohibited ? Qtrue : Qfalse;
}
Return the query object wrapped by this BooleanClause.
static VALUE
frb_bc_get_query(VALUE self)
{
GET_BC();
return object_get(bc->query);
}
Set the query wrapped by this BooleanClause.
static VALUE
frb_bc_set_query(VALUE self, VALUE rquery)
{
GET_BC();
Data_Get_Struct(rquery, Query, bc->query);
return rquery;
}
Return true if this clause is required. ie, this will be true if occur was equal to :must.
static VALUE
frb_bc_is_required(VALUE self)
{
GET_BC();
return bc->is_required ? Qtrue : Qfalse;
}
Return a string representation of this clause. This will not be used by BooleanQuery#to_s. It is only used by BooleanClause#to_s and will specify whether the clause is :must, :should or :must_not.
static VALUE
frb_bc_to_s(VALUE self)
{
VALUE rstr;
char *qstr, *ostr = "", *str;
int len;
GET_BC();
qstr = bc->query->to_s(bc->query, NULL);
switch (bc->occur) {
case BC_SHOULD:
ostr = "Should";
break;
case BC_MUST:
ostr = "Must";
break;
case BC_MUST_NOT:
ostr = "Must Not";
break;
}
len = strlen(ostr) + strlen(qstr) + 2;
str = ALLOC_N(char, len);
sprintf(str, "%s:%s", ostr, qstr);
rstr = rb_str_new(str, len);
free(qstr);
free(str);
return rstr;
}
Generated with the Darkfish Rdoc Generator 2.