1 /* regex-fields.h - xapian glue for semi-bruteforce regexp search
3 * This file is part of notmuch.
5 * Copyright © 2015 Austin Clements
6 * Copyright © 2016 David Bremner
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.
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.
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/ .
21 * Author: Austin Clements <aclements@csail.mit.edu>
22 * David Bremner <david@tethera.net>
25 #ifndef NOTMUCH_REGEXP_FIELDS_H
26 #define NOTMUCH_REGEXP_FIELDS_H
27 #if HAVE_XAPIAN_FIELD_PROCESSOR
28 #include <sys/types.h>
30 #include "database-private.h"
31 #include "notmuch-private.h"
33 /* A posting source that returns documents where a value matches a
36 class RegexpPostingSource : public Xapian::PostingSource
39 const Xapian::valueno slot_;
43 Xapian::ValueIterator it_, end_;
46 RegexpPostingSource (const RegexpPostingSource &);
47 RegexpPostingSource &operator= (const RegexpPostingSource &);
50 RegexpPostingSource (Xapian::valueno slot, const std::string ®exp);
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;
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));
64 class RegexpFieldProcessor : public Xapian::FieldProcessor {
67 std::string term_prefix;
68 notmuch_field_flag_t options;
69 Xapian::QueryParser &parser;
70 notmuch_database_t *notmuch;
73 RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options,
74 Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
76 ~RegexpFieldProcessor () { };
78 Xapian::Query operator()(const std::string & str);
81 #endif /* NOTMUCH_REGEXP_FIELDS_H */