### Home Classes Methods

### In Files

- ext/r_search.c

### Parent

Ferret::Search::Query

### Methods

- ::new
- #<<
- #add

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.