From: Timo Sirainen Date: Tue, 30 Aug 2011 02:36:24 +0000 (+0300) Subject: fts-lucene, fts-solr: Try to optimize searching for existence of header name. X-Git-Tag: 2.1.alpha1~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06ed0c58ea392df22ccf4868aac494831ea756e1;p=thirdparty%2Fdovecot%2Fcore.git fts-lucene, fts-solr: Try to optimize searching for existence of header name. --- diff --git a/src/plugins/fts-lucene/lucene-wrapper.cc b/src/plugins/fts-lucene/lucene-wrapper.cc index e0b1895e87..8f5bd4ba42 100644 --- a/src/plugins/fts-lucene/lucene-wrapper.cc +++ b/src/plugins/fts-lucene/lucene-wrapper.cc @@ -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; diff --git a/src/plugins/fts-solr/fts-backend-solr.c b/src/plugins/fts-solr/fts-backend-solr.c index 5efbab13f9..bda41f5fdf 100644 --- a/src/plugins/fts-solr/fts-backend-solr.c +++ b/src/plugins/fts-solr/fts-backend-solr.c @@ -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;