FIXED: Number of articles to high in the library (ID: 3396763)

This commit is contained in:
kelson42 2012-02-27 11:32:06 +00:00
parent 0b50729e03
commit bc8a400fd1
2 changed files with 62 additions and 2 deletions

View File

@ -67,14 +67,68 @@ namespace kiwix {
void Reader::reset() {
this->currentArticleOffset = this->firstArticleOffset;
}
std::map<std::string, unsigned int> Reader::parseCounterMetadata() {
std::map<std::string, unsigned int> counters;
string content, mimeType, item, counterString;
unsigned int contentLength, counter;
string counterUrl = "/M/Counter";
this->getContentByUrl(counterUrl, content, contentLength, mimeType);
stringstream ssContent(content);
while(getline(ssContent, item, ';')) {
stringstream ssItem(item);
getline(ssItem, mimeType, '=');
getline(ssItem, counterString, '=');
if (!counterString.empty() && !mimeType.empty()) {
sscanf(counterString.c_str(), "%u", &counter);
counters.insert(pair<string, int>(mimeType, counter));
}
}
return counters;
}
/* Get the count of articles which can be indexed/displayed */
unsigned int Reader::getArticleCount() {
return this->articleCount;
std::map<std::string, unsigned int> counterMap = this->parseCounterMetadata();
unsigned int counter = 0;
if (counterMap.empty())
counter = this->articleCount;
else {
std::map<std::string, unsigned int>::const_iterator it = counterMap.find("text/html");
if (it != counterMap.end())
counter = it->second;
}
return counter;
}
unsigned int Reader::getMediaCount() {
return this->mediaCount;
std::map<std::string, unsigned int> counterMap = this->parseCounterMetadata();
unsigned int counter = 0;
if (counterMap.empty())
counter = this->mediaCount;
else {
std::map<std::string, unsigned int>::const_iterator it;
it = counterMap.find("image/jpeg");
if (it != counterMap.end())
counter += it->second;
it = counterMap.find("image/gif");
if (it != counterMap.end())
counter += it->second;
it = counterMap.find("image/png");
if (it != counterMap.end())
counter += it->second;
}
return counter;
}
/* Return the UID of the ZIM file */

View File

@ -24,8 +24,10 @@
#include <zim/file.h>
#include <zim/article.h>
#include <zim/fileiterator.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <map>
#include "time.h"
using namespace std;
@ -71,6 +73,10 @@ namespace kiwix {
std::vector<std::string> suggestions;
std::vector<std::string>::iterator suggestionsOffset;
private:
std::map<std::string, unsigned int> parseCounterMetadata();
};
}