1 /* datematchdecider.h: date filtering using a Xapian::MatchDecider
2  *
3  * Copyright (C) 2006 Olly Betts
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19 
20 #ifndef OMEGA_INCLUDED_DATEMATCHDECIDER_H
21 #define OMEGA_INCLUDED_DATEMATCHDECIDER_H
22 
23 #include <xapian.h>
24 
25 #include <ctime>
26 #include <string>
27 
28 extern time_t set_start_or_end(const std::string & str, char * yyyymmddhhmm, char * yyyymmdd, char * raw4, bool start);
29 extern time_t set_start_or_end(time_t secs, char * yyyymmddhhmm, char * yyyymmdd, char * raw4);
30 
31 class DateMatchDecider : public Xapian::MatchDecider {
32     Xapian::valueno val;
33     char s_yyyymmdd[9], s_yyyymmddhhmm[13], s_raw4[4];
34     char e_yyyymmdd[9], e_yyyymmddhhmm[13], e_raw4[4];
35 
set_start(const std::string & str)36     time_t set_start(const std::string & str) {
37 	return set_start_or_end(str, s_yyyymmddhhmm, s_yyyymmdd, s_raw4, true);
38     }
39 
set_start(time_t t)40     time_t set_start(time_t t) {
41 	return set_start_or_end(t, s_yyyymmddhhmm, s_yyyymmdd, s_raw4);
42     }
43 
set_end(const std::string & str)44     time_t set_end(const std::string & str) {
45 	return set_start_or_end(str, e_yyyymmddhhmm, e_yyyymmdd, e_raw4, false);
46     }
47 
set_end(time_t t)48     time_t set_end(time_t t) {
49 	return set_start_or_end(t, e_yyyymmddhhmm, e_yyyymmdd, e_raw4);
50     }
51 
52   public:
53     DateMatchDecider(Xapian::valueno val_,
54 		     const std::string & date_start,
55 		     const std::string & date_end,
56 		     const std::string & date_span);
57 
58     bool operator()(const Xapian::Document &doc) const;
59 };
60 
61 #endif
62