2017-02-27 03:34:20 +01:00
|
|
|
/* regex-fields.h - xapian glue for semi-bruteforce regexp search
|
|
|
|
*
|
|
|
|
* This file is part of notmuch.
|
|
|
|
*
|
|
|
|
* Copyright © 2015 Austin Clements
|
|
|
|
* Copyright © 2016 David Bremner
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/ .
|
|
|
|
*
|
|
|
|
* Author: Austin Clements <aclements@csail.mit.edu>
|
|
|
|
* David Bremner <david@tethera.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NOTMUCH_REGEXP_FIELDS_H
|
|
|
|
#define NOTMUCH_REGEXP_FIELDS_H
|
2020-04-21 23:07:29 +02:00
|
|
|
|
2017-02-27 03:34:20 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include "database-private.h"
|
|
|
|
#include "notmuch-private.h"
|
|
|
|
|
2021-08-24 17:17:28 +02:00
|
|
|
notmuch_status_t
|
|
|
|
_notmuch_regex_to_query (notmuch_database_t *notmuch, Xapian::valueno slot, std::string field,
|
|
|
|
std::string regexp_str,
|
|
|
|
Xapian::Query &output, std::string &msg);
|
|
|
|
|
2017-02-27 03:34:20 +01:00
|
|
|
/* A posting source that returns documents where a value matches a
|
|
|
|
* regexp.
|
|
|
|
*/
|
|
|
|
class RegexpPostingSource : public Xapian::PostingSource
|
|
|
|
{
|
2019-06-13 12:55:35 +02:00
|
|
|
protected:
|
2017-02-27 03:34:20 +01:00
|
|
|
const Xapian::valueno slot_;
|
|
|
|
regex_t regexp_;
|
|
|
|
Xapian::Database db_;
|
|
|
|
bool started_;
|
|
|
|
Xapian::ValueIterator it_, end_;
|
|
|
|
|
|
|
|
/* No copying */
|
|
|
|
RegexpPostingSource (const RegexpPostingSource &);
|
|
|
|
RegexpPostingSource &operator= (const RegexpPostingSource &);
|
|
|
|
|
2019-06-13 12:55:35 +02:00
|
|
|
public:
|
2017-02-27 03:34:20 +01:00
|
|
|
RegexpPostingSource (Xapian::valueno slot, const std::string ®exp);
|
|
|
|
~RegexpPostingSource ();
|
|
|
|
void init (const Xapian::Database &db);
|
|
|
|
Xapian::doccount get_termfreq_min () const;
|
|
|
|
Xapian::doccount get_termfreq_est () const;
|
|
|
|
Xapian::doccount get_termfreq_max () const;
|
|
|
|
Xapian::docid get_docid () const;
|
|
|
|
bool at_end () const;
|
|
|
|
void next (unused (double min_wt));
|
2017-03-07 13:52:39 +01:00
|
|
|
void skip_to (Xapian::docid did, unused (double min_wt));
|
|
|
|
bool check (Xapian::docid did, unused (double min_wt));
|
2017-02-27 03:34:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RegexpFieldProcessor : public Xapian::FieldProcessor {
|
2019-06-13 12:55:35 +02:00
|
|
|
protected:
|
2017-02-27 03:34:20 +01:00
|
|
|
Xapian::valueno slot;
|
2021-08-24 17:17:28 +02:00
|
|
|
std::string field;
|
2017-02-27 03:34:20 +01:00
|
|
|
std::string term_prefix;
|
2017-02-15 13:58:28 +01:00
|
|
|
notmuch_field_flag_t options;
|
2017-02-27 03:34:20 +01:00
|
|
|
Xapian::QueryParser &parser;
|
|
|
|
notmuch_database_t *notmuch;
|
|
|
|
|
2019-06-13 12:55:35 +02:00
|
|
|
public:
|
2017-02-15 13:58:28 +01:00
|
|
|
RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options,
|
|
|
|
Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
|
2017-02-27 03:34:20 +01:00
|
|
|
|
2019-06-13 12:55:35 +02:00
|
|
|
~RegexpFieldProcessor ()
|
|
|
|
{
|
|
|
|
};
|
2017-02-27 03:34:20 +01:00
|
|
|
|
2019-06-13 12:55:35 +02:00
|
|
|
Xapian::Query operator() (const std::string & str);
|
2017-02-27 03:34:20 +01:00
|
|
|
};
|
2020-04-21 23:07:29 +02:00
|
|
|
|
2017-02-27 03:34:20 +01:00
|
|
|
#endif /* NOTMUCH_REGEXP_FIELDS_H */
|