diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index 4daed2915..f362d8a0d 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -21,6 +21,20 @@ namespace kiwix { + /* Count word */ + std::string Searcher::beautifyInteger(const unsigned int number) { + stringstream numberStream; + numberStream << number; + std::string numberString = numberStream.str(); + + signed int offset = numberString.size() - 3; + while (offset > 0) { + numberString.insert(offset, "."); + offset -= 3; + } + return numberString; + } + /* Constructor */ Searcher::Searcher() : estimatedResultCount(0), @@ -54,7 +68,7 @@ namespace kiwix { } /* Return the result count estimation */ - const unsigned int Searcher::getEstimatedResultCount() { + unsigned int Searcher::getEstimatedResultCount() { return this->estimatedResultCount; } @@ -82,12 +96,12 @@ namespace kiwix { return retVal; } - const bool Searcher::setResultTemplatePath(const std::string path) { + bool Searcher::setResultTemplatePath(const std::string path) { this->resultTemplatePath = path; return true; } - const string Searcher::getHtml() { + string Searcher::getHtml() { const STLW::string & sSourceFile = this->resultTemplatePath; VMOpcodeCollector oVMOpcodeCollector; @@ -139,8 +153,8 @@ namespace kiwix { result["title"] = this->resultOffset->title; result["url"] = this->resultOffset->url; result["snippet"] = this->resultOffset->snippet; - result["size"] = this->resultOffset->size; - result["wordCount"] = this->resultOffset->wordCount; + result["size"] = this->beautifyInteger(this->resultOffset->size); + result["wordCount"] = this->beautifyInteger(this->resultOffset->wordCount); resultsCDT.PushBack(result); this->resultOffset++; } diff --git a/src/common/kiwix/searcher.h b/src/common/kiwix/searcher.h index a9b8e367d..92c94ce21 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -64,12 +67,13 @@ namespace kiwix { void search(std::string &search, const unsigned int resultsCount, const bool verbose=false); bool getNextResult(string &url, string &title, unsigned int &score); - const unsigned int getEstimatedResultCount(); - const bool setResultTemplatePath(const std::string path); - const string getHtml(); + unsigned int getEstimatedResultCount(); + bool setResultTemplatePath(const std::string path); + string getHtml(); void reset(); protected: + std::string beautifyInteger(const unsigned int number); virtual void closeIndex() = 0; virtual void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false) = 0;