allow multiple directory specs as in dir:/home/me -dir:tmp

This commit is contained in:
"Jean-Francois Dockes ext:(%22)
2012-08-19 08:27:12 +02:00
parent 0e0f41ef0a
commit 6eada80b08
5 changed files with 37 additions and 29 deletions
+13 -13
View File
@@ -320,29 +320,30 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d)
// Add the directory filtering clause. This is a phrase of terms
// prefixed with the pathelt prefix XP
if (!m_topdir.empty()) {
for (vector<DirSpec>::const_iterator dit = m_dirspecs.begin();
dit != m_dirspecs.end(); dit++) {
vector<string> vpath;
stringToTokens(m_topdir, vpath, "/");
stringToTokens(dit->dir, vpath, "/");
vector<string> pvpath;
if (m_topdir[0] == '/')
if (dit->dir[0] == '/')
pvpath.push_back(pathelt_prefix);
for (vector<string>::const_iterator it = vpath.begin();
it != vpath.end(); it++){
pvpath.push_back(pathelt_prefix + *it);
for (vector<string>::const_iterator pit = vpath.begin();
pit != vpath.end(); pit++){
pvpath.push_back(pathelt_prefix + *pit);
}
Xapian::Query::op tdop;
if (m_topdirweight == 1.0) {
tdop = m_topdirexcl ?
if (dit->weight == 1.0) {
tdop = dit->exclude ?
Xapian::Query::OP_AND_NOT : Xapian::Query::OP_FILTER;
} else {
tdop = m_topdirexcl ?
tdop = dit->exclude ?
Xapian::Query::OP_AND_NOT : Xapian::Query::OP_AND_MAYBE;
}
Xapian::Query tdq = Xapian::Query(Xapian::Query::OP_PHRASE,
pvpath.begin(), pvpath.end());
if (m_topdirweight != 1.0)
if (dit->weight != 1.0)
tdq = Xapian::Query(Xapian::Query::OP_SCALE_WEIGHT,
tdq, m_topdirweight);
tdq, dit->weight);
xq = Xapian::Query(tdop, xq, tdq);
}
@@ -480,8 +481,7 @@ void SearchData::erase() {
delete *it;
m_query.clear();
m_filetypes.clear();
m_topdir.erase();
m_topdirexcl = false;
m_dirspecs.clear();
m_description.erase();
m_reason.erase();
m_haveDates = false;
+18 -10
View File
@@ -71,8 +71,7 @@ class SearchDataClause;
class SearchData {
public:
SearchData(SClType tp)
: m_tp(tp), m_topdirexcl(false), m_topdirweight(1.0),
m_haveDates(false), m_maxSize(size_t(-1)),
: m_tp(tp), m_haveDates(false), m_maxSize(size_t(-1)),
m_minSize(size_t(-1)), m_haveWildCards(false)
{
if (m_tp != SCLT_OR && m_tp != SCLT_AND)
@@ -105,11 +104,9 @@ public:
bool maybeAddAutoPhrase(Rcl::Db &db, double threshold);
/** Set/get top subdirectory for filtering results */
void setTopdir(const std::string& t, bool excl = false, float w = 1.0)
void addDirSpec(const std::string& t, bool excl = false, float w = 1.0)
{
m_topdir = t;
m_topdirexcl = excl;
m_topdirweight = w;
m_dirspecs.push_back(DirSpec(t, excl, w));
}
void setMinSize(size_t size) {m_minSize = size;}
@@ -148,10 +145,21 @@ private:
std::vector<std::string> m_filetypes;
// Excluded set of file types if not empty
std::vector<std::string> m_nfiletypes;
// Restrict to subtree.
std::string m_topdir;
bool m_topdirexcl; // Invert meaning
float m_topdirweight; // affect weight instead of filter
// Restrict to subtree or exclude one
class DirSpec {
public:
std::string dir;
bool exclude;
// For positive spec: affect weight instead of filter
float weight;
DirSpec(const std::string&d, bool x, float w)
: dir(d), exclude(x), weight(w)
{
}
};
std::vector<DirSpec> m_dirspecs;
bool m_haveDates;
DateInterval m_dates; // Restrict to date interval
size_t m_maxSize;