From a57b02bd095c4c2ad40d48bb978982ab386f3b43 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 4 Mar 2013 14:44:04 +0100 Subject: [PATCH] wildcard-expand mime types against the index not the config --- src/rcldb/searchdata.cpp | 38 +++++++++++++++++++------------------- src/rcldb/searchdata.h | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp index 7ab46f30..65bbf835 100644 --- a/src/rcldb/searchdata.cpp +++ b/src/rcldb/searchdata.cpp @@ -68,20 +68,17 @@ void SearchData::commoninit() m_maxcl = 100000; } -// Expand categories and mime type wild card exps -// Actually, using getAllMimeTypes() here is a bit problematic because -// there maybe other types in the index, not indexed by content, but -// which could be searched by file name. It would probably be -// preferable to do a termMatch() on field "mtype", which would -// retrieve all values from the index. -bool SearchData::expandFileTypes(const RclConfig *cfg, vector& tps) +// Expand categories and mime type wild card exps Categories are +// expanded against the configuration, mimetypes against the index +// (for wildcards). +bool SearchData::expandFileTypes(Db &db, vector& tps) { + const RclConfig *cfg = db.getConf(); if (!cfg) { LOGFATAL(("Db::expandFileTypes: null configuration!!\n")); return false; } vector exptps; - vector alltypes = cfg->getAllMimeTypes(); for (vector::iterator it = tps.begin(); it != tps.end(); it++) { if (cfg->isMimeCategory(*it)) { @@ -89,19 +86,22 @@ bool SearchData::expandFileTypes(const RclConfig *cfg, vector& tps) cfg->getMimeCatTypes(*it, tps); exptps.insert(exptps.end(), tps.begin(), tps.end()); } else { - bool matched = false; - for (vector::const_iterator ait = alltypes.begin(); - ait != alltypes.end(); ait++) { - if (fnmatch(it->c_str(), ait->c_str(), FNM_CASEFOLD) - != FNM_NOMATCH) { - exptps.push_back(*ait); - matched = true; + TermMatchResult res; + string mt = stringtolower((const string&)*it); + db.termMatch(Db::ET_WILD, "", mt, res, -1, "mtype"); + if (res.entries.empty()) { + exptps.push_back(it->c_str()); + } else { + for (vector::const_iterator rit = + res.entries.begin(); rit != res.entries.end(); rit++) { + exptps.push_back(strip_prefix(rit->term)); } } - if (!matched) - exptps.push_back(it->c_str()); } } + sort(exptps.begin(), exptps.end()); + exptps.erase(unique(exptps.begin(), exptps.end()), exptps.end()); + tps = exptps; return true; } @@ -259,7 +259,7 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d) // Add the file type filtering clause if any if (!m_filetypes.empty()) { - expandFileTypes(db.getConf(), m_filetypes); + expandFileTypes(db, m_filetypes); Xapian::Query tq; for (vector::iterator it = m_filetypes.begin(); @@ -274,7 +274,7 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d) // Add the neg file type filtering clause if any if (!m_nfiletypes.empty()) { - expandFileTypes(db.getConf(), m_nfiletypes); + expandFileTypes(db, m_nfiletypes); Xapian::Query tq; for (vector::iterator it = m_nfiletypes.begin(); diff --git a/src/rcldb/searchdata.h b/src/rcldb/searchdata.h index 6747cc47..24fd38a3 100644 --- a/src/rcldb/searchdata.h +++ b/src/rcldb/searchdata.h @@ -202,7 +202,7 @@ private: // value during "find-as-you-type" operations from the GUI int m_softmaxexpand; - bool expandFileTypes(const RclConfig *cfg, std::vector& exptps); + bool expandFileTypes(Rcl::Db &db, std::vector& exptps); bool clausesToQuery(Rcl::Db &db, SClType tp, std::vector& query, string& reason, void *d);