class Ferret::Search::Spans::SpanOrQuery

Summary

SpanOrQuery is just like a BooleanQuery with all :should clauses. However, the difference is that all sub-clauses must be SpanQueries and the resulting query can then be used within other SpanQueries like SpanNearQuery.

Example

Combined with SpanNearQuery we can create a multi-PhraseQuery like query;

quick_query = SpanOrQuery.new()
quick_query << SpanTermQuery.new(:field, "quick")
quick_query << SpanTermQuery.new(:field, "fast")
quick_query << SpanTermQuery.new(:field, "speedy")

colour_query = SpanOrQuery.new()
colour_query << SpanTermQuery.new(:field, "red")
colour_query << SpanTermQuery.new(:field, "brown")

query = SpanNearQuery.new(:slop => 2, :in_order => true)
query << quick_query
query << colour_query
query << SpanTermQuery.new(:field, "fox")
# matches => "quick red speckled sleepy fox"
                          |______2______^
# matches => "speedy brown speckled fox"
                              |__1__^
# doesn't match => "brown fast _____ fox"
#  not in order       ^_____2____|

NOTE

SpanOrQuery only works with other SpanQueries.

Public Class Methods

new(options = {}) → query click to toggle source

Create a new SpanOrQuery. This is just like a BooleanQuery with all clauses with the occur value of :should. The difference is that it can be passed to other SpanQuerys like SpanNearQuery.

static VALUE
frb_spanoq_init(int argc, VALUE *argv, VALUE self)
{
    Query *q;
    VALUE rclauses;

    q = spanoq_new();
    if (rb_scan_args(argc, argv, "01", &rclauses) > 0) {
        int i;
        Query *clause;
        Check_Type(rclauses, T_ARRAY);
        for (i = 0; i < RARRAY_LEN(rclauses); i++) {
            Data_Get_Struct(RARRAY_PTR(rclauses)[i], Query, clause);
            spanoq_add_clause(q, clause);
        }
    }
    Frt_Wrap_Struct(self, &frb_spanoq_mark, &frb_q_free, q);
    object_add(q, self);
    return self;
}

Public Instance Methods

add(span_query) → self click to toggle source
query << span_query → self

Add a clause to the SpanOrQuery. Note that clauses must be SpanQueries, not other types of query.

static VALUE
frb_spanoq_add(VALUE self, VALUE rclause)
{
    GET_Q();
    Query *clause;
    Data_Get_Struct(rclause, Query, clause);
    spanoq_add_clause(q, clause);
    return self;
}
add(span_query) → self click to toggle source
query << span_query → self

Add a clause to the SpanOrQuery. Note that clauses must be SpanQueries, not other types of query.

static VALUE
frb_spanoq_add(VALUE self, VALUE rclause)
{
    GET_Q();
    Query *clause;
    Data_Get_Struct(rclause, Query, clause);
    spanoq_add_clause(q, clause);
    return self;
}