Class: Ferret::Search::TypedRangeFilter

Summary

TypedRangeFilter filters a set of documents which contain a lexicographical range of terms (ie "aaa", "aab", "aac", etc), unless the range boundaries happen to be numbers (positive, negative, integer, float), in which case a numerical filter is applied. See also TypedRangeQuery

Example

Find all products that cost less than or equal to $50.00.

  filter = TypedRangeFilter.new(:created_on, :<= => "50.00")

Public Class Methods


TypedRangeFilter.new(field, options = {}) → range_query

Create a new TypedRangeFilter on field field. There are two ways to build a range filter. 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

  f = TypedRangeFilter.new(:date, :lower => "0.1", :include_lower => false)
  # is equivalent to
  f = TypedRangeFilter.new(:date, :< => "0.1")
  # is equivalent to
  f = TypedRangeFilter.new(:date, :lower_exclusive => "0.1")

  # Note that you numbers can be strings or actual numbers
  f = TypedRangeFilter.new(:date, :lower => "-132.2", :upper => -1.4)
  # is equivalent to
  f = TypedRangeFilter.new(:date, :>= => "-132.2", :<= => -1.4)
/*
 *  call-seq:
 *     TypedRangeFilter.new(field, options = {}) -> range_query
 *
 *  Create a new TypedRangeFilter on field +field+. There are two ways to
 *  build a range filter. 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
 *
 *    f = TypedRangeFilter.new(:date, :lower => "0.1", :include_lower => false)
 *    # is equivalent to 
 *    f = TypedRangeFilter.new(:date, :< => "0.1")
 *    # is equivalent to 
 *    f = TypedRangeFilter.new(:date, :lower_exclusive => "0.1")
 *
 *    # Note that you numbers can be strings or actual numbers
 *    f = TypedRangeFilter.new(:date, :lower => "-132.2", :upper => -1.4)
 *    # is equivalent to 
 *    f = TypedRangeFilter.new(:date, :>= => "-132.2", :<= => -1.4)
 */
static VALUE
frt_trf_init(VALUE self, VALUE rfield, VALUE roptions)
{
    Filter *f;
    char *lterm = NULL;
    char *uterm = NULL;
    bool include_lower = false;
    bool include_upper = false;
    
    get_range_params(roptions, &lterm, &uterm, &include_lower, &include_upper);
    f = trfilt_new(frt_field(rfield), lterm, uterm,
                   include_lower, include_upper);
    Frt_Wrap_Struct(self, NULL, &frt_f_free, f);
    object_add(f, self);
    return self;
}