### 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::Analysis
- Ferret::Analysis::Analyzer
- Ferret::Analysis::AsciiLetterAnalyzer
- Ferret::Analysis::AsciiLetterTokenizer
- Ferret::Analysis::AsciiLowerCaseFilter
- Ferret::Analysis::AsciiStandardAnalyzer
- Ferret::Analysis::AsciiStandardTokenizer
- Ferret::Analysis::AsciiWhiteSpaceAnalyzer
- Ferret::Analysis::AsciiWhiteSpaceTokenizer
- Ferret::Analysis::HyphenFilter
- Ferret::Analysis::LetterAnalyzer
- Ferret::Analysis::LetterTokenizer
- Ferret::Analysis::LowerCaseFilter
- Ferret::Analysis::MappingFilter
- Ferret::Analysis::PerFieldAnalyzer
- Ferret::Analysis::RegExpAnalyzer
- Ferret::Analysis::RegExpTokenizer
- Ferret::Analysis::StandardAnalyzer
- Ferret::Analysis::StandardTokenizer
- Ferret::Analysis::StemFilter
- Ferret::Analysis::StopFilter
- Ferret::Analysis::Token
- Ferret::Analysis::TokenStream
- Ferret::Analysis::WhiteSpaceAnalyzer
- Ferret::Analysis::WhiteSpaceTokenizer
- 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
- Ferret::Utils
- Ferret::Utils::BitVector
- Ferret::Utils::MultiMapper
- Ferret::Utils::PriorityQueue
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Search::Spans::SpanNearQuery

## Summary

A SpanNearQuery is like a combination between a PhraseQuery and a BooleanQuery. It matches sub-SpanQueries which are added as clauses but those clauses must occur within a `slop` edit distance of each other. You can also specify that clauses must occur `in_order`.

## Example

    query = SpanNearQuery.new(:slop => 2)
    query << SpanTermQuery.new(:field, "quick")
    query << SpanTermQuery.new(:field, "brown")
    query << SpanTermQuery.new(:field, "fox")
    # matches => "quick brown speckled sleepy fox"
                                 |______2______^
    # matches => "quick brown speckled fox"
                                  |__1__^
    # matches => "brown quick _____ fox"
                    ^_____2_____|

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

## NOTE

SpanNearQuery only works with other SpanQueries.

### Public Class Methods

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

Create a new SpanNearQuery. You can add an array of clauses with the `:clause` parameter or you can add clauses individually using the SpanNearQuery#add method.

    query = SpanNearQuery.new(:clauses => [spanq1, spanq2, spanq3])
    # is equivalent to
    query = SpanNearQuery.new()
    query << spanq1 << spanq2 << spanq3

You have two other options which you can set.

:slop | Default: 0. Works exactly like a PhraseQuery slop. It is the amount of slop allowed in the match (the term edit distance allowed in the match).
:in_order | Default: false. Specifies whether or not the matches have to occur in the order they were added to the query. When slop is set to 0, this parameter will make no difference.

    static VALUE
    frb_spannq_init(int argc, VALUE *argv, VALUE self)
    {
        Query *q;
        VALUE roptions;
        int slop = 0;
        bool in_order = false;

        if (rb_scan_args(argc, argv, "01", &roptions) > 0) {
            VALUE v;
            if (Qnil != (v = rb_hash_aref(roptions, sym_slop))) {
                slop = FIX2INT(v);
            }
            if (Qnil != (v = rb_hash_aref(roptions, sym_in_order))) {
                in_order = RTEST(v);
            }
        }
        q = spannq_new(slop, in_order);
        if (argc > 0) {
            VALUE v;
            if (Qnil != (v = rb_hash_aref(roptions, sym_clauses))) {
                int i;
                Query *clause;
                Check_Type(v, T_ARRAY);
                for (i = 0; i < RARRAY_LEN(v); i++) {
                    Data_Get_Struct(RARRAY_PTR(v)[i], Query, clause);
                    spannq_add_clause(q, clause);
                }
            }
        }

        Frt_Wrap_Struct(self, &frb_spannq_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 SpanNearQuery. Clauses are stored in the order they are added to the query which is important for matching. Note that clauses must be SpanQueries, not other types of query.

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

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

Add a clause to the SpanNearQuery. Clauses are stored in the order they are added to the query which is important for matching. Note that clauses must be SpanQueries, not other types of query.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.