strusAnalyzer  0.17
queryTermExpression.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_ANALYZER_QUERY_TERM_EXPRESSION_HPP_INCLUDED
11 #define _STRUS_ANALYZER_QUERY_TERM_EXPRESSION_HPP_INCLUDED
13 #include <string>
14 #include <vector>
15 
17 namespace strus {
19 namespace analyzer {
20 
23 {
24 public:
28 #if __cplusplus >= 201103L
30  QueryTermExpression( const QueryTermExpression& ) = default;
31  QueryTermExpression& operator= ( QueryTermExpression&& ) = default;
32  QueryTermExpression& operator= ( const QueryTermExpression& ) = default;
33 #else
35  :m_terms(o.m_terms)
36  ,m_instructions(o.m_instructions){}
37 #endif
38 
41  {
42  public:
44  static const char* opCodeName( OpCode i)
45  {
46  static const char* ar[] = {"term","op"};
47  return ar[i];
48  }
49 
50  Instruction( OpCode opCode_, int idx_, std::size_t nofOperands_=0)
51  :m_opCode(opCode_),m_idx(idx_),m_nofOperands(nofOperands_){}
53  :m_opCode(o.m_opCode),m_idx(o.m_idx),m_nofOperands(o.m_nofOperands){}
54 
56  OpCode opCode() const {return m_opCode;}
58  int idx() const {return m_idx;}
60  int nofOperands() const {return m_nofOperands;}
61 
62  private:
63  friend class QueryTermExpression;
64  OpCode m_opCode;
65  int m_idx;
66  int m_nofOperands;
67  };
68 
71  const std::vector<Instruction>& instructions() const {return m_instructions;}
72 
75  const analyzer::QueryTerm& term( int idx) const
76  {
77  return m_terms[ idx];
78  }
79 
82  void pushTerm( const analyzer::QueryTerm& term_)
83  {
84  m_instructions.push_back( Instruction( Instruction::Term, m_terms.size()));
85  m_terms.push_back( term_);
86  }
87 
91  void pushOperator( int operatorId, int nofOperands)
92  {
93  m_instructions.push_back( Instruction( Instruction::Operator, operatorId, nofOperands));
94  }
95 
96 private:
97  std::vector<analyzer::QueryTerm> m_terms;
98  std::vector<Instruction> m_instructions;
99 };
100 
101 }}//namespace
102 #endif
103 
Query instruction.
Definition: queryTermExpression.hpp:40
void pushTerm(const analyzer::QueryTerm &term_)
Add a search index term to the query.
Definition: queryTermExpression.hpp:82
int nofOperands() const
Number of operands.
Definition: queryTermExpression.hpp:60
OpCode
Definition: queryTermExpression.hpp:43
OpCode opCode() const
Opcode identifier.
Definition: queryTermExpression.hpp:56
Definition: queryTermExpression.hpp:43
void pushOperator(int operatorId, int nofOperands)
Add an instruction.
Definition: queryTermExpression.hpp:91
Instruction(const Instruction &o)
Definition: queryTermExpression.hpp:52
Instruction(OpCode opCode_, int idx_, std::size_t nofOperands_=0)
Definition: queryTermExpression.hpp:50
const std::vector< Instruction > & instructions() const
Get the list of query instructions.
Definition: queryTermExpression.hpp:71
const analyzer::QueryTerm & term(int idx) const
Get the argument of a term instruction.
Definition: queryTermExpression.hpp:75
Structure describing a typed query term.
QueryTermExpression()
Default constructor.
Definition: queryTermExpression.hpp:26
int idx() const
Index of the element in the associated list to retrieve with term(std::size_t) or the operator group ...
Definition: queryTermExpression.hpp:58
QueryTermExpression(const QueryTermExpression &o)
Copy constructor.
Definition: queryTermExpression.hpp:34
Structure describing a typed query term.
Definition: queryTerm.hpp:21
static const char * opCodeName(OpCode i)
Definition: queryTermExpression.hpp:44
Expression of a query terms as result of a query analysis.
Definition: queryTermExpression.hpp:22