]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts-lucene, fts-solr: Try to optimize searching for existence of header name.
authorTimo Sirainen <tss@iki.fi>
Tue, 30 Aug 2011 02:36:24 +0000 (05:36 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 30 Aug 2011 02:36:24 +0000 (05:36 +0300)
src/plugins/fts-lucene/lucene-wrapper.cc
src/plugins/fts-solr/fts-backend-solr.c

index e0b1895e87faf4add6353344269eaee8300e252e..8f5bd4ba425d8fe7894295c0f0c068845f6b87d1 100644 (file)
@@ -1007,16 +1007,22 @@ static Query* getFieldQuery(Analyzer *analyzer, const TCHAR* _field, const TCHAR
 }
 
 static Query *
-lucene_get_query(struct lucene_index *index,
-                const TCHAR *key, const struct mail_search_arg *arg)
+lucene_get_query_str(struct lucene_index *index,
+                    const TCHAR *key, const char *str, bool fuzzy)
 {
-       const TCHAR *wvalue = t_lucene_utf8_to_tchar(arg->value.str);
-       Analyzer *analyzer = guess_analyzer(index, arg->value.str,
-                                           strlen(arg->value.str));
+       const TCHAR *wvalue = t_lucene_utf8_to_tchar(str);
+       Analyzer *analyzer = guess_analyzer(index, str, strlen(str));
        if (analyzer == NULL)
                analyzer = index->default_analyzer;
 
-       return getFieldQuery(analyzer, key, wvalue, arg->fuzzy);
+       return getFieldQuery(analyzer, key, wvalue, fuzzy);
+}
+
+static Query *
+lucene_get_query(struct lucene_index *index,
+                const TCHAR *key, const struct mail_search_arg *arg)
+{
+       return lucene_get_query_str(index, key, arg->value.str, arg->fuzzy);
 }
 
 static bool
@@ -1102,7 +1108,13 @@ lucene_add_maybe_query(struct lucene_index *index, BooleanQuery &query,
 
                /* we can check if the search key exists in some header and
                   filter out the messages that have no chance of matching */
-               q = lucene_get_query(index, _T("hdr"), arg);
+               if (*arg->value.str != '\0')
+                       q = lucene_get_query(index, _T("hdr"), arg);
+               else {
+                       /* checking potential existence of the header name */
+                       q = lucene_get_query_str(index, _T("hdr"),
+                                                arg->hdr_field_name, FALSE);
+               }
                break;
        default:
                return false;
index 5efbab13f9c3429d9cde906b2f8a0b5468f9f9ae..bda41f5fdf2d34a3271833df42f83be78f1f5498 100644 (file)
@@ -559,7 +559,12 @@ solr_add_maybe_query(string_t *str, struct mail_search_arg *arg)
                /* we can check if the search key exists in some header and
                   filter out the messages that have no chance of matching */
                str_append(str, "hdr:");
-               solr_quote_http(str, arg->value.str);
+               if (*arg->value.str != '\0')
+                       solr_quote_http(str, arg->value.str);
+               else {
+                       /* checking potential existence of the header name */
+                       solr_quote_http(str, arg->hdr_field_name);
+               }
                break;
        default:
                return FALSE;