wildcard-expand mime types against the index not the config

This commit is contained in:
Jean-Francois Dockes 2013-03-04 14:44:04 +01:00
parent dcf937d650
commit a57b02bd09
2 changed files with 20 additions and 20 deletions

View File

@ -68,20 +68,17 @@ void SearchData::commoninit()
m_maxcl = 100000; m_maxcl = 100000;
} }
// Expand categories and mime type wild card exps // Expand categories and mime type wild card exps Categories are
// Actually, using getAllMimeTypes() here is a bit problematic because // expanded against the configuration, mimetypes against the index
// there maybe other types in the index, not indexed by content, but // (for wildcards).
// which could be searched by file name. It would probably be bool SearchData::expandFileTypes(Db &db, vector<string>& tps)
// preferable to do a termMatch() on field "mtype", which would
// retrieve all values from the index.
bool SearchData::expandFileTypes(const RclConfig *cfg, vector<string>& tps)
{ {
const RclConfig *cfg = db.getConf();
if (!cfg) { if (!cfg) {
LOGFATAL(("Db::expandFileTypes: null configuration!!\n")); LOGFATAL(("Db::expandFileTypes: null configuration!!\n"));
return false; return false;
} }
vector<string> exptps; vector<string> exptps;
vector<string> alltypes = cfg->getAllMimeTypes();
for (vector<string>::iterator it = tps.begin(); it != tps.end(); it++) { for (vector<string>::iterator it = tps.begin(); it != tps.end(); it++) {
if (cfg->isMimeCategory(*it)) { if (cfg->isMimeCategory(*it)) {
@ -89,19 +86,22 @@ bool SearchData::expandFileTypes(const RclConfig *cfg, vector<string>& tps)
cfg->getMimeCatTypes(*it, tps); cfg->getMimeCatTypes(*it, tps);
exptps.insert(exptps.end(), tps.begin(), tps.end()); exptps.insert(exptps.end(), tps.begin(), tps.end());
} else { } else {
bool matched = false; TermMatchResult res;
for (vector<string>::const_iterator ait = alltypes.begin(); string mt = stringtolower((const string&)*it);
ait != alltypes.end(); ait++) { db.termMatch(Db::ET_WILD, "", mt, res, -1, "mtype");
if (fnmatch(it->c_str(), ait->c_str(), FNM_CASEFOLD) if (res.entries.empty()) {
!= FNM_NOMATCH) { exptps.push_back(it->c_str());
exptps.push_back(*ait); } else {
matched = true; for (vector<TermMatchEntry>::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; tps = exptps;
return true; return true;
} }
@ -259,7 +259,7 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d)
// Add the file type filtering clause if any // Add the file type filtering clause if any
if (!m_filetypes.empty()) { if (!m_filetypes.empty()) {
expandFileTypes(db.getConf(), m_filetypes); expandFileTypes(db, m_filetypes);
Xapian::Query tq; Xapian::Query tq;
for (vector<string>::iterator it = m_filetypes.begin(); for (vector<string>::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 // Add the neg file type filtering clause if any
if (!m_nfiletypes.empty()) { if (!m_nfiletypes.empty()) {
expandFileTypes(db.getConf(), m_nfiletypes); expandFileTypes(db, m_nfiletypes);
Xapian::Query tq; Xapian::Query tq;
for (vector<string>::iterator it = m_nfiletypes.begin(); for (vector<string>::iterator it = m_nfiletypes.begin();

View File

@ -202,7 +202,7 @@ private:
// value during "find-as-you-type" operations from the GUI // value during "find-as-you-type" operations from the GUI
int m_softmaxexpand; int m_softmaxexpand;
bool expandFileTypes(const RclConfig *cfg, std::vector<std::string>& exptps); bool expandFileTypes(Rcl::Db &db, std::vector<std::string>& exptps);
bool clausesToQuery(Rcl::Db &db, SClType tp, bool clausesToQuery(Rcl::Db &db, SClType tp,
std::vector<SearchDataClause*>& query, std::vector<SearchDataClause*>& query,
string& reason, void *d); string& reason, void *d);