make sure that expansions of * done to retrieve all years or all mime types from index are done against the appropriate field section of the main index, not the whole synexpand one

This commit is contained in:
Jean-Francois Dockes 2013-04-13 16:34:09 +02:00
parent b8778f655e
commit ec99c6bf51
7 changed files with 37 additions and 22 deletions

View file

@ -293,6 +293,9 @@ void AdvSearch::fillFileTypes()
QStringList ql; QStringList ql;
if (m_ignByCats == false) { if (m_ignByCats == false) {
vector<string> types = theconfig->getAllMimeTypes(); vector<string> types = theconfig->getAllMimeTypes();
rcldb->getAllDbMimeTypes(types);
sort(types.begin(), types.end());
types.erase(unique(types.begin(), types.end()), types.end());
for (vector<string>::iterator it = types.begin(); for (vector<string>::iterator it = types.begin();
it != types.end(); it++) { it != types.end(); it++) {
QString qs = QString::fromUtf8(it->c_str()); QString qs = QString::fromUtf8(it->c_str());

View file

@ -1108,24 +1108,17 @@ void RclMain::showActiveTypes()
return; return;
} }
// Get list of all mime types in index. For this, we use a // All mime types in index.
// wildcard field search on mtype vector<string> vdbtypes;
Rcl::TermMatchResult matches; if (!rcldb->getAllDbMimeTypes(vdbtypes)) {
if (!rcldb->termMatch(Rcl::Db::ET_WILD, "", "*", matches, -1, "mtype")) {
QMessageBox::warning(0, tr("Error"), QMessageBox::warning(0, tr("Error"),
tr("Index query error"), tr("Index query error"),
QMessageBox::Ok, QMessageBox::Ok,
QMessageBox::NoButton); QMessageBox::NoButton);
return; return;
} }
// Build the set of mtypes, stripping the prefix
set<string> mtypesfromdb; set<string> mtypesfromdb;
for (vector<Rcl::TermMatchEntry>::const_iterator it = mtypesfromdb.insert(vdbtypes.begin(), vdbtypes.end());
matches.entries.begin();
it != matches.entries.end(); it++) {
mtypesfromdb.insert(it->term.substr(matches.prefix.size()));
}
// All types listed in mimeconf: // All types listed in mimeconf:
vector<string> mtypesfromconfig = theconfig->getAllMimeTypes(); vector<string> mtypesfromconfig = theconfig->getAllMimeTypes();

View file

@ -352,16 +352,13 @@ int SSearch::partialWord(string& s)
} }
// Create completion list for term by adding a joker at the end and calling // Create completion list for term by adding a joker at the end and calling
// rcldb->termMatch(). This does not work well if the db is not // rcldb->termMatch().
// rcldb->stripped, the completion is casediac-sensitive in this case.
//
// What we should do instead is complete the term from the key list in
// the casediac expansion db (stripped->unstripped synonyms table),
// then expand each of the completed keys.
int SSearch::completionList(string s, QStringList& lst, int max) int SSearch::completionList(string s, QStringList& lst, int max)
{ {
if (!rcldb) if (!rcldb)
return -1; return -1;
if (s.empty())
return 0;
// Query database for completions // Query database for completions
s += "*"; s += "*";
Rcl::TermMatchResult tmres; Rcl::TermMatchResult tmres;

View file

@ -22,7 +22,7 @@
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -284,6 +284,9 @@
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
</property> </property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value"> <property name="value">
<number>8</number> <number>8</number>
</property> </property>

View file

@ -329,6 +329,10 @@ class Db {
bool dbStats(DbStats& stats); bool dbStats(DbStats& stats);
/** Return min and max years for doc mod times in db */ /** Return min and max years for doc mod times in db */
bool maxYearSpan(int *minyear, int *maxyear); bool maxYearSpan(int *minyear, int *maxyear);
/** Return all mime types in index. This can be different from the
ones defined in the config because of 'file' command
usage. Inserts the types at the end of the parameter */
bool getAllDbMimeTypes(std::vector<std::string>&);
/** Wildcard expansion specific to file names. Internal/sdata use only */ /** Wildcard expansion specific to file names. Internal/sdata use only */
bool filenameWildExp(const string& exp, vector<string>& names, int max); bool filenameWildExp(const string& exp, vector<string>& names, int max);

View file

@ -59,8 +59,8 @@ bool Db::filenameWildExp(const string& fnexp, vector<string>& names, int max)
} }
TermMatchResult result; TermMatchResult result;
if (!termMatch(ET_WILD, string(), pattern, result, max, if (!idxTermMatch(ET_WILD, string(), pattern, result, max,
unsplitFilenameFieldName)) unsplitFilenameFieldName))
return false; return false;
for (vector<TermMatchEntry>::const_iterator it = result.entries.begin(); for (vector<TermMatchEntry>::const_iterator it = result.entries.begin();
it != result.entries.end(); it++) it != result.entries.end(); it++)
@ -81,7 +81,7 @@ bool Db::maxYearSpan(int *minyear, int *maxyear)
*minyear = 1000000; *minyear = 1000000;
*maxyear = -1000000; *maxyear = -1000000;
TermMatchResult result; TermMatchResult result;
if (!termMatch(ET_WILD, string(), "*", result, -1, "xapyear")) { if (!idxTermMatch(ET_WILD, string(), "*", result, -1, "xapyear")) {
LOGINFO(("Rcl::Db:maxYearSpan: termMatch failed\n")); LOGINFO(("Rcl::Db:maxYearSpan: termMatch failed\n"));
return false; return false;
} }
@ -98,6 +98,19 @@ bool Db::maxYearSpan(int *minyear, int *maxyear)
return true; return true;
} }
bool Db::getAllDbMimeTypes(std::vector<std::string>& exp)
{
Rcl::TermMatchResult res;
if (!idxTermMatch(Rcl::Db::ET_WILD, "", "*", res, -1, "mtype")) {
return false;
}
for (vector<Rcl::TermMatchEntry>::const_iterator rit = res.entries.begin();
rit != res.entries.end(); rit++) {
exp.push_back(Rcl::strip_prefix(rit->term));
}
return true;
}
class TermMatchCmpByWcf { class TermMatchCmpByWcf {
public: public:
int operator()(const TermMatchEntry& l, const TermMatchEntry& r) { int operator()(const TermMatchEntry& l, const TermMatchEntry& r) {

View file

@ -87,7 +87,9 @@ bool SearchData::expandFileTypes(Db &db, vector<string>& tps)
} else { } else {
TermMatchResult res; TermMatchResult res;
string mt = stringtolower((const string&)*it); string mt = stringtolower((const string&)*it);
db.termMatch(Db::ET_WILD, "", mt, res, -1, "mtype"); // We set casesens|diacsens to get an equivalent of ixTermMatch()
db.termMatch(Db::ET_WILD|Db::ET_CASESENS|Db::ET_DIACSENS, string(),
mt, res, -1, "mtype");
if (res.entries.empty()) { if (res.entries.empty()) {
exptps.push_back(it->c_str()); exptps.push_back(it->c_str());
} else { } else {