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
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
/*
* This program is free software; you can redistribute it and/or modify
@ -48,8 +48,14 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
{
if (wasa == 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;
Rcl::SearchDataClause *nclause;
@ -59,7 +65,7 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
case WasaQuery::OP_NULL:
case WasaQuery::OP_AND:
default:
// ??
LOGINFO(("wasaQueryToRcl: found bad NULL or AND q type in list\n"));
continue;
case WasaQuery::OP_LEAF:
@ -107,7 +113,12 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
}
sdata->addClause(nclause);
break;
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
// phrase if there are several words in there. Not pretty
// but should work. If there is actually a single
@ -126,29 +137,21 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause);
break;
case WasaQuery::OP_OR:
// Concatenate all OR values as phrases. Hope there are no
// stray dquotes in there. Note that single terms won't be
// handled as real phrases inside searchdata.cpp (so the
// added dquotes won't interfer with stemming)
{
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);
// Create a subquery.
Rcl::SearchData *sub = wasaQueryToRcl(*it);
if (sub == 0) {
continue;
}
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
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
/*
* 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;
}
// Translate subquery
bool SearchDataClauseSub::toNativeQuery(Rcl::Db &db, void *p,
const string& stemlang)
{
return m_sub->toNativeQuery(db, p, stemlang);
}
} // Namespace Rcl

View File

@ -16,7 +16,7 @@
*/
#ifndef _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
@ -222,19 +222,18 @@ public:
// m_slack is declared in SearchDataClauseSimple
};
#ifdef NOTNOW
/** Future pointer to subquery ? */
class SearchDataClauseSub : public SearchDataClause {
public:
SearchDataClauseSub(SClType tp, SClType stp)
: SearchDataClause(tp), m_sub(stp) {}
virtual ~SearchDataClauseSub() {}
// Note that we take charge of the SearchData * and will delete it.
SearchDataClauseSub(SClType tp, SearchData *sub)
: SearchDataClause(tp), m_sub(sub) {}
virtual ~SearchDataClauseSub() {delete m_sub; m_sub = 0;}
virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
protected:
SearchData m_sub;
SearchData *m_sub;
};
#endif // NOTNOW
} // Namespace Rcl
#endif /* _SEARCHDATA_H_INCLUDED_ */