Commit 3e958134 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

Fix autophrase for queries produced by new parser

parent db7b05c1
......@@ -90,12 +90,28 @@ bool SearchData::maybeAddAutoPhrase(Rcl::Db& db, double freqThreshold)
// field names, bail out.
for (qlist_it_t it = m_query.begin(); it != m_query.end(); it++) {
SClType tp = (*it)->m_tp;
if (tp != SCLT_AND && tp != SCLT_OR) {
LOGDEB2(("SearchData::maybeAddAutoPhrase: rejected clause\n"));
SearchDataClauseSimple *clp = 0;
if (tp == SCLT_SUB) {
// The query language parser produces subqueries for simple terms
SearchDataClauseSub *subclp =
dynamic_cast<SearchDataClauseSub*>(*it);
if (subclp == 0) {
LOGDEB2(("SearchData::maybeAddAutoPhrase: "
"dyncast to clauseSub failed\n"));
return false;
}
if (!subclp->getSub()->singleSimple()) {
LOGDEB2(("SearchData::maybeAddAutoPhrase: !pureSingle\n"));
return false;
}
clp = dynamic_cast<SearchDataClauseSimple*>(
*(subclp->getSub()->m_query.begin()));
} else if (tp != SCLT_AND && tp != SCLT_OR) {
LOGDEB2(("SearchData::maybeAddAutoPhrase: wrong tp %d\n", tp));
return false;
}
SearchDataClauseSimple *clp =
dynamic_cast<SearchDataClauseSimple*>(*it);
} else {
clp = dynamic_cast<SearchDataClauseSimple*>(*it);
}
if (clp == 0) {
LOGDEB2(("SearchData::maybeAddAutoPhrase: dyncast failed\n"));
return false;
......@@ -183,6 +199,18 @@ bool SearchData::fileNameOnly()
return true;
}
bool SearchData::singleSimple()
{
if (m_query.size() != 1 || !m_filetypes.empty() || !m_nfiletypes.empty() ||
m_haveDates || m_maxSize != size_t(-1) || m_minSize != size_t(-1) ||
m_haveWildCards)
return false;
SearchDataClause *clp = *m_query.begin();
if (clp->getTp() != SCLT_AND && clp->getTp() != SCLT_OR)
return false;
return true;
}
// Extract all term data
void SearchData::getTerms(HighlightData &hld) const
{
......
......@@ -95,6 +95,9 @@ public:
/** Is there anything but a file name search in here ? */
bool fileNameOnly();
/** Are we a simple query with one clause? */
bool singleSimple();
/** Do we have wildcards anywhere apart from filename searches ? */
bool haveWildCards() {return m_haveWildCards;}
......@@ -488,7 +491,9 @@ public:
{
m_sub.getconstptr()->getTerms(hldata);
}
virtual RefCntr<SearchData> getSub() {
return m_sub;
}
protected:
RefCntr<SearchData> m_sub;
};
......
......@@ -980,7 +980,6 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p)
*qp = Xapian::Query();
vector<Xapian::Query> pqueries;
Xapian::Query nq;
// We produce a single phrase out of the user entry then use
// stringToXapianQueries() to lowercase and simplify the phrase
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment