Class | Ferret::Search::Spans::SpanOrQuery |
In: |
ext/r_search.c
|
Parent: | Ferret::Search::Query |
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.
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____|
SpanOrQuery only works with other SpanQueries.
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.
Add a clause to the SpanOrQuery. Note that clauses must be SpanQueries, not other types of query.
Add a clause to the SpanOrQuery. Note that clauses must be SpanQueries, not other types of query.