]> git.cworth.org Git - notmuch/blobdiff - lib/regexp-fields.cc
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / lib / regexp-fields.cc
index c6d9d94f7686063bb59f76fbd4daf0a19ae81500..3a775261fc3a1c2f31b82f345766e231fbf45f81 100644 (file)
@@ -25,6 +25,7 @@
 #include "regexp-fields.h"
 #include "notmuch-private.h"
 #include "database-private.h"
+#include "xapian-extra.h"
 
 notmuch_status_t
 compile_regex (regex_t &regexp, const char *str, std::string &msg)
@@ -200,7 +201,7 @@ RegexpFieldProcessor::operator() (const std::string & str)
     if (str.empty ()) {
        if (options & NOTMUCH_FIELD_PROBABILISTIC) {
            return Xapian::Query (Xapian::Query::OP_AND_NOT,
-                                 Xapian::Query::MatchAll,
+                                 xapian_query_match_all (),
                                  Xapian::Query (Xapian::Query::OP_WILDCARD, term_prefix));
        } else {
            return Xapian::Query (term_prefix);
@@ -227,7 +228,8 @@ RegexpFieldProcessor::operator() (const std::string & str)
             * phrase parsing, when possible */
            std::string query_str;
 
-           if (*str.rbegin () != '*' || str.find (' ') != std::string::npos)
+           if ((str.at (0) != '(' || *str.rbegin () != ')') &&
+               (*str.rbegin () != '*' || str.find (' ') != std::string::npos))
                query_str = '"' + str + '"';
            else
                query_str = str;
@@ -235,7 +237,15 @@ RegexpFieldProcessor::operator() (const std::string & str)
            return parser.parse_query (query_str, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix);
        } else {
            /* Boolean prefix */
-           std::string term = term_prefix + str;
+           std::string query_str;
+           std::string term;
+
+           if (str.length () > 1 && str.at (str.size () - 1) == '/')
+               query_str = str.substr (0, str.size () - 1);
+           else
+               query_str = str;
+
+           term = term_prefix + query_str;
            return Xapian::Query (term);
        }
     }