mirror of https://github.com/kiwix/libkiwix.git
Merge branch 'master' of https://github.com/kiwix/kiwix
This commit is contained in:
commit
5ff4abfab2
|
@ -72,6 +72,7 @@ namespace kiwix {
|
||||||
this->currentArticleOffset = this->firstArticleOffset;
|
this->currentArticleOffset = this->firstArticleOffset;
|
||||||
this->nsACount = this->zimFileHandler->getNamespaceCount('A');
|
this->nsACount = this->zimFileHandler->getNamespaceCount('A');
|
||||||
this->nsICount = this->zimFileHandler->getNamespaceCount('I');
|
this->nsICount = this->zimFileHandler->getNamespaceCount('I');
|
||||||
|
this->zimFilePath = zimFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize random seed: */
|
/* initialize random seed: */
|
||||||
|
@ -252,6 +253,10 @@ namespace kiwix {
|
||||||
return content.empty() ? false : true;
|
return content.empty() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Reader::getZimFilePath() {
|
||||||
|
return this->zimFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return a metatag value */
|
/* Return a metatag value */
|
||||||
bool Reader::getMetatag(const string &name, string &value) {
|
bool Reader::getMetatag(const string &name, string &value) {
|
||||||
unsigned int contentLength = 0;
|
unsigned int contentLength = 0;
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace kiwix {
|
||||||
unsigned int getArticleCount();
|
unsigned int getArticleCount();
|
||||||
unsigned int getMediaCount();
|
unsigned int getMediaCount();
|
||||||
unsigned int getGlobalCount();
|
unsigned int getGlobalCount();
|
||||||
|
string getZimFilePath();
|
||||||
string getId();
|
string getId();
|
||||||
string getRandomPageUrl();
|
string getRandomPageUrl();
|
||||||
string getFirstPageUrl();
|
string getFirstPageUrl();
|
||||||
|
@ -81,6 +82,7 @@ namespace kiwix {
|
||||||
bool parseUrl(const string &url, char *ns, string &title);
|
bool parseUrl(const string &url, char *ns, string &title);
|
||||||
unsigned int getFileSize();
|
unsigned int getFileSize();
|
||||||
zim::File* getZimFileHandler();
|
zim::File* getZimFileHandler();
|
||||||
|
bool getArticleObjectByDecodedUrl(const string &url, zim::Article &article);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
zim::File* zimFileHandler;
|
zim::File* zimFileHandler;
|
||||||
|
@ -89,13 +91,13 @@ namespace kiwix {
|
||||||
zim::size_type currentArticleOffset;
|
zim::size_type currentArticleOffset;
|
||||||
zim::size_type nsACount;
|
zim::size_type nsACount;
|
||||||
zim::size_type nsICount;
|
zim::size_type nsICount;
|
||||||
|
std::string zimFilePath;
|
||||||
|
|
||||||
std::vector< std::vector<std::string> > suggestions;
|
std::vector< std::vector<std::string> > suggestions;
|
||||||
std::vector< std::vector<std::string> >::iterator suggestionsOffset;
|
std::vector< std::vector<std::string> >::iterator suggestionsOffset;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, unsigned int> parseCounterMetadata();
|
std::map<std::string, unsigned int> parseCounterMetadata();
|
||||||
bool getArticleObjectByDecodedUrl(const string &url, zim::Article &article);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,11 @@ namespace kiwix {
|
||||||
{
|
{
|
||||||
template_ct2 = getResourceAsString("results.ct2");
|
template_ct2 = getResourceAsString("results.ct2");
|
||||||
loadICUExternalTables();
|
loadICUExternalTables();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Destructor */
|
||||||
|
Searcher::~Searcher() {}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* Search strings in the database */
|
||||||
void Searcher::search(std::string &search, unsigned int resultStart,
|
void Searcher::search(std::string &search, unsigned int resultStart,
|
||||||
unsigned int resultEnd, const bool verbose) {
|
unsigned int resultEnd, const bool verbose) {
|
||||||
|
@ -127,6 +129,8 @@ namespace kiwix {
|
||||||
this->contentHumanReadableId = contentHumanReadableId;
|
this->contentHumanReadableId = contentHumanReadableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __ANDROID__
|
||||||
|
|
||||||
string Searcher::getHtml() {
|
string Searcher::getHtml() {
|
||||||
|
|
||||||
SimpleVM oSimpleVM;
|
SimpleVM oSimpleVM;
|
||||||
|
@ -203,9 +207,6 @@ namespace kiwix {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
#endif
|
||||||
Searcher::~Searcher() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,16 @@
|
||||||
#include <stringTools.h>
|
#include <stringTools.h>
|
||||||
#include "unicode/putil.h"
|
#include "unicode/putil.h"
|
||||||
|
|
||||||
|
#ifndef __ANDROID__
|
||||||
#include <ctpp2/CDT.hpp>
|
#include <ctpp2/CDT.hpp>
|
||||||
#include <ctpp2/CTPP2FileLogger.hpp>
|
#include <ctpp2/CTPP2FileLogger.hpp>
|
||||||
#include <ctpp2/CTPP2SimpleVM.hpp>
|
#include <ctpp2/CTPP2SimpleVM.hpp>
|
||||||
|
|
||||||
#include "kiwix/ctpp2/CTPP2VMStringLoader.hpp"
|
#include "kiwix/ctpp2/CTPP2VMStringLoader.hpp"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace CTPP;
|
using namespace CTPP;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct Result
|
struct Result
|
||||||
{
|
{
|
||||||
|
@ -58,6 +60,7 @@ namespace kiwix {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Searcher();
|
Searcher();
|
||||||
|
~Searcher();
|
||||||
|
|
||||||
void search(std::string &search, unsigned int resultStart,
|
void search(std::string &search, unsigned int resultStart,
|
||||||
unsigned int resultEnd, const bool verbose=false);
|
unsigned int resultEnd, const bool verbose=false);
|
||||||
|
@ -65,11 +68,13 @@ namespace kiwix {
|
||||||
unsigned int getEstimatedResultCount();
|
unsigned int getEstimatedResultCount();
|
||||||
bool setProtocolPrefix(const std::string prefix);
|
bool setProtocolPrefix(const std::string prefix);
|
||||||
bool setSearchProtocolPrefix(const std::string prefix);
|
bool setSearchProtocolPrefix(const std::string prefix);
|
||||||
string getHtml();
|
|
||||||
void reset();
|
void reset();
|
||||||
void setContentHumanReadableId(const string &contentHumanReadableId);
|
void setContentHumanReadableId(const string &contentHumanReadableId);
|
||||||
~Searcher();
|
|
||||||
|
|
||||||
|
#ifndef __ANDROID__
|
||||||
|
string getHtml();
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
virtual void closeIndex() = 0;
|
virtual void closeIndex() = 0;
|
||||||
|
|
|
@ -27,10 +27,8 @@ using namespace std;
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
class NoXapianIndexInZim: public exception
|
class NoXapianIndexInZim: public exception {
|
||||||
{
|
virtual const char* what() const throw() {
|
||||||
virtual const char* what() const throw()
|
|
||||||
{
|
|
||||||
return "There is no fulltext index in the zim file";
|
return "There is no fulltext index in the zim file";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -39,7 +37,6 @@ namespace kiwix {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XapianSearcher(const string &xapianDirectoryPath);
|
XapianSearcher(const string &xapianDirectoryPath);
|
||||||
|
|
||||||
void searchInIndex(string &search, const unsigned int resultStart, const unsigned int resultEnd,
|
void searchInIndex(string &search, const unsigned int resultStart, const unsigned int resultEnd,
|
||||||
const bool verbose=false);
|
const bool verbose=false);
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,19 @@ void kiwix::loadICUExternalTables() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string kiwix::removeAccents(const std::string &text) {
|
||||||
|
loadICUExternalTables();
|
||||||
|
ucnv_setDefaultName("UTF-8");
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
Transliterator *removeAccentsTrans = Transliterator::createInstance("Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status);
|
||||||
|
UnicodeString ustring = UnicodeString(text.c_str());
|
||||||
|
removeAccentsTrans->transliterate(ustring);
|
||||||
|
delete removeAccentsTrans;
|
||||||
|
std::string unaccentedText;
|
||||||
|
ustring.toUTF8String(unaccentedText);
|
||||||
|
return unaccentedText;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
|
|
||||||
/* Prepare integer for display */
|
/* Prepare integer for display */
|
||||||
|
@ -59,19 +72,6 @@ std::string kiwix::beautifyFileSize(const unsigned int number) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string kiwix::removeAccents(const std::string &text) {
|
|
||||||
loadICUExternalTables();
|
|
||||||
ucnv_setDefaultName("UTF-8");
|
|
||||||
UErrorCode status = U_ZERO_ERROR;
|
|
||||||
Transliterator *removeAccentsTrans = Transliterator::createInstance("Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status);
|
|
||||||
UnicodeString ustring = UnicodeString(text.c_str());
|
|
||||||
removeAccentsTrans->transliterate(ustring);
|
|
||||||
delete removeAccentsTrans;
|
|
||||||
std::string unaccentedText;
|
|
||||||
ustring.toUTF8String(unaccentedText);
|
|
||||||
return unaccentedText;
|
|
||||||
}
|
|
||||||
|
|
||||||
void kiwix::printStringInHexadecimal(UnicodeString s) {
|
void kiwix::printStringInHexadecimal(UnicodeString s) {
|
||||||
std::cout << std::showbase << std::hex;
|
std::cout << std::showbase << std::hex;
|
||||||
for (int i=0; i<s.length(); i++) {
|
for (int i=0; i<s.length(); i++) {
|
||||||
|
|
|
@ -40,7 +40,6 @@ namespace kiwix {
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
|
|
||||||
std::string removeAccents(const std::string &text);
|
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
std::string beautifyFileSize(const unsigned int number);
|
std::string beautifyFileSize(const unsigned int number);
|
||||||
std::string urlEncode(const std::string &c);
|
std::string urlEncode(const std::string &c);
|
||||||
|
@ -51,6 +50,7 @@ namespace kiwix {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string removeAccents(const std::string &text);
|
||||||
void loadICUExternalTables();
|
void loadICUExternalTables();
|
||||||
std::string urlDecode(const std::string &c);
|
std::string urlDecode(const std::string &c);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue