1 /*
2  * Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU  General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301, USA.
18  */
19 
20 #ifndef KIWIX_SEARCH_RENDERER_H
21 #define KIWIX_SEARCH_RENDERER_H
22 
23 #include <string>
24 
25 namespace kiwix
26 {
27 
28 class Searcher;
29 class NameMapper;
30 /**
31  * The SearcherRenderer class is used to render a search result to a html page.
32  */
33 class SearchRenderer
34 {
35  public:
36   /**
37    * The default constructor.
38    *
39    * @param humanReadableName The global zim's humanReadableName.
40    *                          Used to generate pagination links.
41    */
42   SearchRenderer(Searcher* searcher, NameMapper* mapper);
43 
44   ~SearchRenderer();
45 
46   void setSearchPattern(const std::string& pattern);
47 
48   /**
49    * Set the search content id.
50    */
51   void setSearchContent(const std::string& name);
52 
53   /**
54    * Set protocol prefix.
55    */
56   void setProtocolPrefix(const std::string& prefix);
57 
58   /**
59    * Set search protocol prefix.
60    */
61   void setSearchProtocolPrefix(const std::string& prefix);
62 
63   /**
64    * set result count per page
65    */
setPageLength(unsigned int pageLength)66   void setPageLength(unsigned int pageLength){
67     this->pageLength  = pageLength;
68   }
69 
70   /**
71    * Generate the html page with the resutls of the search.
72    */
73   std::string getHtml();
74 
75  protected:
76   std::string beautifyInteger(const unsigned int number);
77   Searcher* mp_searcher;
78   NameMapper* mp_nameMapper;
79   std::string searchContent;
80   std::string searchPattern;
81   std::string protocolPrefix;
82   std::string searchProtocolPrefix;
83   unsigned int pageLength;
84   unsigned int estimatedResultCount;
85   unsigned int resultStart;
86 };
87 
88 
89 }
90 
91 #endif
92