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 28 #include <sys/types.h> 29 #include <regex.h> 30 #include "database-private.h" 31 #include "notmuch-private.h" 32 33 notmuch_status_t 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); 37 38 /* A posting source that returns documents where a value matches a 39 * regexp. 40 */ 41 class RegexpPostingSource : public Xapian::PostingSource 42 { 43 protected: 44 const Xapian::valueno slot_; 45 regex_t regexp_; 46 Xapian::Database db_; 47 bool started_; 48 Xapian::ValueIterator it_, end_; 49 50 /* No copying */ 51 RegexpPostingSource (const RegexpPostingSource &); 52 RegexpPostingSource &operator= (const RegexpPostingSource &); 53 54 public: 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; 62 bool at_end () 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)); 66 }; 67 68 69 class RegexpFieldProcessor : public Xapian::FieldProcessor { 70 protected: 71 Xapian::valueno slot; 72 std::string field; 73 std::string term_prefix; 74 notmuch_field_flag_t options; 75 Xapian::QueryParser &parser; 76 notmuch_database_t *notmuch; 77 78 public: 79 RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options, 80 Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); 81 ~RegexpFieldProcessor()82 ~RegexpFieldProcessor () 83 { 84 }; 85 86 Xapian::Query operator() (const std::string & str); 87 }; 88 89 #endif /* NOTMUCH_REGEXP_FIELDS_H */ 90