Search Query. More...

#include <gsearchquery.h>

Inheritance diagram for GSearchQuery:
[legend]

Public Member Functions

 GSearchQuery (GSession *session, GConceptExtractor *extractor, size_t caller, int options=qoStems|qoKeywords|qoExpressions|qoReplace, R::RContainer< GLang, false, false > *langs=0)
 
GSearchQueryNodeGetTop (void)
 
const GSearchQueryNodeGetTop (void) const
 
bool UseOnlyAND (void) const
 
R::RCursor< R::RStringGetTokens (void) const
 
size_t GetNbTokens (void) const
 
R::RCursor< GConceptGetConcepts (size_t min=0, size_t max=SIZE_MAX) const
 
size_t GetNbConcepts (void) const
 
bool IsIn (GConcept *concept) const
 
virtual void Build (const R::RString &query)
 
void InsertNode (GSearchQueryNode *parent, GSearchQueryNode *node)
 
void MoveNode (GSearchQueryNode *to, GSearchQueryNode *node)
 
virtual GSearchQueryNodeNewNode (const R::RString &token, GSearchToken::tType type)
 
virtual GSearchQueryNodeNewNode (GConcept *concept, GSearchToken::tType type)
 
virtual GSearchQueryNodeNewNode (GSearchQueryNode::tOperator op)
 
R::RString ClearString (const R::RString &str)
 
bool CreateToken (GSearchQueryNode *parent, const R::RString &str)
 
GSearchQueryNodeCreateToken (GSearchQueryNode *parent, const R::RString &token, GSearchToken::tType type, bool multiple)
 
 ~GSearchQuery (void)
 

Private Member Functions

GSearchQueryNodeAddORs (GSearchQueryNode *parent)
 
void TreatNode (GSearchQueryNode *node)
 
void TreatANDNode (GSearchQueryNode *node, R::RString &str)
 

Private Attributes

GSessionSession
 
R::RContainer< R::RString,
true, true > 
Tokens
 
R::RContainer< GConcept, false,
true > 
Concepts
 
R::RContainer< R::RString,
true, false > 
Tmp
 
R::RContainer< GConceptRef,
true, true > 
Found
 
bool OnlyAND
 
int Options
 
R::RContainer< GConcept, false,
true > 
Stems
 
R::RContainer< GLang, false,
false > * 
Langs
 
GConceptExtractorExtractor
 
size_t Caller
 

Additional Inherited Members

- Protected Member Functions inherited from RTree< T, N, bAlloc >
 RTree (void)
 
void ClearNode (N *node)
 
virtual void Clear (void)
 
N * GetFirst (void) const
 
N * GetLast (void) const
 
size_t GetMaxDepth (void) const
 
N * GetTop (void)
 
const N * GetTop (void) const
 
size_t GetNbNodes (void) const
 
size_t GetNbTopNodes (void) const
 
size_t GetTab (N **tab, N *node, bool children=false)
 
void InsertNode (N *to, N *node)
 
void DeleteNodes (N *node, bool del=bAlloc)
 
void DeleteNode (N *node, bool del=bAlloc)
 
void UpdateDepth (N *node)
 
void MoveNode (N *to, N *node)
 
void Copy (const RTree< T, N, a > &src)
 
void DeepCopy (N *src, N *newparent)
 
N * GetNode (const TUse &tag) const
 
double GetUpOperationsCost (const N *u, const N *v) const
 
virtual ~RTree (void)
 
- Protected Attributes inherited from RTree< T, N, bAlloc >
N * First
 
N * Last
 
size_t NbTopNodes
 
size_t NbNodes
 
size_t MaxDepth
 

Detailed Description

Search Query.

The GSearchQuery class provides a representation for a structured query, that is a tree of query nodes, where each node is either an operator or a keyword.

A query may have multiple options as defined with tQueryOption.

Constructor & Destructor Documentation

GSearchQuery ( GSession session,
GConceptExtractor extractor,
size_t  caller,
int  options = qoStems|qoKeywords|qoExpressions|qoReplace,
R::RContainer< GLang, false, false > *  langs = 0 
)

Constructor of the query.

Parameters
sessionSession.
extractorExtractor.
callerIdentifier of the caller (for example a thread).
optionsOptions of the query. By default, all options are active.
langsPointer to a container of languages that must be use for the search. When null (default value), all languages are used.
~GSearchQuery ( void  )

Destructor.

Member Function Documentation

GSearchQueryNode* GetTop ( void  )

Get the top node of a query.

Returns
a pointer to a GSearchQueryNode.
const GSearchQueryNode* GetTop ( void  ) const

Get the top node of a query.

Returns
a pointer to a GSearchQueryNode.
bool UseOnlyAND ( void  ) const

Look if only the AND operator is used.

Returns
true if it is the case.
R::RCursor<R::RString> GetTokens ( void  ) const

Get the list of tokens.

Returns
a R;;RCursor.
size_t GetNbTokens ( void  ) const
Returns
the number of tokens.
R::RCursor<GConcept> GetConcepts ( size_t  min = 0,
size_t  max = SIZE_MAX 
) const

Get the list of concepts used in the query.

Parameters
minMinimum position of the elements to iterate.
maxMaximum position of the elements to iterate (included max). If SZE_MAX, iterate until the end of the container.
Returns
a R;;RCursor.
size_t GetNbConcepts ( void  ) const
Returns
the number of concepts.
bool IsIn ( GConcept concept) const

Look if a given concept was used to formulate the query.

Parameters
conceptConcept to search for.
Returns
true if the concept was used.
virtual void Build ( const R::RString query)
virtual

Build the query based on a string. By default, it is analyses the string in order to create the tree. In practice, the query is parsed from left to right.

Parameters
queryQuery submitted.
void InsertNode ( GSearchQueryNode parent,
GSearchQueryNode node 
)

Insert a token in the query tree.

Parameters
parentParent token.
nodeToken to add.
void MoveNode ( GSearchQueryNode to,
GSearchQueryNode node 
)

Move a token in the query tree.

Parameters
toFuture parent token.
nodeToken to add.
virtual GSearchQueryNode* NewNode ( const R::RString token,
GSearchToken::tType  type 
)
virtual

Create a new node corresponding to a string.

Parameters
tokenString containing the token.
typeType of the token.
Returns
a pointer that will be inserted in the query tree.
virtual GSearchQueryNode* NewNode ( GConcept concept,
GSearchToken::tType  type 
)
virtual

Create a new node corresponding to a given concept.

Parameters
conceptConcept.
typeType of the token.
Returns
a pointer that will be inserted in the query tree.
virtual GSearchQueryNode* NewNode ( GSearchQueryNode::tOperator  op)
virtual

Create a new node corresponding to an operator.

Parameters
opOperator.
Returns
a pointer that will be inserted in the query tree.
R::RString ClearString ( const R::RString str)

Clear a string. In practice, the leading and ending spaces are removed. If the string is an expression, the corresponding parentheses are removed.

Parameters
strString to clear.
Returns
the string cleared.
bool CreateToken ( GSearchQueryNode parent,
const R::RString str 
)

Create the nodes appearing in a given string. The method is called recursively to obtain the whole query.

Parameters
parentParent node (if null, it is the top node).
strString to analyze.
Returns
true if a node was created for the string passed.
GSearchQueryNode* CreateToken ( GSearchQueryNode parent,
const R::RString token,
GSearchToken::tType  type,
bool  multiple 
)

Create a token and insert it in the query tree. Eventually, if the token is a keyword, stems are used as alternatives and combine with the OR operator.

Parameters
parentParent token.
tokenString representing the keyword.
typeType of the token
multipleIn the case of a keyword, are there multiple terms.
Returns
a pointer to the node was inserted in the query tree.
GSearchQueryNode* AddORs ( GSearchQueryNode parent)
private

Insert different alternatives (OR operator) to a given node based on the container Found.

Parameters
parentparent node.
Returns
a pointer to the last created search node.
void TreatNode ( GSearchQueryNode node)
private

Treat a node to find an AND that can create an expression.

Parameters
nodeNode to treat.
void TreatANDNode ( GSearchQueryNode node,
R::RString str 
)
private

Build all the possible expressions that results from the combinations of the keywords linked by AND operators.

Parameters
nodeNode to treat.
strString containing thz different concepts.

Member Data Documentation

GSession* Session
private

Session launching the query.

R::RContainer<R::RString,true,true> Tokens
private

Tokens given in the query.

R::RContainer<GConcept,false,true> Concepts
private

Container of all concepts.

R::RContainer<R::RString,true,false> Tmp
private

Temporary container of strings.

R::RContainer<GConceptRef,true,true> Found
private

Container to store some concepts found in the query.

bool OnlyAND
private

AND is the only operator used in the query.

int Options
private

Options of the query.

R::RContainer<GConcept,false,true> Stems
private

Temporary concepts.

R::RContainer<GLang,false,false>* Langs
private

Languages used for the stemming if necessary.

GConceptExtractor* Extractor
private

Extractor.

size_t Caller
private

Identifier of the caller.