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
28 #include <sys/types.h>
30 #include "database-private.h"
31 #include "notmuch-private.h"
34 _notmuch_regex_to_query (notmuch_database_t *notmuch, Xapian::valueno slot, std::string field,
35 std::string regexp_str,
36 Xapian::Query &output, std::string &msg);
38 /* A posting source that returns documents where a value matches a
41 class RegexpPostingSource : public Xapian::PostingSource
44 const Xapian::valueno slot_;
48 Xapian::ValueIterator it_, end_;
51 RegexpPostingSource (const RegexpPostingSource &);
52 RegexpPostingSource &operator= (const RegexpPostingSource &);
55 RegexpPostingSource (Xapian::valueno slot, const std::string ®exp);
56 ~RegexpPostingSource ();
57 void init (const Xapian::Database &db);
58 Xapian::doccount get_termfreq_min () const;
59 Xapian::doccount get_termfreq_est () const;
60 Xapian::doccount get_termfreq_max () const;
61 Xapian::docid get_docid () const;
63 void next (unused (double min_wt));
64 void skip_to (Xapian::docid did, unused (double min_wt));
65 bool check (Xapian::docid did, unused (double min_wt));
69 class RegexpFieldProcessor : public Xapian::FieldProcessor {
73 std::string term_prefix;
74 notmuch_field_flag_t options;
75 Xapian::QueryParser &parser;
76 notmuch_database_t *notmuch;
79 RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options,
80 Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
82 ~RegexpFieldProcessor ()
86 Xapian::Query operator() (const std::string & str);
89 #endif /* NOTMUCH_REGEXP_FIELDS_H */