00001 #ifndef LUX_QUERY_BOOLEANQUERY_H 00002 #define LUX_QUERY_BOOLEANQUERY_H 00003 00004 #include "query.h" 00005 #include "lux/index/search_index.h" 00006 #include <vector> 00007 #include <iostream> 00008 00009 namespace Lux { 00010 00011 typedef enum { 00012 OP_AND = 1, 00013 OP_OR = 2, 00014 OP_NOT = 3, 00015 } op_t; 00016 00017 struct QuerySet { 00018 QuerySet(Query *query_, int op_type_) 00019 : query(query_), op_type(op_type_) 00020 {} 00021 Query *query; 00022 int op_type; 00023 }; 00024 00025 typedef std::vector<QuerySet> QSContainer; 00026 typedef QSContainer::const_iterator QSCIterator; 00027 00028 class BooleanQuery : public Query { 00029 public: 00030 static BooleanQuery *create(bool is_composite = false); 00031 virtual ~BooleanQuery(void); 00032 virtual IndexResultSet search(SearchIndex *si); 00033 void add(Query *query, op_t op_type = OP_AND); 00034 void set_composite(bool is_composite) { is_composite_ = is_composite; } 00035 bool is_composite(void) { return is_composite_; } 00036 bool is_composite(void) const { return is_composite_; } 00037 bool has_next(void); 00038 bool has_next(void) const; 00039 QuerySet get_next(void); 00040 QuerySet get_next(void) const; 00041 void init_iter(void) { q_sets_iterator_ = q_sets_.begin(); } 00042 void init_iter(void) const { q_sets_iterator_ = q_sets_.begin(); } 00043 virtual std::string to_str(void); 00044 00045 private: 00046 QSContainer q_sets_; 00047 mutable QSCIterator q_sets_iterator_; 00048 bool is_composite_; 00049 00050 BooleanQuery(bool is_composite = false) 00051 : is_composite_(is_composite) 00052 {} 00053 }; 00054 } 00055 00056 #endif