Xapian::DateRangeProcessor Class Reference

Handle a date range. More...

`#include <queryparser.h>`

Inheritance diagram for Xapian::DateRangeProcessor:
[legend]

## Public Member Functions

| DateRangeProcessor (Xapian::valueno slot_, unsigned flags_=0, int epoch_year_=1970)
| Constructor.
| DateRangeProcessor (Xapian::valueno slot_, std::string_view str_, unsigned flags_=0, int epoch_year_=1970)
| Constructor.
Xapian::Query | operator() (const std::string &begin, const std::string &end)
| Check for a valid date range.
Public Member Functions inherited from Xapian::RangeProcessor
| RangeProcessor ()
| Default constructor.
| RangeProcessor (Xapian::valueno slot_, std::string_view str_={}, unsigned flags_=0)
| Constructor.
virtual | ~RangeProcessor ()
| Destructor.
Xapian::Query | check_range (const std::string &b, const std::string &e)
| Check prefix/suffix on range.
RangeProcessor * | release ()
| Start reference counting this object.
const RangeProcessor * | release () const
| Start reference counting this object.

## Additional Inherited Members

Protected Attributes inherited from Xapian::RangeProcessor
Xapian::valueno | slot
| The value slot to process.
std::string | str
| The prefix (or suffix with RP_SUFFIX) string to look for.
unsigned | flags
| Flags.

## Detailed Description

Handle a date range.

Begin and end must be dates in a recognised format.

## Constructor & Destructor Documentation

## DateRangeProcessor() [1/2]

Xapian::DateRangeProcessor::DateRangeProcessor | ( | Xapian::valueno | slot_,
|  | unsigned | flags_ = 0,
|  | int | epoch_year_ = 1970 )

inline explicit

Constructor.

Parameters

  slot_ | The value number to return from operator().

  flags_

  Zero or more of the following flags, combined with bitwise-or:
  - Xapian::RP_DATE_PREFER_MDY - interpret ambiguous dates as month/day/year rather than day/month/year.

  epoch_year_ | Year to use as the epoch for dates with 2 digit years (default: 1970, so 1/1/69 is 2069 while 1/1/70 is 1970).

## DateRangeProcessor() [2/2]

Xapian::DateRangeProcessor::DateRangeProcessor | ( | Xapian::valueno | slot_,
|  | std::string_view | str_,
|  | unsigned | flags_ = 0,
|  | int | epoch_year_ = 1970 )

inline

Constructor.

Parameters

  slot_ | The value slot number to query.
  str_ | A prefix or suffix string to look for to recognise values as belonging to this date range (flags_ determines whether this is a prefix or suffix).

  flags_

  Zero or more of the following flags, combined with bitwise-or:
  - Xapian::RP_SUFFIX - require str_ as a suffix instead of a prefix.
  - Xapian::RP_REPEATED - optionally allow str_ on both ends of the range - e.g. $1..$10 or 5m..50m. By default a prefix is only checked for on the start (e.g. date:1/1/1980..31/12/1989), and a suffix only on the end (e.g. 2..12kg).
  - Xapian::RP_DATE_PREFER_MDY - interpret ambiguous dates as month/day/year rather than day/month/year.

  epoch_year_ | Year to use as the epoch for dates with 2 digit years (default: 1970, so 1/1/69 is 2069 while 1/1/70 is 1970).

The string supplied in str_ is used by operator() to decide whether the pair of strings supplied to it constitute a valid range. If prefix_ is true, the first value in a range must begin with str_ (and the second value may optionally begin with str_); if prefix_ is false, the second value in a range must end with str_ (and the first value may optionally end with str_).

If str_ is empty then no prefix or suffix is checked for (and Xapian::RP_SUFFIX and Xapian::RP_REPEATED are irrelevant) - anything which looks like a date range will be processed.

## Member Function Documentation

## operator()()

Xapian::Query Xapian::DateRangeProcessor::operator() | ( | const std::string & | begin,
|  | const std::string & | end )

virtual

Check for a valid date range.

Parameters

  begin | The start of the range as specified in the query string by the user.
  end | The end of the range as specified in the query string by the user.

If a prefix or suffix was specified at construction time, that must be present on begin and/or end (taking Xapian::RP_SUFFIX and Xapian::RP_REPEATED into account).

Then if the range looks like a date range, the dates are converted to the format YYYYMMDD and combined into a value range query.

Most numeric date formats are recognised:

- YYYYMMDD - e.g. 20251225..20260214
- YYYY-MM-DD (ISO) - e.g. 2025-12-25..2026-02-14
- month/day/year (US) - e.g. 12/25/2025..2/14/2026
- day/month/year (much of the world) - e.g. 25/12/2025..14/2/2026

The delimiter can be -, / or . for any of the delimited formats, but must be the same within a single date.

Some dates are unfortunately ambiguous and could be in either of the last two formats - for example 2/3/2025 could be March 2nd or February 3rd. The range start is assumed to be before the range end which can resolve some ambiguous cases, but otherwise day/month/year is assumed unless flag Xapian::RP_DATE_PREFER_MDY was specified.

Two digit years can be used with the last two formats - constructor parameter epoch_year_ determines how these are interpreted.

Reimplemented from Xapian::RangeProcessor.

The documentation for this class was generated from the following file:

- xapian/queryparser.h