actually implement maxTermExpand and maxXapianClauses and improve error message

This commit is contained in:
Jean-Francois Dockes 2013-02-26 14:34:25 +01:00
parent c472613f87
commit 87120798c2
2 changed files with 23 additions and 9 deletions

View File

@ -106,6 +106,13 @@ bool SearchData::expandFileTypes(const RclConfig *cfg, vector<string>& tps)
return true; return true;
} }
static const char *maxXapClauseMsg =
"Maximum Xapian query size exceeded. Increase maxXapianClauses "
"in the configuration. ";
static const char *maxXapClauseCaseDiacMsg =
"Or try to use case (C) or diacritics (D) sensitivity qualifiers."
;
bool SearchData::clausesToQuery(Rcl::Db &db, SClType tp, bool SearchData::clausesToQuery(Rcl::Db &db, SClType tp,
vector<SearchDataClause*>& query, vector<SearchDataClause*>& query,
string& reason, void *d) string& reason, void *d)
@ -145,13 +152,16 @@ bool SearchData::clausesToQuery(Rcl::Db &db, SClType tp,
xq = Xapian::Query(op, xq, nq); xq = Xapian::Query(op, xq, nq);
} }
if (int(xq.get_length()) >= getMaxCl()) { if (int(xq.get_length()) >= getMaxCl()) {
LOGERR(("Maximum Xapian query size exceeded." LOGERR(("%s\n", maxXapClauseMsg));
" Maybe increase maxXapianClauses.")); m_reason += maxXapClauseMsg;
m_reason += "Maximum Xapian query size exceeded." if (!o_index_stripchars)
" Maybe increase maxXapianClauses."; m_reason += maxXapClauseCaseDiacMsg;
return false; return false;
} }
} }
LOGDEB0(("SearchData::clausesToQuery: got %d clauses\n", xq.get_length()));
if (xq.empty()) if (xq.empty())
xq = Xapian::Query::MatchAll; xq = Xapian::Query::MatchAll;
@ -164,6 +174,9 @@ bool SearchData::toNativeQuery(Rcl::Db &db, void *d)
LOGDEB(("SearchData::toNativeQuery: stemlang [%s]\n", m_stemlang.c_str())); LOGDEB(("SearchData::toNativeQuery: stemlang [%s]\n", m_stemlang.c_str()));
m_reason.erase(); m_reason.erase();
db.getConf()->getConfParam("maxTermExpand", &m_maxexp);
db.getConf()->getConfParam("maxXapianClauses", &m_maxcl);
// Walk the clause list translating each in turn and building the // Walk the clause list translating each in turn and building the
// Xapian query tree // Xapian query tree
Xapian::Query xq; Xapian::Query xq;
@ -624,7 +637,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db,
// Term match entries to vector of terms // Term match entries to vector of terms
if (int(res.entries.size()) >= maxexpand && !maxexpissoft) { if (int(res.entries.size()) >= maxexpand && !maxexpissoft) {
ermsg = "Maximum term expansion size exceeded." ermsg = "Maximum term expansion size exceeded."
" Maybe increase maxTermExpand."; " Maybe use case/diacritics sensitivity or increase maxTermExpand.";
return false; return false;
} }
for (vector<TermMatchEntry>::const_iterator it = res.entries.begin(); for (vector<TermMatchEntry>::const_iterator it = res.entries.begin();
@ -956,8 +969,9 @@ bool SearchDataClauseSimple::processUserString(Rcl::Db &db, const string &iq,
useNear, slack); useNear, slack);
} }
if (m_curcl >= getMaxCl()) { if (m_curcl >= getMaxCl()) {
ermsg = "Maximum Xapian query size exceeded." ermsg = maxXapClauseMsg;
" Maybe increase maxXapianClauses."; if (!o_index_stripchars)
ermsg += maxXapClauseCaseDiacMsg;
break; break;
} }
} }

View File

@ -114,8 +114,8 @@ maxTermExpand = 10000
# Maximum number of clauses we add to a single Xapian query. In some cases, # Maximum number of clauses we add to a single Xapian query. In some cases,
# the result of term expansion can be multiplicative, and we want to avoid # the result of term expansion can be multiplicative, and we want to avoid
# eating all the memory. Default 100 000 # eating all the memory. Default 50000
maxXapianClauses = 100000 maxXapianClauses = 50000
# Where to store the database (directory). This may be an absolute path, # Where to store the database (directory). This may be an absolute path,
# else it is taken as relative to the configuration directory (-c argument # else it is taken as relative to the configuration directory (-c argument