.. _program_listing_file_include_zim_search.h: Program Listing for File search.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/zim/search.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (C) 2017-2021 Matthieu Gautier * Copyright (C) 2021 Maneesh P M * Copyright (C) 2007 Tommi Maekitalo * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef ZIM_SEARCH_H #define ZIM_SEARCH_H #include "search_iterator.h" #include "archive.h" #include #include namespace Xapian { class Enquire; class MSet; }; namespace zim { class Archive; class InternalDataBase; class Query; class Search; class SearchResultSet; class LIBZIM_API Searcher { public: explicit Searcher(const std::vector& archives); explicit Searcher(const Archive& archive); Searcher(const Searcher& other); Searcher& operator=(const Searcher& other); Searcher(Searcher&& other); Searcher& operator=(Searcher&& other); ~Searcher(); Searcher& addArchive(const Archive& archive); Search search(const Query& query); void setVerbose(bool verbose); private: // methods void initDatabase(); private: // data std::shared_ptr mp_internalDb; std::vector m_archives; bool m_verbose; }; class LIBZIM_API Query { public: Query(const std::string& query = ""); Query& setQuery(const std::string& query); Query& setGeorange(float latitude, float longitude, float distance); std::string m_query { "" }; bool m_geoquery { false }; float m_latitude { 0 }; float m_longitude { 0 }; float m_distance { 0 } ; }; class LIBZIM_API Search { public: Search(Search&& s); Search& operator=(Search&& s); ~Search(); const SearchResultSet getResults(int start, int maxResults) const; int getEstimatedMatches() const; private: // methods Search(std::shared_ptr p_internalDb, const Query& query); Xapian::Enquire& getEnquire() const; private: // data std::shared_ptr mp_internalDb; mutable std::unique_ptr mp_enquire; Query m_query; friend class Searcher; }; class LIBZIM_API SearchResultSet { public: typedef SearchIterator iterator; iterator begin() const; iterator end() const; int size() const; private: SearchResultSet(std::shared_ptr p_internalDb, Xapian::MSet&& mset); SearchResultSet(std::shared_ptr p_internalDb); private: // data std::shared_ptr mp_internalDb; std::shared_ptr mp_mset; friend class Search; }; } //namespace zim #endif // ZIM_SEARCH_H