### Home Classes Methods

### In Files

- ext/r_search.c

### Parent

Object

### Methods

- ::new
- #occur=
- #prohibited?
- #query
- #query=
- #required?
- #to_s

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Search::BooleanQuery::BooleanClause

## Summary

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.

## Example

    clause1 = BooleanClause.new(query1, :should)
    clause2 = BooleanClause.new(query2, :should)

    query = BooleanQuery.new
    query << clause1 << clause2

### Public Class Methods

new(query, occur = :should) → BooleanClause click to toggle source

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;
    }

### Public Instance Methods

occur = occur → occur click to toggle source

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;
    }

prohibited? → bool click to toggle source

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;
    }

query → query click to toggle source

Return the query object wrapped by this BooleanClause.

    static VALUE
    frb_bc_get_query(VALUE self)
    {
        GET_BC();
        return object_get(bc->query);
    }

query = query → query click to toggle source

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;
    }

required? → bool click to toggle source

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;
    }

to_s → string click to toggle source

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;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.