ddc
|
#include <QueryCompiler.h>
Public Member Functions | |
CQueryCompiler (const CConcHolder *pHolder=NULL) | |
default constructor More... | |
virtual | ~CQueryCompiler () |
default destructor More... | |
void | CleanParser () |
int | yyqlex (void *valp) |
wrapper for yylex() as called from bison parser (valp is a YYSTYPE*) More... | |
string * | newString (const string &s=string("")) |
wrapper to push a new string pointer onto the m_Labels stack (to be freed on CleanParser()) More... | |
string * | newRegex (const string &pattern, const string &modifiers=string(""), bool isMatch=true) |
const char * | yytext () const |
flex convenience wrapper More... | |
int | yyleng () const |
flex convenience wrapper More... | |
string | yystring () const |
flex convenience wrapper More... | |
void | yybegin (int new_state) |
wrapper for protected yyFlexLexer::yy_begin() More... | |
void | DeleteTree () |
delete parse tree (m_pQuery) if non-NULL; actually wipes all queries in m_Queries and m_qCountKeys More... | |
bool | ParseQuery (const string &QueryStr) |
bool | CompileFilters () |
bool | CheckSatisfiable (CQuery *query) |
bool | Compile (CQuery *query) |
bool | Evaluate (CQuery *query) |
bool | CheckSatisfiable () |
bool | Compile () |
bool | Evaluate () |
evaluate parse tree bottom-up; wrapper for Evaluate(m_pQuery) More... | |
int | GetNewNodeIndex () |
return current node index to set CQueryTokenNode::m_NodeIndex More... | |
size_t | GetNodeIndicesCount () const |
return m_CurrentNodeIndex More... | |
CQuery * | SetQuery (CQuery *qp) |
CQuery * | PushQuery (CQuery *qp) |
CQCount * | PushCountQuery (CQuery *qConditions) |
CQKeys * | PushKeysQuery (CQCount *qCount) |
CQFPrune * | newPruneFilter (HitSortEnum ftype, const string &limitStr="-1") |
void | SetFilterBounds (const string &lb="", const string &ub="") |
set string bounds for current filter (called by bison parser) More... | |
void | SetFilterKey (const string &field="", BYTE matchid=0, int offset=INT_MIN) |
set context-filter key More... | |
string | QueryToString (void) |
debug: return a string form for the current query; wraps m_pQuery->toString() + m_pQuery->optionsToString() More... | |
string | QueryToJson (void) |
return a json string form for the current query; wraps m_pQuery->toJson() + m_pQuery->optionsToJson() More... | |
void | barf (const std::string &msg) const |
error reporting: throws a errParseError exception More... | |
void | barf (const char *fmt,...) const |
error reporting: throws a errParseError exception with a printf() format More... | |
void | yybarf (const char *yymsg) const |
virtual ddcObjectList | Children () const |
virtual void | DisownChildren () |
virtual string | jsonClass () |
virtual string | jsonData () |
Public Member Functions inherited from ddcObject | |
ddcObject () | |
Default constructor. More... | |
virtual | ~ddcObject () |
virtual destructor does nothing More... | |
template<typename Visit > | |
ddcObject * | Traverse (Visit &visit) |
template<typename Visit > | |
ddcObject * | Traverse (Visit &visit) const |
template<typename Visit > | |
ddcObject * | TraverseR (Visit &visit) |
template<typename Visit > | |
ddcObject * | TraverseR (Visit &visit) const |
virtual ddcObjectList | Descendants () const |
virtual string | toString () |
virtual string | toJson () |
Public Attributes | |
const CConcHolder * | m_pHolder |
a reference to the holder, for which this query is parsed More... | |
CQuery * | m_pQuery |
root of the abstract parse tree More... | |
CQueryOptions | m_qOptions |
query options (adopted into top-level m_pQuery on SetQuery()) More... | |
size_t | m_Limit |
query limit (anything but 0 (default) overrides CConcHolder arguments) More... | |
bool | m_bSatisfiable |
is query satisfiable? (default is true, may be set to false by CheckSatisfiable()) More... | |
CQCountKeyExprList | m_qCountKeys |
count()-query keys More... | |
size_t | m_qCountSample |
count()-query sample size (overrides count-query m_dtr->m_Options->m_Limit if set) More... | |
size_t | m_qCountLimit |
count()-query result-set size (for keys()-queries) More... | |
HitSortEnum | m_qCountSort |
count()-query sort order More... | |
string | m_qCountLo |
count()-query lower bound More... | |
string | m_qCountHi |
count()-query upper bound More... | |
vector< string > | m_IndexTuple |
keys()-query tuple More... | |
set< string > | m_WordSet |
temporary for $i={w1,w2,...,wN} word-set queries More... | |
vector< string > | m_Expanders |
temporary for "% X1 % X2 ..." expansion queries More... | |
vector< string > | m_MorphItems |
temporary for [m1,m2,...,mN] morph-pattern queries More... | |
string | m_FilterField |
temporary for filter field (#less_by_xyz, #greater_by_xyz) More... | |
string | m_FilterLB |
temporary for filter lower bound (#less_by_xyz, #greater_by_xyz) More... | |
string | m_FilterUB |
temporary for filter upper bound (#less_by_xyz, #greater_by_xyz) More... | |
BYTE | m_FilterMatchId |
temporary for filter reference match-id (#left, #right, #mid; default=0:any) More... | |
int | m_FilterOffset |
temporary for filter offsets (#left, #right, #mid; default=0:any) More... | |
string | m_RegexPattern |
temporary for regex patterns More... | |
string | m_RegexReplacement |
temporary for regex replacement strings (used by count-keys) More... | |
string | m_RegexModifiers |
temporary for regex modifiers More... | |
int | m_CurrentNodeIndex |
current node index to set CQueryTokenNode::m_NodeIndex More... | |
vector< CQuery * > | m_Queries |
set of all query nodes allocated during current parse More... | |
list< string > | m_Labels |
a special slot for YACC (which contains all string leaves of the parse tree) More... | |
bool | m_KeepLexerComments |
enable collection of lexer comments in m_pQuery->m_Options->m_LexerComments (default=false) More... | |
Public Attributes inherited from ddcObject | |
void * | m_User |
user data associated with this object (for use e.g. by perl wrappers) More... | |
Static Public Attributes | |
static const size_t | m_MaxContextSentencesCount = 5 |
maximum context size for #cntxt operator More... | |
CQueryCompiler is a class for the parse tree of the input query and its general properties.
Descended from FlexLexer (abstract class of flex tool), so it should implement also flex parser's functionality (DDC uses YACC in thread-safe mode).
moo: renamed CQueryParser to CQueryCompiler to reflect actual functionality.
CQueryCompiler::CQueryCompiler | ( | const CConcHolder * | pHolder = NULL | ) |
default constructor
References DDCDefaultCountSampleSize, m_CurrentNodeIndex, m_KeepLexerComments, m_Limit, m_pHolder, m_pQuery, m_qCountLimit, m_qCountSample, m_qCountSort, and NoSort.
|
virtual |
void CQueryCompiler::CleanParser | ( | ) |
make this parse ready for a new call of ParseQuery()
References CQueryOptions::Clear(), CQCountKeyExprList::Clear(), DDCDefaultCountSampleSize, DeleteTree(), m_bSatisfiable, m_CurrentNodeIndex, m_Expanders, m_FilterField, m_FilterLB, m_FilterMatchId, m_FilterOffset, m_FilterUB, m_IndexTuple, m_Labels, m_Limit, m_MorphItems, m_qCountHi, m_qCountKeys, m_qCountLimit, m_qCountLo, m_qCountSample, m_qCountSort, m_qOptions, m_RegexModifiers, m_RegexPattern, m_RegexReplacement, m_WordSet, and NoSort.
Referenced by CRunQueryData::Clear(), ParseQuery(), and ~CQueryCompiler().
int CQueryCompiler::yyqlex | ( | void * | valp | ) |
wrapper for yylex() as called from bison parser (valp is a YYSTYPE*)
References BLOCK_COMMENT, DATE, DDC_STATIC_BUFLEN, errParseError, EXPANDER, INDEX, INFIX, INTEGER, KW_DATE, KW_FILEID, KW_FILENAME, LINE_COMMENT, m_KeepLexerComments, CQueryOptions::m_LexerComments, m_qOptions, m_RegexModifiers, m_RegexPattern, m_RegexReplacement, NEG_REGEX, newString(), PREFIX, REGEX, REGEX_REPLACE, REGEX_SEARCH, REGOPT, SUFFIX, SYMBOL, yyleng(), yylex, and yytext().
Referenced by yyqlex().
string * CQueryCompiler::newString | ( | const string & | s = string("") | ) |
wrapper to push a new string pointer onto the m_Labels stack (to be freed on CleanParser())
References m_Labels.
Referenced by newRegex(), and yyqlex().
string * CQueryCompiler::newRegex | ( | const string & | pattern, |
const string & | modifiers = string("") , |
||
bool | isMatch = true |
||
) |
wrapper for regexes, similar to "(?" + modifers + ":" + pattern + ")"
isMatch | if true (default), /g modifier will cause regex to be wrapped in '^' and '$' anchors (match whole string) |
References newString().
|
inline |
|
inline |
|
inline |
flex convenience wrapper
References CheckSatisfiable(), Compile(), CompileFilters(), DeleteTree(), Evaluate(), ParseQuery(), and yybegin().
void CQueryCompiler::yybegin | ( | int | new_state | ) |
wrapper for protected yyFlexLexer::yy_begin()
Referenced by ParseQuery(), and yystring().
void CQueryCompiler::DeleteTree | ( | ) |
delete parse tree (m_pQuery) if non-NULL; actually wipes all queries in m_Queries and m_qCountKeys
References CQCountKeyExprList::Clear(), DDCDefaultCountSampleSize, m_Limit, m_pQuery, m_qCountHi, m_qCountKeys, m_qCountLimit, m_qCountLo, m_qCountSample, m_qCountSort, m_Queries, and NoSort.
Referenced by CleanParser(), and yystring().
bool CQueryCompiler::ParseQuery | ( | const string & | QueryStr | ) |
parse QueryStr
and build a parse tree for it in m_pQuery
References CleanParser(), m_pQuery, QueryToString(), yybegin(), yyqdebug, and yyqparse().
Referenced by CRunQueryData::Init(), and yystring().
bool CQueryCompiler::CompileFilters | ( | ) |
moo: compile and apply filters in m_pQuery->m_Options->m_QFilters OBSOLETE : now just a wrapper for m_pQuery->CompileOptions(this)
References CQuery::CompileOptions(), and m_pQuery.
Referenced by yystring().
bool CQueryCompiler::CheckSatisfiable | ( | CQuery * | query | ) |
moo: check the current parsed query (m_pQuery) for unsatisfiability with respect to the current index (m_pHolder) and compiler options (m_HitTypeStr etc.)
References CQuery::CheckSatisfiable(), and m_bSatisfiable.
bool CQueryCompiler::Compile | ( | CQuery * | query | ) |
moo: compile the given query (query) with respect to the current index (m_pHolder) and compiler options (m_HitTypeStr etc.)
References CQuery::Compile(), CQuery::CompileOptions(), errParseError, CQuery::RootOK(), and CQuery::toString().
bool CQueryCompiler::Evaluate | ( | CQuery * | query | ) |
evaluate parse tree bottom-up
References Compile(), CQuery::Evaluate(), and CQuery::m_Compiler.
|
inline |
wrapper for CheckSatisfiable(m_pQuery)
Referenced by yystring().
|
inline |
wrapper for Compile(m_pQuery)
Referenced by Evaluate(), and yystring().
|
inline |
evaluate parse tree bottom-up; wrapper for Evaluate(m_pQuery)
References GetNewNodeIndex(), GetNodeIndicesCount(), and SetQuery().
Referenced by yystring().
int CQueryCompiler::GetNewNodeIndex | ( | ) |
return current node index to set CQueryTokenNode::m_NodeIndex
References m_CurrentNodeIndex.
Referenced by CQToken::Compile(), and Evaluate().
size_t CQueryCompiler::GetNodeIndicesCount | ( | ) | const |
return m_CurrentNodeIndex
References m_CurrentNodeIndex.
Referenced by Evaluate().
set current top-level query, adopting filters and flags; sets this->m_pQuery=qp Called by bison during the parse.
References CQueryOptions::Clear(), m_pQuery, m_qOptions, CQuery::SetOptions(), and CQueryOptions::swap().
Referenced by Evaluate(), and PushCountQuery().
push a newly allocated CQuery* onto the stack. Called by bison during the parse.
References barf(), Children(), DisownChildren(), newPruneFilter(), PushCountQuery(), PushKeysQuery(), QueryToJson(), QueryToString(), SetFilterBounds(), SetFilterKey(), and yybarf().
Referenced by PushCountQuery(), and PushKeysQuery().
push a newly allocated CQCount* count-query onto the stack, setting m_CountBy Called by bison during the parse.
References DDCDefaultCountSampleSize, CQCountKeyExprList::m_Exprs, m_qCountHi, m_qCountKeys, m_qCountLo, m_qCountSample, m_qCountSort, NoSort, PushQuery(), and SetQuery().
Referenced by PushQuery().
push a newly allocated CQKeys* query onto the stack. called by bison during the parse.
References m_IndexTuple, m_Limit, m_qCountLimit, and PushQuery().
Referenced by PushQuery().
CQFPrune * CQueryCompiler::newPruneFilter | ( | HitSortEnum | ftype, |
const string & | limitStr = "-1" |
||
) |
allocated CQFPrune* filter onto Called by bison during the parse.
References CQCountKeyExprList::m_Exprs, and m_qCountKeys.
Referenced by PushQuery().
void CQueryCompiler::SetFilterBounds | ( | const string & | lb = "" , |
const string & | ub = "" |
||
) |
set string bounds for current filter (called by bison parser)
References m_FilterLB, and m_FilterUB.
Referenced by PushQuery(), and SetFilterKey().
void CQueryCompiler::SetFilterKey | ( | const string & | field = "" , |
BYTE | matchid = 0 , |
||
int | offset = INT_MIN |
||
) |
set context-filter key
References m_FilterField, m_FilterMatchId, m_FilterOffset, and SetFilterBounds().
Referenced by PushQuery().
string CQueryCompiler::QueryToString | ( | void | ) |
debug: return a string form for the current query; wraps m_pQuery->toString() + m_pQuery->optionsToString()
References m_pQuery, CQuery::optionsToString(), and CQuery::toString().
Referenced by ParseQuery(), and PushQuery().
string CQueryCompiler::QueryToJson | ( | void | ) |
return a json string form for the current query; wraps m_pQuery->toJson() + m_pQuery->optionsToJson()
References m_pQuery, CQuery::optionsToJson(), and CQuery::toJson().
Referenced by PushQuery().
void CQueryCompiler::barf | ( | const std::string & | msg | ) | const |
error reporting: throws a errParseError exception
References errParseError.
Referenced by PushQuery(), and yybarf().
void CQueryCompiler::barf | ( | const char * | fmt, |
... | |||
) | const |
error reporting: throws a errParseError exception with a printf() format
References BARFSIZE, and errParseError.
void CQueryCompiler::yybarf | ( | const char * | yymsg | ) | const |
error reporting: throw a verbose errParseError exception using current lexer+parser context
References barf().
Referenced by PushQuery().
|
virtual |
get a list of direct ddcObject daughters of this node
Reimplemented from ddcObject.
References m_pQuery.
Referenced by PushQuery().
|
virtual |
"disown" any direct child objects, preventing their destruction if the current object is deleted
Reimplemented from ddcObject.
References m_pQuery, and m_Queries.
Referenced by PushQuery().
|
inlinevirtual |
class-name for json strinfication
Reimplemented from ddcObject.
|
inlinevirtual |
|
static |
maximum context size for #cntxt operator
Referenced by CQueryOptions::Compile().
const CConcHolder* CQueryCompiler::m_pHolder |
a reference to the holder, for which this query is parsed
Referenced by CQToken::BreakName(), CQueryOptions::CheckSatisfiable(), CQueryOptions::Compile(), CQCountKeyExprIndexed::Compile(), CQFRandomSort::Compile(), CQFBiblSort::Compile(), CQCountKeyExprToken::Compile(), CQFContextSort::Compile(), CQAnd::Compile(), CQOr::Compile(), CQWith::Compile(), CQFHasFieldValue::Compile(), CQWithout::Compile(), CQFHasFieldRegex::Compile(), CQWithor::Compile(), CQToken::Compile(), CQFHasFieldSet::Compile(), CQKeys::Compile(), CQNear::Compile(), CQSeq::Compile(), CQueryCompiler(), CQToken::Create(), CQTokAny::Create(), CQTokAnchor::Create(), CQTokRegex::Create(), CQTokSet::Create(), CQTokInfl::Create(), CQTokSetInfl::Create(), CQTokPrefix::Create(), CQTokSuffix::Create(), CQTokInfix::Create(), CQTokPrefixSet::Create(), CQTokSuffixSet::Create(), CQTokInfixSet::Create(), CQTokMorph::Create(), CQTokLemma::Create(), CQTokThes::Create(), CQTokChunk::Create(), CQTokFile::Create(), CQFSort::GetBiblConstant(), CQTokInfl::GetChain(), CQToken::IndexName(), CQFPrune::PruneHitsIndex(), and CQFSort::ResolveAttributeName().
CQuery* CQueryCompiler::m_pQuery |
root of the abstract parse tree
Referenced by Children(), CompileFilters(), CQueryCompiler(), DeleteTree(), DisownChildren(), ParseQuery(), CRunQueryData::Query(), QueryToJson(), QueryToString(), and SetQuery().
CQueryOptions CQueryCompiler::m_qOptions |
query options (adopted into top-level m_pQuery on SetQuery())
Referenced by CleanParser(), SetQuery(), and yyqlex().
size_t CQueryCompiler::m_Limit |
query limit (anything but 0 (default) overrides CConcHolder arguments)
Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushKeysQuery().
bool CQueryCompiler::m_bSatisfiable |
is query satisfiable? (default is true, may be set to false by CheckSatisfiable())
Referenced by CheckSatisfiable(), CleanParser(), CQFBiblSort::Compile(), CQFContextSort::Compile(), CQFHasFieldValue::Compile(), CQFHasFieldRegex::Compile(), CQToken::Compile(), CQFHasFieldSet::Compile(), and CConcSession::GetHits().
CQCountKeyExprList CQueryCompiler::m_qCountKeys |
count()-query keys
Referenced by CleanParser(), DeleteTree(), newPruneFilter(), and PushCountQuery().
size_t CQueryCompiler::m_qCountSample |
count()-query sample size (overrides count-query m_dtr->m_Options->m_Limit if set)
Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushCountQuery().
size_t CQueryCompiler::m_qCountLimit |
count()-query result-set size (for keys()-queries)
Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushKeysQuery().
HitSortEnum CQueryCompiler::m_qCountSort |
count()-query sort order
Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushCountQuery().
string CQueryCompiler::m_qCountLo |
count()-query lower bound
Referenced by CleanParser(), DeleteTree(), and PushCountQuery().
string CQueryCompiler::m_qCountHi |
count()-query upper bound
Referenced by CleanParser(), DeleteTree(), and PushCountQuery().
vector<string> CQueryCompiler::m_IndexTuple |
keys()-query tuple
Referenced by CleanParser(), and PushKeysQuery().
set<string> CQueryCompiler::m_WordSet |
temporary for $i={w1,w2,...,wN} word-set queries
Referenced by CleanParser().
vector<string> CQueryCompiler::m_Expanders |
temporary for "% X1 % X2 ..." expansion queries
Referenced by CleanParser().
vector<string> CQueryCompiler::m_MorphItems |
temporary for [m1,m2,...,mN] morph-pattern queries
Referenced by CleanParser().
string CQueryCompiler::m_FilterField |
temporary for filter field (#less_by_xyz, #greater_by_xyz)
Referenced by CleanParser(), and SetFilterKey().
string CQueryCompiler::m_FilterLB |
temporary for filter lower bound (#less_by_xyz, #greater_by_xyz)
Referenced by CleanParser(), and SetFilterBounds().
string CQueryCompiler::m_FilterUB |
temporary for filter upper bound (#less_by_xyz, #greater_by_xyz)
Referenced by CleanParser(), and SetFilterBounds().
BYTE CQueryCompiler::m_FilterMatchId |
temporary for filter reference match-id (#left, #right, #mid; default=0:any)
Referenced by CleanParser(), and SetFilterKey().
int CQueryCompiler::m_FilterOffset |
temporary for filter offsets (#left, #right, #mid; default=0:any)
Referenced by CleanParser(), and SetFilterKey().
string CQueryCompiler::m_RegexPattern |
temporary for regex patterns
Referenced by CleanParser(), and yyqlex().
string CQueryCompiler::m_RegexReplacement |
temporary for regex replacement strings (used by count-keys)
Referenced by CleanParser(), and yyqlex().
string CQueryCompiler::m_RegexModifiers |
temporary for regex modifiers
Referenced by CleanParser(), and yyqlex().
int CQueryCompiler::m_CurrentNodeIndex |
current node index to set CQueryTokenNode::m_NodeIndex
Referenced by CleanParser(), CQueryCompiler(), GetNewNodeIndex(), and GetNodeIndicesCount().
vector<CQuery*> CQueryCompiler::m_Queries |
set of all query nodes allocated during current parse
Referenced by DeleteTree(), and DisownChildren().
list<string> CQueryCompiler::m_Labels |
a special slot for YACC (which contains all string leaves of the parse tree)
Referenced by CleanParser(), and newString().
bool CQueryCompiler::m_KeepLexerComments |
enable collection of lexer comments in m_pQuery->m_Options->m_LexerComments (default=false)
Referenced by CQueryCompiler(), and yyqlex().