implemented proper limitation and error reporting in case of truncation for term and query expansions

This commit is contained in:
Jean-Francois Dockes
2012-10-05 12:36:19 +02:00
parent bfd111ecaa
commit c9f6612c10
13 changed files with 217 additions and 105 deletions
+11 -1
View File
@@ -138,7 +138,10 @@ class DocSequence {
{
return std::list<std::string>();
}
virtual std::string getReason()
{
return m_reason;
}
/** Optional functionality. */
virtual bool canFilter() {return false;}
virtual bool canSort() {return false;}
@@ -154,6 +157,7 @@ class DocSequence {
protected:
static std::string o_sort_trans;
static std::string o_filt_trans;
std::string m_reason;
private:
std::string m_title;
};
@@ -206,6 +210,12 @@ public:
return false;
return m_seq->getEnclosing(doc, pdoc);
}
virtual std::string getReason()
{
if (m_seq.isNull())
return false;
return m_seq->getReason();
}
virtual std::string title() {return m_seq->title();}
virtual RefCntr<DocSequence> getSourceSeq() {return m_seq;}
+19 -15
View File
@@ -51,14 +51,16 @@ string DocSequenceDb::getDescription()
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh)
{
setQuery();
if (!setQuery())
return false;
if (sh) sh->erase();
return m_q->getDoc(num, doc);
}
int DocSequenceDb::getResCnt()
{
setQuery();
if (!setQuery())
return false;
if (m_rescnt < 0) {
m_rescnt= m_q->getResCnt();
}
@@ -71,7 +73,8 @@ static const string cstr_mre("[...]");
bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<Rcl::Snippet>& vpabs)
{
LOGDEB(("DocSequenceDb::getAbstract/pair\n"));
setQuery();
if (!setQuery())
return false;
// Have to put the limit somewhere.
int maxoccs = 500;
@@ -93,7 +96,8 @@ bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<Rcl::Snippet>& vpabs)
bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<string>& vabs)
{
setQuery();
if (!setQuery())
return false;
if (m_q->whatDb() &&
m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
m_q->makeDocAbstract(doc, vabs);
@@ -105,7 +109,8 @@ bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<string>& vabs)
int DocSequenceDb::getFirstMatchPage(Rcl::Doc &doc, string& term)
{
setQuery();
if (!setQuery())
return false;
if (m_q->whatDb()) {
return m_q->getFirstMatchPage(doc, term);
}
@@ -114,7 +119,8 @@ int DocSequenceDb::getFirstMatchPage(Rcl::Doc &doc, string& term)
bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
setQuery();
if (!setQuery())
return false;
string udi;
if (!FileInterner::getEnclosing(doc.url, doc.ipath, pdoc.url, pdoc.ipath,
udi))
@@ -124,7 +130,8 @@ bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
list<string> DocSequenceDb::expand(Rcl::Doc &doc)
{
setQuery();
if (!setQuery())
return list<string>();
vector<string> v = m_q->expand(doc);
return list<string>(v.begin(), v.end());
}
@@ -209,13 +216,10 @@ bool DocSequenceDb::setQuery()
return true;
m_rescnt = -1;
m_needSetQuery = !m_q->setQuery(m_fsdata);
#if 0
HighlightData hld;
m_fsdata->getTerms(hld);
string str;
hld.toString(str);
fprintf(stderr, "DocSequenceDb::setQuery: terms: %s\n", str.c_str());
#endif
if (m_needSetQuery) {
m_reason = m_q->getReason();
LOGERR(("DocSequenceDb::setQuery: rclquery::setQuery failed: %s\n",
m_reason.c_str()));
}
return !m_needSetQuery;
}
+1
View File
@@ -67,6 +67,7 @@ class DocSequenceDb : public DocSequence {
bool m_isFiltered;
bool m_isSorted;
bool m_needSetQuery; // search data changed, need to reapply before fetch
bool setQuery();
};
+4 -1
View File
@@ -319,7 +319,10 @@ int recollq(RclConfig **cfp, int argc, char **argv)
query.setSortBy(sortfield, (op_flags & OPT_D) ? false : true);
}
Chrono chron;
query.setQuery(rq);
if (!query.setQuery(rq)) {
cerr << "Query setup failed: " << query.getReason() << endl;
return(1);
}
int cnt = query.getResCnt();
if (!(op_flags & OPT_b)) {
cout << "Recoll query: " << rq->getDescription() << endl;
+34 -28
View File
@@ -337,37 +337,43 @@ void ResListPager::displayPage(RclConfig *config)
if (pageEmpty()) {
chunk << trans("<p><b>No results found</b><br>");
HighlightData hldata;
m_docSource->getTerms(hldata);
vector<string> uterms(hldata.uterms.begin(), hldata.uterms.end());
if (!uterms.empty()) {
map<string, vector<string> > spellings;
suggest(uterms, spellings);
if (!spellings.empty()) {
if (o_index_stripchars) {
chunk <<
trans("<p><i>Alternate spellings (accents suppressed): </i>")
<< "<br /><blockquote>";
} else {
chunk <<
trans("<p><i>Alternate spellings: </i>")
<< "<br /><blockquote>";
string reason = m_docSource->getReason();
if (!reason.empty()) {
chunk << "<blockquote>" << escapeHtml(reason) <<
"</blockquote></p>";
} else {
HighlightData hldata;
m_docSource->getTerms(hldata);
vector<string> uterms(hldata.uterms.begin(), hldata.uterms.end());
if (!uterms.empty()) {
map<string, vector<string> > spellings;
suggest(uterms, spellings);
if (!spellings.empty()) {
if (o_index_stripchars) {
chunk <<
trans("<p><i>Alternate spellings (accents suppressed): </i>")
<< "<br /><blockquote>";
} else {
chunk <<
trans("<p><i>Alternate spellings: </i>")
<< "<br /><blockquote>";
}
for (map<string, vector<string> >::const_iterator it0 =
spellings.begin(); it0 != spellings.end(); it0++) {
chunk << "<b>" << it0->first << "</b> : ";
for (vector<string>::const_iterator it =
it0->second.begin();
it != it0->second.end(); it++) {
chunk << *it << " ";
}
chunk << "<br />";
for (map<string, vector<string> >::const_iterator it0 =
spellings.begin(); it0 != spellings.end(); it0++) {
chunk << "<b>" << it0->first << "</b> : ";
for (vector<string>::const_iterator it =
it0->second.begin();
it != it0->second.end(); it++) {
chunk << *it << " ";
}
chunk << "<br />";
}
chunk << "</blockquote></p>";
}
chunk << "</blockquote></p>";
}
}
}
}
} else {
unsigned int resCnt = m_docSource->getResCnt();
if (m_winfirst + m_respage.size() < resCnt) {