From d2fbc7f53d92b7f1859acedc3b0894a028e078bd Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 18 Nov 2012 17:28:49 +0100 Subject: [PATCH] add "soft" term expansion limit not causing error when reached --- src/rcldb/searchdata.cpp | 24 +++++++++++++++++------- src/rcldb/searchdata.h | 5 +++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp index dcb61265..1004b8f2 100644 --- a/src/rcldb/searchdata.cpp +++ b/src/rcldb/searchdata.cpp @@ -564,6 +564,14 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db, if (term.empty()) return true; + bool maxexpissoft = false; + int maxexpand = getSoftMaxExp(); + if (maxexpand != -1) { + maxexpissoft = true; + } else { + maxexpand = getMaxExp(); + } + bool haswild = term.find_first_of(cstr_minwilds) != string::npos; // If there are no wildcards, add term to the list of user-entered terms @@ -644,7 +652,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db, // would be nothing to prevent us to expand from the casediac // synonyms first. To be done later db.termMatch(Rcl::Db::ET_WILD, getStemLang(), term, res, - getMaxExp(), m_field); + maxexpand, m_field); goto termmatchtoresult; } @@ -653,7 +661,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db, #ifdef RCL_INDEX_STRIPCHARS db.termMatch(Rcl::Db::ET_STEM, getStemLang(), term, res, - getMaxExp(), m_field); + maxexpand, m_field); #else @@ -661,7 +669,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db, // If the index is raw, we can only come here if nostemexp is unset // and we just need stem expansion. db.termMatch(Rcl::Db::ET_STEM, getStemLang(), term, res, - getMaxExp(), m_field); + maxexpand, m_field); goto termmatchtoresult; } @@ -731,13 +739,13 @@ exptotermatch: for (vector::const_iterator it = lexp.begin(); it != lexp.end(); it++) { db.termMatch(Rcl::Db::ET_WILD, getStemLang(), *it, res, - getMaxExp(), m_field); + maxexpand, m_field); } #endif // Term match entries to vector of terms termmatchtoresult: - if (int(res.entries.size()) >= getMaxExp()) { + if (int(res.entries.size()) >= maxexpand && !maxexpissoft) { ermsg = "Maximum term expansion size exceeded." " Maybe increase maxTermExpand."; return false; @@ -1140,9 +1148,11 @@ bool SearchDataClauseFilename::toNativeQuery(Rcl::Db &db, void *p) Xapian::Query *qp = (Xapian::Query *)p; *qp = Xapian::Query(); + int maxexp = getSoftMaxExp(); + if (maxexp == -1) + maxexp = getMaxExp(); + vector names; - int maxexp = 10000; - db.getConf()->getConfParam("maxTermExpand", &maxexp); db.filenameWildExp(m_text, names, maxexp); *qp = Xapian::Query(Xapian::Query::OP_OR, names.begin(), names.end()); diff --git a/src/rcldb/searchdata.h b/src/rcldb/searchdata.h index 4c04165d..940ded1f 100644 --- a/src/rcldb/searchdata.h +++ b/src/rcldb/searchdata.h @@ -168,6 +168,7 @@ public: bool getAutoCase() {return m_autocasesens;} int getMaxExp() {return m_maxexp;} int getMaxCl() {return m_maxcl;} + int getSoftMaxExp() {return m_softmaxexpand;} friend class ::AdvSearch; @@ -276,6 +277,10 @@ public: { return m_parentSearch ? m_parentSearch->getMaxCl() : 100000; } + int getSoftMaxExp() + { + return m_parentSearch ? m_parentSearch->getSoftMaxExp() : -1; + } virtual void setModifiers(Modifier mod) { m_modifiers = mod;