00001 #ifndef LUX_INDEX_INVERTEDINDEX_H 00002 #define LUX_INDEX_INVERTEDINDEX_H 00003 00004 #include "lux/lux.h" 00005 #include "lux/scoped_ptr.h" 00006 #include "search_index.h" 00007 #include "inverted_index_core.h" 00008 #include "document/document_definition.pb.h" 00009 #include "lexer/lexer.h" 00010 #include <cstring> 00011 00012 namespace Lux { 00013 00014 class Query; 00015 class TermQuery; 00016 class PhraseQuery; 00017 class BooleanQuery; 00018 00022 class InvertedIndex : public SearchIndex { 00023 00024 public: 00025 InvertedIndex(Config::Document &doc_config); 00026 virtual ~InvertedIndex(); 00027 virtual bool open(std::string storage_dir, db_flags_t open_params); 00028 virtual bool close(void); 00029 virtual bool add(const Document *doc); 00030 virtual bool add(const Document &doc); 00031 virtual void flush(void); 00032 virtual uint32_t get_buffer_size(void); 00033 virtual void print_buffer(void); 00034 virtual void set_sys_cond(sys_cond_t sys_cond); 00035 virtual IndexResultSet search(Query *query); 00036 virtual IndexResultSet search_term(TermQuery *qterm); 00037 virtual IndexResultSet search_phrase(PhraseQuery *qphrase); 00038 virtual IndexResultSet search_boolean(BooleanQuery *qboolean); 00039 00040 private: 00041 scoped_ptr<LuxLexer> lexer_; 00042 IndexEngineSet index_engine_set_; 00043 scoped_ptr<IndexBufferSet> index_buffer_set_; 00044 scoped_ptr<IndexDataSet> index_data_set_; 00045 Config::Document doc_config_; 00046 sys_cond_t sys_cond_; 00047 00048 LuxDataUnit *get_term_unit_(TermQuery *qterm); 00049 Posting get_term_pos_(TermQuery *qterm); 00050 Posting get_phrase_pos_(PhraseQuery *qphrase); 00051 IndexResultSet pos_to_rs_(Posting &p); 00052 pos_list_t _intersect(LuxDataUnit *u1, LuxDataUnit *u2, int diff); 00053 pos_list_t _intersect(LuxDataUnit *u, pos_list_t &p, int diff); 00054 pos_list_t _intersect(pos_list_t &p, LuxDataUnit *u, int diff); 00055 00056 }; 00057 } 00058 00059 #endif