class Ferret::Search::RangeQuery
Summary¶ ↑
RangeQuery is used to find documents with terms in a range. RangeQuerys are usually used on untokenized fields like date fields or number fields.
Example¶ ↑
To find all documents written between January 1st 2006 and January 26th 2006 inclusive you would write the query like this;
query = RangeQuery.new(:create_date, :>= "20060101", :<= "20060126")
Range queries on numbers¶ ↑
There is now a new query called TypedRangeQuery which detects the type of the range and if the range is numerical it will find a numerical range. This allows you to do range queries with negative numbers and without having to pad the field. However, RangeQuery will perform a lot faster on large indexes so if you are working with a very large index you will need to normalize your number fields so that they are a fixed width and always positive. That way the standard String range query will do fine.
For example, if you have the numbers;
[10, -999, -90, 100, 534]
Then the can be normalized to;
# note that we have added 1000 to all numbers to make them all positive [1010, 0001, 0910, 1100, 1534]
Public Class Methods
Create a new RangeQuery on field
field. There are two ways to build a range query. With the
old-style options; :lower, :upper,
:include_lower and :include_upper or the new
style options; :<, +:<=+, :> and
+:>=+. The options' names should speak for themselves. In the
old-style options, limits are inclusive by default.
Examples¶ ↑
q = RangeQuery.new(:date, :lower => "200501", :include_lower => false) # is equivalent to q = RangeQuery.new(:date, :< => "200501") # is equivalent to q = RangeQuery.new(:date, :lower_exclusive => "200501") q = RangeQuery.new(:date, :lower => "200501", :upper => 200502) # is equivalent to q = RangeQuery.new(:date, :>= => "200501", :<= => 200502)
static VALUE
frb_rq_init(VALUE self, VALUE rfield, VALUE roptions)
{
Query *q;
char *lterm = NULL;
char *uterm = NULL;
bool include_lower = false;
bool include_upper = false;
get_range_params(roptions, <erm, &uterm, &include_lower, &include_upper);
q = rq_new(frb_field(rfield),
lterm, uterm,
include_lower, include_upper);
Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
object_add(q, self);
return self;
}