express query language OR chains as rcldb subqueries so that field specs will work inside them

This commit is contained in:
dockes 2008-01-16 11:14:38 +00:00
parent a0f6c46874
commit 3223e8dc03
3 changed files with 41 additions and 32 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.12 2007-11-16 12:21:46 dockes Exp $ (C) 2006 J.F.Dockes"; static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.13 2008-01-16 11:14:38 dockes Exp $ (C) 2006 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -48,8 +48,14 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
{ {
if (wasa == 0) if (wasa == 0)
return 0; return 0;
if (wasa->m_op != WasaQuery::OP_AND && wasa->m_op != WasaQuery::OP_OR) {
LOGERR(("wasaQueryToRcl: top query neither AND nor OR!\n"));
return 0;
}
Rcl::SearchData *sdata = new Rcl::SearchData(Rcl::SCLT_AND); Rcl::SearchData *sdata = new
Rcl::SearchData(wasa->m_op == WasaQuery::OP_AND ? Rcl::SCLT_AND :
Rcl::SCLT_OR);
WasaQuery::subqlist_t::iterator it; WasaQuery::subqlist_t::iterator it;
Rcl::SearchDataClause *nclause; Rcl::SearchDataClause *nclause;
@ -59,7 +65,7 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
case WasaQuery::OP_NULL: case WasaQuery::OP_NULL:
case WasaQuery::OP_AND: case WasaQuery::OP_AND:
default: default:
// ?? LOGINFO(("wasaQueryToRcl: found bad NULL or AND q type in list\n"));
continue; continue;
case WasaQuery::OP_LEAF: case WasaQuery::OP_LEAF:
@ -107,7 +113,12 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
} }
sdata->addClause(nclause); sdata->addClause(nclause);
break; break;
case WasaQuery::OP_EXCL: case WasaQuery::OP_EXCL:
if (wasa->m_op != WasaQuery::OP_AND) {
LOGERR(("wasaQueryToRcl: negative clause inside OR list!\n"));
continue;
}
// Note: have to add dquotes which will be translated to // Note: have to add dquotes which will be translated to
// phrase if there are several words in there. Not pretty // phrase if there are several words in there. Not pretty
// but should work. If there is actually a single // but should work. If there is actually a single
@ -126,29 +137,21 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING); nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause); sdata->addClause(nclause);
break; break;
case WasaQuery::OP_OR: case WasaQuery::OP_OR:
// Concatenate all OR values as phrases. Hope there are no // Create a subquery.
// stray dquotes in there. Note that single terms won't be Rcl::SearchData *sub = wasaQueryToRcl(*it);
// handled as real phrases inside searchdata.cpp (so the if (sub == 0) {
// added dquotes won't interfer with stemming) continue;
{
string orvalue;
WasaQuery::subqlist_t::iterator orit;
for (orit = (*it)->m_subs.begin();
orit != (*it)->m_subs.end(); orit++) {
orvalue += string("\"") + (*orit)->m_value + "\" ";
}
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
orvalue,
(*it)->m_fieldspec);
if (nclause == 0) {
LOGERR(("wasaQueryToRcl: out of memory\n"));
return 0;
}
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause);
} }
nclause = new Rcl::SearchDataClauseSub(Rcl::SCLT_SUB, sub);
if (nclause == 0) {
LOGERR(("wasaQueryToRcl: out of memory\n"));
return 0;
}
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause);
} }
} }

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.20 2008-01-16 08:43:26 dockes Exp $ (C) 2006 J.F.Dockes"; static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.21 2008-01-16 11:14:38 dockes Exp $ (C) 2006 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -607,4 +607,11 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
return true; return true;
} }
// Translate subquery
bool SearchDataClauseSub::toNativeQuery(Rcl::Db &db, void *p,
const string& stemlang)
{
return m_sub->toNativeQuery(db, p, stemlang);
}
} // Namespace Rcl } // Namespace Rcl

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _SEARCHDATA_H_INCLUDED_ #ifndef _SEARCHDATA_H_INCLUDED_
#define _SEARCHDATA_H_INCLUDED_ #define _SEARCHDATA_H_INCLUDED_
/* @(#$Id: searchdata.h,v 1.10 2007-02-13 10:58:32 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: searchdata.h,v 1.11 2008-01-16 11:14:38 dockes Exp $ (C) 2004 J.F.Dockes */
/** /**
* Structures to hold data coming almost directly from the gui * Structures to hold data coming almost directly from the gui
@ -222,19 +222,18 @@ public:
// m_slack is declared in SearchDataClauseSimple // m_slack is declared in SearchDataClauseSimple
}; };
#ifdef NOTNOW
/** Future pointer to subquery ? */ /** Future pointer to subquery ? */
class SearchDataClauseSub : public SearchDataClause { class SearchDataClauseSub : public SearchDataClause {
public: public:
SearchDataClauseSub(SClType tp, SClType stp) // Note that we take charge of the SearchData * and will delete it.
: SearchDataClause(tp), m_sub(stp) {} SearchDataClauseSub(SClType tp, SearchData *sub)
virtual ~SearchDataClauseSub() {} : SearchDataClause(tp), m_sub(sub) {}
virtual ~SearchDataClauseSub() {delete m_sub; m_sub = 0;}
virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang); virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
protected: protected:
SearchData m_sub; SearchData *m_sub;
}; };
#endif // NOTNOW
} // Namespace Rcl } // Namespace Rcl
#endif /* _SEARCHDATA_H_INCLUDED_ */ #endif /* _SEARCHDATA_H_INCLUDED_ */