]> git.notmuchmail.org Git - notmuch/blob - lib/regexp-fields.h
gmime-cleanup: pass NULL arguments explicitly where GMime 3.0 expects it
[notmuch] / lib / regexp-fields.h
1 /* regex-fields.h - xapian glue for semi-bruteforce regexp search
2  *
3  * This file is part of notmuch.
4  *
5  * Copyright © 2015 Austin Clements
6  * Copyright © 2016 David Bremner
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see https://www.gnu.org/licenses/ .
20  *
21  * Author: Austin Clements <aclements@csail.mit.edu>
22  *                David Bremner <david@tethera.net>
23  */
24
25 #ifndef NOTMUCH_REGEXP_FIELDS_H
26 #define NOTMUCH_REGEXP_FIELDS_H
27 #if HAVE_XAPIAN_FIELD_PROCESSOR
28 #include <sys/types.h>
29 #include <regex.h>
30 #include "database-private.h"
31 #include "notmuch-private.h"
32
33 /* A posting source that returns documents where a value matches a
34  * regexp.
35  */
36 class RegexpPostingSource : public Xapian::PostingSource
37 {
38  protected:
39     const Xapian::valueno slot_;
40     regex_t regexp_;
41     Xapian::Database db_;
42     bool started_;
43     Xapian::ValueIterator it_, end_;
44
45 /* No copying */
46     RegexpPostingSource (const RegexpPostingSource &);
47     RegexpPostingSource &operator= (const RegexpPostingSource &);
48
49  public:
50     RegexpPostingSource (Xapian::valueno slot, const std::string &regexp);
51     ~RegexpPostingSource ();
52     void init (const Xapian::Database &db);
53     Xapian::doccount get_termfreq_min () const;
54     Xapian::doccount get_termfreq_est () const;
55     Xapian::doccount get_termfreq_max () const;
56     Xapian::docid get_docid () const;
57     bool at_end () const;
58     void next (unused (double min_wt));
59     void skip_to (Xapian::docid did, unused (double min_wt));
60     bool check (Xapian::docid did, unused (double min_wt));
61 };
62
63
64 class RegexpFieldProcessor : public Xapian::FieldProcessor {
65  protected:
66     Xapian::valueno slot;
67     std::string term_prefix;
68     notmuch_field_flag_t options;
69     Xapian::QueryParser &parser;
70     notmuch_database_t *notmuch;
71
72  public:
73     RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options,
74                           Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
75
76     ~RegexpFieldProcessor () { };
77
78     Xapian::Query operator()(const std::string & str);
79 };
80 #endif
81 #endif /* NOTMUCH_REGEXP_FIELDS_H */