2
// $Id: sphinxquery.h 1164 2008-02-20 00:34:50Z shodan $
6
// Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved.
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License. You should have
10
// received a copy of the GPL license along with this program; if you
11
// did not, you can find it at http://www.gnu.org/
19
//////////////////////////////////////////////////////////////////////////////
21
/// Sphinx boolean query expression type
22
enum ESphBooleanQueryExpr
30
/// Sphinx boolean query expression
31
struct CSphBooleanQueryExpr
33
ESphBooleanQueryExpr m_eType; ///< this node's type
34
CSphString m_sWord; ///< used for simple, ie. 1-word, subexpressions
35
CSphBooleanQueryExpr * m_pExpr; ///< used for composite, ie. non-word, subexperssions
36
CSphBooleanQueryExpr * m_pPrev; ///< next node in the list
37
CSphBooleanQueryExpr * m_pNext; ///< prev node in the list
38
CSphBooleanQueryExpr * m_pParent; ///< parent node
39
bool m_bInvert; ///< whether to invert word/subexpr matching result
40
bool m_bEvaluable; ///< whether this node evaluates to a document list or can only be used as a filter
42
/// ctor. zeroes out everything
43
CSphBooleanQueryExpr ();
45
/// dtor. automatically kills the child and all siblings to the right
46
~CSphBooleanQueryExpr ();
48
/// detaches this node from its siblings, parent, and subexpressions
51
/// create a new tail, if i'm the tail
52
CSphBooleanQueryExpr * NewTail ();
54
/// check if this node is totally empty
57
/// check if this node has no siblings
62
struct CSphBooleanQuery : ISphNoncopyable
64
CSphString m_sParseError;
65
CSphBooleanQueryExpr * m_pTree;
67
CSphBooleanQuery () : m_pTree ( NULL ) {}
68
~CSphBooleanQuery () { SafeDelete ( m_pTree ); }
71
//////////////////////////////////////////////////////////////////////////////
73
/// extended query word with attached position within atom
74
struct CSphExtendedQueryAtomWord
79
CSphExtendedQueryAtomWord () : m_iAtomPos ( -1 ) {}
80
CSphExtendedQueryAtomWord ( const char * sWord, int iPos ) : m_sWord ( sWord ), m_iAtomPos ( iPos ) {}
84
/// extended query atom
85
/// atom is a list of required query words with field and proximity constraints
86
struct CSphExtendedQueryAtom
88
CSphVector<CSphExtendedQueryAtomWord> m_dWords;
94
CSphExtendedQueryAtom ()
95
: m_uFields ( 0xFFFFFFFF )
96
, m_iMaxDistance( -1 )
101
virtual ~CSphExtendedQueryAtom () {}
103
/// clears but does NOT free everything
104
/// NOTE: preserves field ID!
105
virtual void Reset ()
111
/// check if we're empty
112
bool IsEmpty () const
114
return m_dWords.GetLength()==0;
119
/// extended query node
120
/// plain nodes are just an atom
121
/// non-plain nodes are a logical function over children nodes
122
struct CSphExtendedQueryNode : public ISphNoncopyable
124
CSphExtendedQueryNode * m_pParent; ///< my parent node (NULL for root ones)
126
CSphExtendedQueryAtom m_tAtom; ///< plain node atom
127
bool m_bAny; ///< whether to match any or all children (ie. OR or AND)
128
CSphVector<CSphExtendedQueryNode*> m_dChildren; ///< non-plain node children
132
CSphExtendedQueryNode ()
138
~CSphExtendedQueryNode ()
140
ARRAY_FOREACH ( i, m_dChildren )
141
SafeDelete ( m_dChildren[i] );
144
/// check if i'm empty
145
bool IsEmpty () const
147
assert ( m_tAtom.IsEmpty() || m_dChildren.GetLength()==0 );
148
return m_tAtom.IsEmpty() && ( m_dChildren.GetLength()==0 );
151
/// check if i'm plain
152
bool IsPlain () const
154
return m_dChildren.GetLength()==0;
158
/// WARNING! pNew contents may no longer be used, and pointer gets set to NULL
159
void Submit ( CSphExtendedQueryNode * & pNew, bool bAny );
161
/// make a sublevel from this node contents and given node
162
/// WARNING! pNew contents may no longer be used, and pointer gets set to NULL
163
void Sublevelize ( CSphExtendedQueryNode * & pNew, bool bAny );
168
struct CSphExtendedQuery : public ISphNoncopyable
170
CSphString m_sParseError;
171
CSphString m_sParseWarning;
172
CSphExtendedQueryNode * m_pAccept;
173
CSphExtendedQueryNode * m_pReject;
178
m_pAccept = new CSphExtendedQueryNode ();
179
m_pReject = new CSphExtendedQueryNode ();
183
~CSphExtendedQuery ()
185
SafeDelete ( m_pAccept );
186
SafeDelete ( m_pReject );
190
//////////////////////////////////////////////////////////////////////////////
192
/// parses the query and returns the resulting tree
193
/// return false and fills tQuery.m_sParseError on error
194
/// WARNING, parsed tree might be NULL (eg. if query was empty)
195
bool sphParseBooleanQuery ( CSphBooleanQuery & tQuery, const char * sQuery, const ISphTokenizer * pTokenizer );
197
/// parses the query and returns the resulting tree
198
/// return false and fills tQuery.m_sParseError on error
199
/// WARNING, parsed tree might be NULL (eg. if query was empty)
200
bool sphParseExtendedQuery ( CSphExtendedQuery & tQuery, const char * sQuery, const ISphTokenizer * pTokenizer, const CSphSchema * pSchema, CSphDict * pDict );
202
#endif // _sphinxquery_
205
// $Id: sphinxquery.h 1164 2008-02-20 00:34:50Z shodan $