Class: Ferret::Search::Spans::SpanOrQuery

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

Overview

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.