Class: Ferret::Search::Spans::SpanNearQuery

Inherits:
Object
  • Object
show all
Defined in:
ext/r_search.c

Overview

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.