00001 /* Copyright (C) 2010 webis.de 00002 * All rights reserved. 00003 */ 00004 #ifndef AITOOLS_INVERTEDINDEX_STORAGE_SEARCHER_HPP 00005 #define AITOOLS_INVERTEDINDEX_STORAGE_SEARCHER_HPP 00006 00007 #include "NonCopyable.hpp" 00008 #include "StorageBuilder.hpp" 00009 #include "PostlistReader.hpp" 00010 #include "MPHashFunction.hpp" 00011 #include <boost/thread/mutex.hpp> 00012 #include <boost/filesystem.hpp> 00013 #include <stdexcept> 00014 #include <vector> 00015 00016 namespace bfs = boost::filesystem; 00017 00018 namespace aitools { 00019 namespace invertedindex { 00020 00030 class StorageSearcher : public NonCopyable { 00031 00032 private: // nested types 00033 00034 typedef PostlistReader::shared_pointer Reader; 00035 typedef StorageBuilder::Location Location; 00036 typedef std::vector<Location> LocationVector; 00037 typedef std::vector<Quantile> QuantileVector; 00038 typedef std::vector<Reader> ReaderVector; 00039 00040 private: // class member 00041 00042 static const Quantile empty_quantile; 00043 00044 public: 00045 00046 StorageSearcher(); 00047 00048 ~StorageSearcher(); 00049 00050 public: // member 00051 00052 void close(); 00053 00054 bool is_open() const; 00055 00056 void open(const bfs::path& directory) throw (std::invalid_argument); 00057 00058 Iterator::SharedPointer 00059 get(const std::string& key) throw (std::runtime_error); 00060 00061 Iterator::SharedPointer 00062 get(const std::string& key, size_t length) throw (std::runtime_error); 00063 00064 Iterator::SharedPointer 00065 get(const std::string& key, Quantile::Order order) 00066 throw (std::runtime_error); 00067 00068 const Quantile& quantile(const std::string& key) const; 00069 00070 const Vocabulary& vocabulary() const; 00071 00072 const MPHashFunction& mphf() const; 00073 00074 private: // data 00075 00076 ReaderVector readers_; 00077 QuantileVector quantiles_; 00078 LocationVector locations_; 00079 MPHashFunction hash_func_; 00080 Vocabulary vocabulary_; 00081 bfs::path directory_; 00082 boost::mutex mutex_; 00083 00084 }; 00085 00086 } // namespace invertedindex 00087 } // namespace aitools 00088 00089 #endif // AITOOLS_INVERTEDINDEX_STORAGE_SEARCHER_HPP