Class | Ferret::Search::Spans::SpanNearQuery
In: | ext/r_search.c
Parent: | Ferret::Search::Query

## 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.

### Methods

<< add new

### Public Class methods

SpanNearQuery.new(options = {}) → query

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.

### Public Instance methods

query.add(span_query) → self
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.

query.add(span_query) → self
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.

[Validate]