+ beautifyInteger()

This commit is contained in:
kelson42 2011-03-22 18:27:20 +00:00
parent 5e5eb61fd2
commit 8b291cd219
2 changed files with 26 additions and 8 deletions

View File

@ -21,6 +21,20 @@
namespace kiwix { 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 */ /* Constructor */
Searcher::Searcher() : Searcher::Searcher() :
estimatedResultCount(0), estimatedResultCount(0),
@ -54,7 +68,7 @@ namespace kiwix {
} }
/* Return the result count estimation */ /* Return the result count estimation */
const unsigned int Searcher::getEstimatedResultCount() { unsigned int Searcher::getEstimatedResultCount() {
return this->estimatedResultCount; return this->estimatedResultCount;
} }
@ -82,12 +96,12 @@ namespace kiwix {
return retVal; return retVal;
} }
const bool Searcher::setResultTemplatePath(const std::string path) { bool Searcher::setResultTemplatePath(const std::string path) {
this->resultTemplatePath = path; this->resultTemplatePath = path;
return true; return true;
} }
const string Searcher::getHtml() { string Searcher::getHtml() {
const STLW::string & sSourceFile = this->resultTemplatePath; const STLW::string & sSourceFile = this->resultTemplatePath;
VMOpcodeCollector oVMOpcodeCollector; VMOpcodeCollector oVMOpcodeCollector;
@ -139,8 +153,8 @@ namespace kiwix {
result["title"] = this->resultOffset->title; result["title"] = this->resultOffset->title;
result["url"] = this->resultOffset->url; result["url"] = this->resultOffset->url;
result["snippet"] = this->resultOffset->snippet; result["snippet"] = this->resultOffset->snippet;
result["size"] = this->resultOffset->size; result["size"] = this->beautifyInteger(this->resultOffset->size);
result["wordCount"] = this->resultOffset->wordCount; result["wordCount"] = this->beautifyInteger(this->resultOffset->wordCount);
resultsCDT.PushBack(result); resultsCDT.PushBack(result);
this->resultOffset++; this->resultOffset++;
} }

View File

@ -25,6 +25,9 @@
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <locale> #include <locale>
#include <cctype> #include <cctype>
#include <vector> #include <vector>
@ -64,12 +67,13 @@ namespace kiwix {
void search(std::string &search, const unsigned int resultsCount, const bool verbose=false); void search(std::string &search, const unsigned int resultsCount, const bool verbose=false);
bool getNextResult(string &url, string &title, unsigned int &score); bool getNextResult(string &url, string &title, unsigned int &score);
const unsigned int getEstimatedResultCount(); unsigned int getEstimatedResultCount();
const bool setResultTemplatePath(const std::string path); bool setResultTemplatePath(const std::string path);
const string getHtml(); string getHtml();
void reset(); void reset();
protected: protected:
std::string beautifyInteger(const unsigned int number);
virtual void closeIndex() = 0; virtual void closeIndex() = 0;
virtual void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false) = 0; virtual void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false) = 0;