mirror of https://github.com/kiwix/libkiwix.git
FIXED: Number of articles to high in the library (ID: 3396763)
This commit is contained in:
parent
0b50729e03
commit
bc8a400fd1
|
@ -67,14 +67,68 @@ namespace kiwix {
|
||||||
void Reader::reset() {
|
void Reader::reset() {
|
||||||
this->currentArticleOffset = this->firstArticleOffset;
|
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 */
|
/* Get the count of articles which can be indexed/displayed */
|
||||||
unsigned int Reader::getArticleCount() {
|
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() {
|
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 */
|
/* Return the UID of the ZIM file */
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
#include <zim/article.h>
|
#include <zim/article.h>
|
||||||
#include <zim/fileiterator.h>
|
#include <zim/fileiterator.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <map>
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -71,6 +73,10 @@ namespace kiwix {
|
||||||
|
|
||||||
std::vector<std::string> suggestions;
|
std::vector<std::string> suggestions;
|
||||||
std::vector<std::string>::iterator suggestionsOffset;
|
std::vector<std::string>::iterator suggestionsOffset;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, unsigned int> parseCounterMetadata();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue